VB2008设置form窗体的位置
1.获显示器的当期分辨:My.Computer.Screen.WorkingArea.Size,返回width,height 可以单独获取width或height My.Computer.Screen.WorkingArea.Size.width My.Computer.Screen.WorkingArea.Size.height 2.设置窗体位置 屏幕中央:Form1.StartPosition=FormStartPosition.CenterScreen 手动设置:Form1.StartPosition = FormStartPosition.Manual 左100,上100像素:Form1.Location = New Point(100,100) 单独设置左边距:Form1.Left = 300 单独设置右边距:Form1.top = 300 3.边距和窗体大小一起设置 Dim Myrect as new rectangle(200,100,300,300) 或单独设置 假设我的form1窗体的大小是400*400,我要设置往屏幕四个角落停靠,往边上托,就可以自动停在角落 Private Sub MyNoteBook_Move(ByVal sender As Object,ByVal e As System.EventArgs) Handles Me.Move '设置窗体往四个角落停靠方法 Dim FormX As Int32 = My.Computer.Screen.WorkingArea.Width - 400 Dim FormY As Int32 = My.Computer.Screen.WorkingArea.Height - 400 If Me.Location.X < 0 And Me.Location.Y < 0 Then Me.Location = New Point(0,0) ElseIf Me.Location.X < 0 And Me.Location.Y > FormY Then Me.Location = New Point(0,FormY) ElseIf Me.Location.X > FormX And Me.Location.Y < 0 Then Me.Location = New Point(FormX,0) ElseIf Me.Location.X > FormX And Me.Location.Y > FormY Then Me.Location = New Point(FormX,FormY) End If End Sub (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |