scrolltab

scrolltab

转载于:https://www.cnblogs.com/wlqsmiling/p/5628997.html

在MATLAB App Designer中实现滚动界面可以使用uifigure和uitab组件。具体步骤如下: 1. 在App Designer中创建一个新的UI Figure,命名为“MainFigure”。 2. 在MainFigure中添加一个uitab组件,命名为“ScrollTab”。 3. 在ScrollTab中添加一个uipanel组件,命名为“ScrollPanel”。 4. 在ScrollPanel中添加需要滚动的UI组件,例如uicontrol或者axes。 5. 在ScrollPanel中添加一个uitable组件,用于显示大量数据。 6. 在ScrollPanel的属性编辑器中将“Position”属性设置为[0 0 1 1],将“Units”属性设置为“normalized”。 7. 在ScrollPanel的属性编辑器中启用“VerticalScrollbar”和“AutoResizeChildren”属性。 8. 在MainFigure的属性编辑器中将“AutoResizeChildren”属性设置为“on”。 9. 在MainFigure的回调函数中添加以下代码实现滚动功能: ``` function ScrollPanelMouseWheel(app, event) scrollPanel = app.ScrollPanel; scrollPanelPosition = scrollPanel.Position; scrollPanelHeight = scrollPanelPosition(4); scrollPanelChildren = scrollPanel.Children; scrollPanelChildrenPosition = scrollPanelChildren(1).Position; scrollPanelChildrenHeight = scrollPanelChildrenPosition(4); scrollPanelChildrenNewPosition = scrollPanelChildrenPosition; scrollDirection = event.VerticalScrollCount; if scrollDirection > 0 && scrollPanelHeight < scrollPanelChildrenHeight scrollPanelChildrenNewPosition(2) = scrollPanelChildrenPosition(2) + scrollPanelHeight/10; elseif scrollDirection < 0 && scrollPanelChildrenPosition(2) > 0 scrollPanelChildrenNewPosition(2) = scrollPanelChildrenPosition(2) - scrollPanelHeight/10; end scrollPanelChildren(1).Position = scrollPanelChildrenNewPosition; end ``` 10. 在MainFigure的回调函数中添加以下代码启用鼠标滚轮事件: ``` function MainFigureWindowScrollWheelFcn(app, event) app.ScrollPanel.UserData = event; app.ScrollPanel.WindowButtonDownFcn(app,event); end ``` 11. 在ScrollPanel的回调函数中添加以下代码响应鼠标滚轮事件: ``` function ScrollPanelWindowButtonDownFcn(app, event) if strcmp(event.EventName, 'WindowScrollWheel') app.ScrollPanelMouseWheel(event); end end ``` 完成以上步骤后,运行App Designer,即可实现滚动界面。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值