vb.netformsuser-interfacevb.net-2010formborderstyle

Put controls on a form border in vb.net?


I have a project where I want to put controls on the form's border, when the formborderstyle is set to formborderstyle.sizable

Formborderstyle.none will not work, since it can't be sized on runtime, and goes in front of the taskbar when maximized.

I'm using vb.net 2010.


Solution

  • I'm not sure if you can override the drawing of the border and if you could not sure how you would add control to the border.

    You can temporarily change the border style before you maximize the form. And you can overload the client event to handle re-sizing the form yourself.

    Are there any other reasons you dont want to go with Formborderstyle.none?

    Public Class Form1
    Inherits Windows.Forms.Form
    
    Private Const BorderWidth As Integer = 30 'This is just for demo purposes.
    
    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    
        Panel1.Location = New Point(Me.Width - BorderWidth, 0)
        Panel1.Width = BorderWidth
    End Sub
    
    Public xLocation, yLocation As Integer
    
    Private Sub Panel1_MouseDown(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseDown
        xLocation = PointToScreen(Cursor.Position).X
        yLocation = PointToScreen(Cursor.Position).Y
    End Sub
    
    Private Sub Panel1_MouseUp(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseUp
        'Stop resizing form
        Me.Width = Me.Width + (PointToScreen(Cursor.Position).X - xLocation)
        xLocation = PointToScreen(Cursor.Position).X
        yLocation = PointToScreen(Cursor.Position).Y
    End Sub
    
    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Me.FormBorderStyle = Windows.Forms.FormBorderStyle.Sizable
        Me.WindowState = FormWindowState.Maximized
        Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
    End Sub
    
    End Class