1

I am doing a full screen/normal screen button but the logic suddenly started looping from full screen to normal size each button click and it was working at one point here is a snippet:

  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
user3671372
  • 21
  • 1
  • 2

3 Answers3

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
nobody
  • 19,814
  • 17
  • 56
  • 77
Creator
  • 1,502
  • 4
  • 17
  • 30
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

although i really don't see the difference, must be in your If Statement logic. using a boolean is fine as long as you're not setting fullscreen mode elsewhere manually. but you shouldn't, since you can just call toggleFullScreen().

for some more fun, you can pass a Form ByRef to it, ie:

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...
porkchop
  • 401
  • 3
  • 8
  • The first one is the exact same result. – user3671372 May 24 '14 at 19:46
  • well then the question is, what event are you handling that calls the fullscreen function, or what other code catches on size/states changes and alters the window properties... it must be something. – porkchop May 25 '14 at 03:09
-2

Private Sub PictureBox2_Click(sender As Object, e As EventArgs) Handles PictureBox2.Click If Me.WindowState = FormWindowState.Normal Then Me.WindowState = FormWindowState.Maximized Me.TopMost = True Else Me.WindowState = FormWindowState.Normal Me.TopMost = False End If End Sub