none
VB.NET - Borderless form maximize problem

    Question

  • Good Day everyone

    I have a borderless form  and put a padding on it that it will look a outline, the problem is when it maximize, the padding is missing it's like it strech to much, but it does not go to the top of my task bar. did i miss some codes for it?

    thanks and regards.

    Saturday, February 22, 2014 9:34 AM

Answers

  • The problem is in your button click code  - when you maximize the form and then change the border style, the form calculates that the borders are off screen.  So the form winds up too big (I happen to have multiple monitors and can see the orange border sticking out on each of my side monitors).

    Just move the line of code to Maximize below the line of code to set the border style.  Note that it does nothing to set the border style to sizable and then immediately change it to none.  It also could just be set on form load since you don't appear to change it with the other button.

    So using your exact code, this would fix it:

    Public Class Form1
        Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
            Me.Padding = New Padding(4)
        End Sub
    
        Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
            Me.FormBorderStyle = Windows.Forms.FormBorderStyle.Sizable
            Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
            Me.WindowState = FormWindowState.Maximized
        End Sub
    
        Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
            Me.WindowState = FormWindowState.Normal
        End Sub
    End Class

    But since that doesn't make a lot of sense, you'd be better off doing:

    Public Class Form1
        Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
            Me.Padding = New Padding(4)
            Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
        End Sub
    
        Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
            Me.WindowState = FormWindowState.Maximized
        End Sub
    
        Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
            Me.WindowState = FormWindowState.Normal
        End Sub
    End Class


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Monday, February 24, 2014 3:48 PM
    Moderator
  • Good Day Everyone 

    thanks for the response

    Cor

    thanks for the response, but your code still not show the orange padding.

    Hi IronRazer

    Your code hides the taskbar, i want to show the task bar, but still the maximise form must show the orange padding.

    I have found the solution here:

    http://social.msdn.microsoft.com/Forums/windows/en-US/35c91bff-234c-40b9-a239-7addae75b393/borderless-form-hiding-taskbar-on-maximize?forum=winforms

    but thanks anyone for the response :)

    Monday, February 24, 2014 11:25 PM
  • Good Day Everyone 

    thanks for the response

    Cor

    thanks for the response, but your code still not show the orange padding.

    Hi IronRazer

    Your code hides the taskbar, i want to show the task bar, but still the maximise form must show the orange padding.

    I have found the solution here:

    http://social.msdn.microsoft.com/Forums/windows/en-US/35c91bff-234c-40b9-a239-7addae75b393/borderless-form-hiding-taskbar-on-maximize?forum=winforms

    but thanks anyone for the response :)

     Hi,

     Glad you found a solution but, i just wanted to mention that it didn`t cover the taskbar on my computer so if you need to restrict it so it does not cover it and you want to try using the code you can just set the MaximizedBounds of the form as i did in the first line of the Form.Load event in this code.  :)

    Public Class Form1
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Me.MaximizedBounds = Screen.PrimaryScreen.WorkingArea 'Keeps it restricted so it does not cover taskbar
            Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
            Me.BackColor = Color.Orange
            Me.Padding = New Padding(4)
            Panel1.BackColor = Color.Gainsboro
            Panel1.Dock = DockStyle.Fill
        End Sub
    
        Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Me.WindowState = FormWindowState.Maximized
        End Sub
    
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            Me.WindowState = FormWindowState.Normal
        End Sub
    
        Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
            Me.Close()
        End Sub
    End Class
    

    Tuesday, February 25, 2014 12:42 AM

All replies

  • Good Day everyone

    I have a borderless form  and put a padding on it that it will look a outline, the problem is when it maximize, the padding is missing it's like it strech to much, but it does not go to the top of my task bar. did i miss some codes for it?

    thanks and regards.

    Without seeing your code and possibly an image it's difficult for me to understand.

    You can use the "Insert Code Block" function to paste your code into by editing your original post and adding that in the original post. And maybe an image of the issue also.


    Please BEWARE that I have NO EXPERIENCE and NO EXPERTISE and probably onset of DEMENTIA which may affect my answers! Also, I've been told by an expert, that when you post an image it clutters up the thread and mysteriously, over time, the link to the image will somehow become "unstable" or something to that effect. :) I can only surmise that is due to Global Warming of the threads.

    Saturday, February 22, 2014 10:46 AM
  • Hi,

     I am guessing this is about the MDI child form from This Question you had yesterday. Using this code and maximizing the MDI child form still shows the border. If this is not what your looking to do then please post your code.  :)

     

    Form1 - The MDI parent form code

    Public Class Form1
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim f2 As New Form2
            f2.MdiParent = Me
            f2.Show()
        End Sub
    End Class
     

    Form2 - The MDI child form code

    Public Class Form2
        Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Me.FormBorderStyle = FormBorderStyle.None
            Me.Padding = New Padding(2)
            Me.WindowState = FormWindowState.Maximized
        End Sub
    
        Private Sub Form2_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
            ControlPaint.DrawBorder(e.Graphics, ClientRectangle, Color.Red, ButtonBorderStyle.Solid)
        End Sub
    End Class
     

     Here you can see the Red border around Form2 the MDI child form.

     

    PS - Please edit your post and change it from a Discussion to a Question. Thanks.


    Saturday, February 22, 2014 1:28 PM
  • Hi Reed 

    No this different, this is not a MDI Parent form, but i use your code on this but it's a regular none borderless form, the problem is when i maximize the form, the padding(colored) and the border is gone or hiding(i think), you will only see it when the windows state is back to normal again. here's my code on my customize maximize button.

    me.Windowstate = FormWindowState.Maximized
    me.FormBorderStyle = Windows.Forms.FormBorderStyle.Sizable
    Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
    Thanks and regards.

    Monday, February 24, 2014 10:32 AM
  • no problem at all

    Public Class Form1
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Me.WindowState = FormWindowState.Maximized
            Me.FormBorderStyle = Windows.Forms.FormBorderStyle.Sizable
            Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Me.WindowState = FormWindowState.Normal
        End Sub
    
        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
            Me.WindowState = FormWindowState.Maximized
        End Sub
    End Class
    


    Success
    Cor

    Monday, February 24, 2014 10:49 AM
  • Hi Cor

    Here's what i'm talking about

    my normal state:

    on my form i set my background color as orange, then put a white panel on it, then set the form padding into 4, this looks like while it is normal.

    now take a look at this when you maximize the form.

    on this image, when you maximize the form, the orange padding is gone, this is what i want to resolve, when the borderless screeen maximize it will still show the orange padding, thanks everyone.

    Monday, February 24, 2014 11:07 AM
  • Public Class Form1
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Me.WindowState = FormWindowState.Normal
    
            Me.FormBorderStyle = Windows.Forms.FormBorderStyle.Sizable
            Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
            Me.Panel1.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
               Or System.Windows.Forms.AnchorStyles.Left) _
               Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Me.WindowState = FormWindowState.Normal
        End Sub
    
        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
            Me.WindowState = FormWindowState.Maximized
        End Sub
    End Class


    Success
    Cor

    Monday, February 24, 2014 12:56 PM
  • Hi,

     This code seems to work alright also. You can give it a try if you want.

    Public Class Form1
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
            Me.BackColor = Color.Orange
            Me.Padding = New Padding(4)
            Panel1.Dock = DockStyle.Fill
        End Sub
    
        Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Me.WindowState = FormWindowState.Maximized
        End Sub
    
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            Me.WindowState = FormWindowState.Normal
        End Sub
    
        Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
            Me.Close()
        End Sub
    End Class
    

    Monday, February 24, 2014 1:33 PM
  • The problem is in your button click code  - when you maximize the form and then change the border style, the form calculates that the borders are off screen.  So the form winds up too big (I happen to have multiple monitors and can see the orange border sticking out on each of my side monitors).

    Just move the line of code to Maximize below the line of code to set the border style.  Note that it does nothing to set the border style to sizable and then immediately change it to none.  It also could just be set on form load since you don't appear to change it with the other button.

    So using your exact code, this would fix it:

    Public Class Form1
        Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
            Me.Padding = New Padding(4)
        End Sub
    
        Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
            Me.FormBorderStyle = Windows.Forms.FormBorderStyle.Sizable
            Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
            Me.WindowState = FormWindowState.Maximized
        End Sub
    
        Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
            Me.WindowState = FormWindowState.Normal
        End Sub
    End Class

    But since that doesn't make a lot of sense, you'd be better off doing:

    Public Class Form1
        Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
            Me.Padding = New Padding(4)
            Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
        End Sub
    
        Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
            Me.WindowState = FormWindowState.Maximized
        End Sub
    
        Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
            Me.WindowState = FormWindowState.Normal
        End Sub
    End Class


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Monday, February 24, 2014 3:48 PM
    Moderator
  • Good Day Everyone 

    thanks for the response

    Cor

    thanks for the response, but your code still not show the orange padding.

    Hi IronRazer

    Your code hides the taskbar, i want to show the task bar, but still the maximise form must show the orange padding.

    I have found the solution here:

    http://social.msdn.microsoft.com/Forums/windows/en-US/35c91bff-234c-40b9-a239-7addae75b393/borderless-form-hiding-taskbar-on-maximize?forum=winforms

    but thanks anyone for the response :)

    Monday, February 24, 2014 11:25 PM
  • Good Day Everyone 

    thanks for the response

    Cor

    thanks for the response, but your code still not show the orange padding.

    Hi IronRazer

    Your code hides the taskbar, i want to show the task bar, but still the maximise form must show the orange padding.

    I have found the solution here:

    http://social.msdn.microsoft.com/Forums/windows/en-US/35c91bff-234c-40b9-a239-7addae75b393/borderless-form-hiding-taskbar-on-maximize?forum=winforms

    but thanks anyone for the response :)

     Hi,

     Glad you found a solution but, i just wanted to mention that it didn`t cover the taskbar on my computer so if you need to restrict it so it does not cover it and you want to try using the code you can just set the MaximizedBounds of the form as i did in the first line of the Form.Load event in this code.  :)

    Public Class Form1
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Me.MaximizedBounds = Screen.PrimaryScreen.WorkingArea 'Keeps it restricted so it does not cover taskbar
            Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
            Me.BackColor = Color.Orange
            Me.Padding = New Padding(4)
            Panel1.BackColor = Color.Gainsboro
            Panel1.Dock = DockStyle.Fill
        End Sub
    
        Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Me.WindowState = FormWindowState.Maximized
        End Sub
    
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            Me.WindowState = FormWindowState.Normal
        End Sub
    
        Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
            Me.Close()
        End Sub
    End Class
    

    Tuesday, February 25, 2014 12:42 AM