VB2008 设置form窗体的位置

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值