'控制樹狀選單自動(dòng)調(diào)整寬度

創(chuàng)新互聯(lián)公司專注于長島網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗(yàn)。 熱誠為您提供長島營銷型網(wǎng)站建設(shè),長島網(wǎng)站制作、長島網(wǎng)頁設(shè)計(jì)、長島網(wǎng)站官網(wǎng)定制、成都微信小程序服務(wù),打造長島網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供長島網(wǎng)站排名全網(wǎng)營銷落地服務(wù)。
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
'取得目前樹狀選單節(jié)點(diǎn)下展開的最大寬度
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 '取得界面原始控件的位置及大小,并保存到數(shù)組里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 '根據(jù)比例調(diào)整控件的大小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 ' '如果初始界面顯示始終是以最大化的方式顯示的話,此處就可以調(diào)用系統(tǒng)分辨率進(jìn)行設(shè)置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
窗體在改變大小時(shí)會(huì)有一個(gè)size事件的,在這個(gè)事件中寫代碼獲取窗體的高度和寬度再根據(jù)窗體的高度和寬度的比例來效果自己的控件的高度寬度比例
使用SplitContainer1控件不就行了,SplitContainer1控件的Fixedpanel屬性設(shè)置為Panel1
SplitContainer1的Panel2里面再放置一個(gè)SplitContainer2
SplitContainer2控件的Fixedpanel屬性設(shè)置為Panel2
二個(gè)SplitContainer設(shè)置為水平折為器方向
至于播放器控件就放在SplitContainer2控件Panel1里面
播放器控件DOCK設(shè)置為FILL
這樣不管放大縮小界面,播放器控件總是自適應(yīng)窗體大小而菜單按鈕總是在最邊緣
兩種方法,一種是固定窗口大小,一種是控件在窗口大小改變時(shí),自動(dòng)按窗口位置進(jìn)行改變;
以上為個(gè)人看法,手打很辛苦,希望采納,謝謝您的支持。
謝謝您的支持,有任何疑問歡迎您再次通過此渠道提問,讓大家共同解決,共同進(jìn)步!
以上回答僅為“百度規(guī)則”,沒有任何違法行為,請(qǐng)樓主采納,謝謝!
Public Class Form1
Dim 初始化控件自動(dòng)大小調(diào)整與窗口的寬度比例 As Integer
Dim 初始化控件自動(dòng)大小調(diào)整與窗口的高度比例 As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
初始化控件自動(dòng)大小調(diào)整與窗口的寬度比例 = Me.Width / 控件自動(dòng)大小調(diào)整.Width
初始化控件自動(dòng)大小調(diào)整與窗口的高度比例 = Me.Height / 控件自動(dòng)大小調(diào)整.Height
顯示控件的位置坐標(biāo)()
End Sub
Private Sub Form1_ResizeEnd(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.ResizeEnd
' Form1_ResizeEnd? 這個(gè)事件是 窗口大小變化完成后 再進(jìn)行操作的
控件自動(dòng)大小調(diào)整.Location = New Point(控件自動(dòng)大小調(diào)整.Left, 控件自動(dòng)大小調(diào)整.Top)
'設(shè)置控件的初始左位置坐標(biāo)? 與? 上位置坐標(biāo)
控件自動(dòng)大小調(diào)整.Size = New Point(Int(Me.Width / 初始化控件自動(dòng)大小調(diào)整與窗口的寬度比例), Int(Me.Height / 初始化控件自動(dòng)大小調(diào)整與窗口的高度比例))
'更改控件的大小? 按第一次窗口的比例 進(jìn)行調(diào)整
顯示控件的位置坐標(biāo)()
End Sub
Private Sub 顯示控件的位置坐標(biāo)()
Label1.Text = "控件的上邊距坐標(biāo): " 控件自動(dòng)大小調(diào)整.Top
Label2.Text = "控件的左邊距坐標(biāo): " 控件自動(dòng)大小調(diào)整.Left
Label3.Text = "控件的寬度大小: " 控件自動(dòng)大小調(diào)整.Width
Label4.Text = "控件的高度大小: " 控件自動(dòng)大小調(diào)整.Height
End Sub
End Class
還有好多方法? 慢慢研究吧兄弟 希望能幫到你
網(wǎng)頁題目:vb.net控件自適應(yīng)的簡單介紹
本文地址:http://chinadenli.net/article8/hihdop.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)頁設(shè)計(jì)公司、營銷型網(wǎng)站建設(shè)、企業(yè)建站、網(wǎng)站設(shè)計(jì)、軟件開發(fā)、品牌網(wǎng)站制作
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)