Results 1 to 5 of 5

Thread: FormBorderStyle to None when maximizing the form...

  1. #1

    Thread Starter
    Fanatic Member arsmakman's Avatar
    Join Date
    Dec 2001
    Location
    Leiden, Netherlands.
    Posts
    719

    Angry FormBorderStyle to None when maximizing the form...

    Argh! This is driving me nuts!

    I have a normal form (FormBorderStyle = Sizeable).

    When the user maximizes the form, the form's border should disappear and fully cover the screen. Like so:

    vb Code:
    1. Private Sub frmVideo_SizeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.SizeChanged
    2.  
    3.     If Me.WindowState = FormWindowState.Maximized Then
    4.         'Remove border
    5.         Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
    6.         'Bring to front
    7.         Me.TopMost = True
    8.     End If
    9.  
    10. End Sub

    Problem is, when the form gets maximized and border changed to None, the form doesn't cover the whole screen.

    The form gets the same height as when it is maximized with a titlebar on top. So, the form is about 20 pixels too short, leaving most of the Windows taskbar uncovered.

    So, apparently, if the FormBorderStyle changes after the form has maximized, the change in size is not corrected.

    Therefore, my question is: How do I change a form's size when it's maximized or how do I change the FormBorderStyle before maximization is finished?

    Thanks for any help!

    Alexander.
    No matter how fool-proof your program is, there will always be a better fool.

    Was a post helpful to you? Rate it!

  2. #2
    Hyperactive Member
    Join Date
    Mar 2005
    Posts
    499

    Re: FormBorderStyle to None when maximizing the form...

    Try running your code in the Resize event of the form.

  3. #3

    Thread Starter
    Fanatic Member arsmakman's Avatar
    Join Date
    Dec 2001
    Location
    Leiden, Netherlands.
    Posts
    719

    Re: FormBorderStyle to None when maximizing the form...

    I've tried that already, but to no avail...
    No matter how fool-proof your program is, there will always be a better fool.

    Was a post helpful to you? Rate it!

  4. #4
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,950

    Re: FormBorderStyle to None when maximizing the form...

    This should do it. This says "if the form is maximised, then change the borderstyle and then maximize";

    Code:
        Private Sub Form1_Resize(ByVal sender As System.Object, ByVal e As System.EventArgs) _
        Handles MyBase.Resize
            If Me.WindowState = FormWindowState.Maximized Then
                Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
                Me.WindowState = FormWindowState.Maximized
            End If
        End Sub

  5. #5

    Thread Starter
    Fanatic Member arsmakman's Avatar
    Join Date
    Dec 2001
    Location
    Leiden, Netherlands.
    Posts
    719

    Re: FormBorderStyle to None when maximizing the form...

    Nope, same problem.

    But I have now solved the issue in a round-about way:
    Code:
        Private Resizing As Boolean = False
    
        Private Sub HandleMaximizing() Handles Me.Resize
    
            If Me.WindowState = FormWindowState.Maximized And Not Resizing Then
                Resizing = True
                Me.Hide()
                Me.WindowState = FormWindowState.Normal
            End If
    
            If Resizing Then
                Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
                Me.WindowState = FormWindowState.Maximized
                Me.Show()
                Resizing = False
            End If
    
        End Sub
    This will:
    1. Hide the form.
    2. Change it back Normal size, which triggers the resize-event again.
    3. Change the border style to None.
    4. Maximize the form again.
    5. Make the form visible.

    I hide the form, so the user won't see the form jumping all over the place. This still gives a short flicker, so it isn't ideal.

    If anyone has a better solution, please let me know!

    Alexander.
    No matter how fool-proof your program is, there will always be a better fool.

    Was a post helpful to you? Rate it!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width