大橙子网站建设,新征程启航

为企业提供网站建设、域名注册、服务器等服务

vb.net窗体自适应的简单介绍

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

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

创新互联于2013年创立,先为通渭等服务建站,通渭等地企业,进行企业商务咨询服务。为通渭企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。

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

vb.net如何设置一个窗体为 宽度不能调节,而高度可以调节

vb.net设置一个窗体为,宽度不能调节,而高度可以调节,

代码设置方法:

Dim form_width As Integer = Me.Width

Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize

If Me.Width form_width Then

Me.Width = form_width

'Debug.Print(TimeString "-" CStr(Me.Width))

End If

End Sub

vb.net,即Visual Basic.NET是基于微软.NET Framework之上的面向对象的编程语言。其在调试时是以解释型语言方式运作,而输出为EXE程序是是以编译型语言方式运作。可以看作是Visual Basic在.Net Framework平台上的升级版本,增强了对面向对象的支持。

vb.net 如何使得控件随着窗体大小 的改变而改变呢,大家帮忙给想想,最好有代码的哦

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

还有好多方法  慢慢研究吧兄弟 希望能帮到你


网页题目:vb.net窗体自适应的简单介绍
标题链接:http://dzwzjz.com/article/hjjgjo.html
在线咨询
服务热线
服务热线:028-86922220
TOP