重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
'控制树状选单自动调整宽度
创新互联公司专注于长岛网站建设服务及定制,我们拥有丰富的企业做网站经验。 热诚为您提供长岛营销型网站建设,长岛网站制作、长岛网页设计、长岛网站官网定制、成都微信小程序服务,打造长岛网络公司原创品牌,更为您提供长岛网站排名全网营销落地服务。
Private Sub tvMenu_AfterExpand(sender As Object, e As TreeViewEventArgs) Handles tvMenu.AfterExpand, tvMenu.AfterCollapse
Dim iMaxWidth As Integer = 0
For Each tn As TreeNode In tvMenu.Nodes
Dim iCurPos As Integer = tn.Bounds.X
Dim iCurWidth As Integer = iCurPos + tn.Bounds.Width
If tn.IsExpanded Then
iCurWidth = GetTreeViewMaxWidth(tn)
End If
If iMaxWidth iCurWidth Then
iMaxWidth = iCurWidth
Me.gbMenu.Width = iCurPos + iMaxWidth
End If
Next
End Sub
'取得目前树状选单节点下展开的最大宽度
Private Function GetTreeViewMaxWidth(tn As TreeNode) As Integer
Dim iMaxWidth As Integer = 0
For Each tnItem As TreeNode In tn.Nodes
Dim iCurPos As Integer = tnItem.Bounds.X
Dim iCurWidth As Integer = iCurPos + tnItem.Bounds.Width
If tnItem.IsExpanded Then
iCurWidth = GetTreeViewMaxWidth(tnItem)
End If
If iMaxWidth iCurWidth Then
iMaxWidth = iCurWidth
End If
Next
Return iMaxWidth
End Function
Public Type CONTROLRECT Left As Single Top As Single Width As Single Height As SingleEnd Type Public Const HORZRES = 8Public Const VERTRES = 10Public Declare Function GetDesktopWindow Lib "user32" () As LongPublic Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As LongPublic Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As LongPublic Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, ByVal nIndex As Long) As Long '取得界面原始控件的位置及大小,并保存到数组里Public Sub GetSourcePos(this As Object, rc() As CONTROLRECT, Optional bigFont As Boolean = True)
'On Error Resume Next
Dim tempX As Integer, tempY As IntegertempX = this.ScaleWidth '1024tempY = this.ScaleHeight '768 '此处原来如果在1024*768分辨率下显示正常的话,就可以直接赋值1024和768 Dim temp As Control Dim nSum As Integer nSum = 0 For Each temp In this '此处要注意,有些控件没有width,height等属性,在此要做出判断 If TypeOf temp Is ComboBox Then With rc(nSum) .Left = temp.Left / tempX .Width = temp.Width / tempX .Top = temp.Top / tempY End With ElseIf TypeOf temp Is Timer Then' 'none' ElseIf TypeOf temp Is StatusBar Then' 'none Else With rc(nSum) .Left = temp.Left / tempX .Width = temp.Width / tempX .Top = temp.Top / tempY .Height = temp.Height / tempY End With End If nSum = nSum + 1 NextEnd Sub '根据比例调整控件的大小Public Sub SetNewPos(this As Object, rc() As CONTROLRECT)
'On Error Resume Next Dim tempX As Integer, tempY As Integer tempX = this.ScaleWidth '1024 tempY = this.ScaleHeight '768 ' '如果初始界面显示始终是以最大化的方式显示的话,此处就可以调用系统分辨率进行设置tempx,tempy' hwnd = GetDesktopWindow()' ' Get the device context for the desktop' hdc = GetWindowDC(hwnd)' If hdc Then' Dim a As Long, b As Long' a = GetDeviceCaps(hdc, HORZRES)' b = GetDeviceCaps(hdc, VERTRES)' tempX = a' tempY = b' End If' ReleaseDC hwnd, hdc Dim temp As Control '//用于取各种控件 Dim nSum As Integer nSum = 0 For Each temp In this '此处要注意,有些控件没有width,height等属性,在此要做出判断 If TypeOf temp Is ComboBox Then temp.Left = rc(nSum).Left * tempX temp.Width = rc(nSum).Width * tempX temp.Top = rc(nSum).Top * tempY ElseIf TypeOf temp Is Timer Then 'none 'ElseIf TypeOf temp Is StatusBar Then 'none Else temp.Left = rc(nSum).Left * tempX temp.Width = rc(nSum).Width * tempX temp.Top = rc(nSum).Top * tempY temp.Height = rc(nSum).Height * tempY End If nSum = nSum + 1 Next End Sub
窗体在改变大小时会有一个size事件的,在这个事件中写代码获取窗体的高度和宽度再根据窗体的高度和宽度的比例来效果自己的控件的高度宽度比例
使用SplitContainer1控件不就行了,SplitContainer1控件的Fixedpanel属性设置为Panel1
SplitContainer1的Panel2里面再放置一个SplitContainer2
SplitContainer2控件的Fixedpanel属性设置为Panel2
二个SplitContainer设置为水平折为器方向
至于播放器控件就放在SplitContainer2控件Panel1里面
播放器控件DOCK设置为FILL
这样不管放大缩小界面,播放器控件总是自适应窗体大小而菜单按钮总是在最边缘
两种方法,一种是固定窗口大小,一种是控件在窗口大小改变时,自动按窗口位置进行改变;
以上为个人看法,手打很辛苦,希望采纳,谢谢您的支持。
谢谢您的支持,有任何疑问欢迎您再次通过此渠道提问,让大家共同解决,共同进步!
以上回答仅为“百度规则”,没有任何违法行为,请楼主采纳,谢谢!
Public Class Form1
Dim 初始化控件自动大小调整与窗口的宽度比例 As Integer
Dim 初始化控件自动大小调整与窗口的高度比例 As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
初始化控件自动大小调整与窗口的宽度比例 = Me.Width / 控件自动大小调整.Width
初始化控件自动大小调整与窗口的高度比例 = Me.Height / 控件自动大小调整.Height
显示控件的位置坐标()
End Sub
Private Sub Form1_ResizeEnd(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.ResizeEnd
' Form1_ResizeEnd 这个事件是 窗口大小变化完成后 再进行操作的
控件自动大小调整.Location = New Point(控件自动大小调整.Left, 控件自动大小调整.Top)
'设置控件的初始左位置坐标 与 上位置坐标
控件自动大小调整.Size = New Point(Int(Me.Width / 初始化控件自动大小调整与窗口的宽度比例), Int(Me.Height / 初始化控件自动大小调整与窗口的高度比例))
'更改控件的大小 按第一次窗口的比例 进行调整
显示控件的位置坐标()
End Sub
Private Sub 显示控件的位置坐标()
Label1.Text = "控件的上边距坐标: " 控件自动大小调整.Top
Label2.Text = "控件的左边距坐标: " 控件自动大小调整.Left
Label3.Text = "控件的宽度大小: " 控件自动大小调整.Width
Label4.Text = "控件的高度大小: " 控件自动大小调整.Height
End Sub
End Class
还有好多方法 慢慢研究吧兄弟 希望能帮到你