加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

VB2008设置form窗体的位置

发布时间:2020-12-17 07:41:06 所属栏目:百科 来源:网络整理
导读:1. 获显示器的当期分辨: My.Computer.Screen.WorkingArea.Size ,返回 width , height 可以单独获取 width 或 height My.Computer.Screen.WorkingArea.Size.width My.Computer.Screen.WorkingArea.Size.height 2. 设置窗体位置 屏幕中央: Form1.StartPosi

1.获显示器的当期分辨:My.Computer.Screen.WorkingArea.Size,返回widthheight

可以单独获取widthheight

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)

或单独设置

Dim myrect As New Rectangle

myrect.X = 200

myrect.Y = 100

myrect.Width = 300

myrect.Height = 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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读