在VB中编程全屏/普通屏幕尺寸按钮

时间:2014-05-24 09:31:33

标签: vb.net winforms if-statement

我正在做一个全屏/普通屏幕按钮,但逻辑突然开始从全屏循环到正常大小每个按钮点击它在一点工作这里是一个片段:

  If ScreenMode.Text = "Normal Size" Then
        ScreenMode.Text = "Full Size"
        Me.WindowState = FormWindowState.Normal
        Me.Width = 563
        Me.Height = 447
        Me.FormBorderStyle = Windows.Forms.FormBorderStyle.Sizable
        Me.TopMost = False
    ElseIf Me.FormBorderStyle = Windows.Forms.FormBorderStyle.Sizable Then
        ScreenMode.Text = "Normal Size"
        Me.WindowState = FormWindowState.Maximized
        Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
        Me.TopMost = True
    End If

3 个答案:

答案 0 :(得分:1)

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    If Me.WindowState = FormWindowState.Normal Then
        Me.WindowState = FormWindowState.Maximized
        Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
        Me.TopMost = True
    Else
        Me.WindowState = FormWindowState.Normal
        Me.Width = 563
        Me.Height = 447
        Me.FormBorderStyle = Windows.Forms.FormBorderStyle.Sizable
        Me.TopMost = False
    End If
End Sub

答案 1 :(得分:0)

Private isFullScreen As Boolean = False
Private Sub toggleFullScreen()
    isFullScreen = Not isFullScreen
    If isFullScreen Then
        MaximizeBox = False
        MinimizeBox = False
        TopMost = True
        FormBorderStyle = FormBorderStyle.None
        WindowState = FormWindowState.Maximized
    Else
        MaximizeBox = True
        MinimizeBox = True
        TopMost = False
        FormBorderStyle = FormBorderStyle.Sizable
        WindowState = FormWindowState.Normal
    End If
End Sub

虽然我真的没有看到差异,但必须在你的If Statement逻辑中。只要您不在其他地方手动设置全屏模式,使用布尔值就可以了。但你不应该这样做,因为你可以调用toggleFullScreen()。

为了更有趣,您可以将Form ByRef传递给它,即:

Public Sub toggleFullScreen(ByRef theForm As Form)
If theForm.FormWindowState = FormWindowState.Normal Then
    With theForm
        .MaximizeBox = False
        .MinimizeBox = False
        .TopMost = True
        .FormBorderStyle = FormBorderStyle.None
        .WindowState = FormWindowState.Maximized
    End With
End If
etc...

答案 2 :(得分:-2)

Private Sub PictureBox2_Click(sender As Object,e As EventArgs)处理PictureBox2.Click         如果Me.WindowState = FormWindowState.Normal那么             Me.WindowState = FormWindowState.Maximized             Me.TopMost = True         其他             Me.WindowState = FormWindowState.Normal             Me.TopMost =假         万一     结束子