网站建设资讯

NEWS

网站建设资讯

vb点虐 自适应的简单介绍

用VB.NET怎样使到DataGrid的列根据内容自动调整列宽?

objTextCol.HeaderText = "备注" '显示DataGrid列名称

创新互联建站是一家网站设计公司,集创意、互联网应用、软件技术为一体的创意网站建设服务商,主营产品:响应式网站建设、品牌网站建设成都全网营销推广。我们专注企业品牌在网站中的整体树立,网络互动的体验,以及在手机等移动端的优质呈现。做网站、网站设计、移动互联产品、网络运营、VI设计、云产品.运维为核心业务。为用户提供一站式解决方案,我们深知市场的竞争激烈,认真对待每位客户,为客户提供赏析悦目的作品,网站的价值服务。

objTextCol.TextBox.AutoSize = True '列宽自适应变化

objDataGridTableStyle.PreferredColumnWidth = objTextCol.TextBox.Width'列宽自适应变化

参考资料:

VB 窗体控件分辨率自适应问题

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

VS2013 VB.NET窗口控件怎么做自适应

窗体在改变大小时会有一个size事件的,在这个事件中写代码获取窗体的高度和宽度再根据窗体的高度和宽度的比例来效果自己的控件的高度宽度比例

VB点虐 TreeView 展开节点自适应宽度

'控制树状选单自动调整宽度

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


网页题目:vb点虐 自适应的简单介绍
分享路径:http://njwzjz.com/article/ddjecep.html