Custom Form Tutorial

Heres your chance to share your own tutorials with the community. Just post them on here. If your lucky they may even be posted on the main site.
3 posts Page 1 of 1
Contributors
User avatar
muttley1968
Hardcore Programmer
Hardcore Programmer
Posts: 622
Joined: Thu Jun 17, 2010 11:54 pm

Custom Form Tutorial
muttley1968
In this tut I will be teaching you how to make an Advanced Custom Form border

So the first Step is to set the formborderstyle to NONE
Image


Now that we have done that add for panels and change their colour or image to what you like
Image

And now Dock them like this 1 dock to the top, 2 dock to the right, 3 docked to the left and finally 4 docked to the bottom
Image

Now on the top bar add 3 pictureboxes and set them all to docked right
Image


First we are going to code the form controls IE the close/maximize/minimize

So double click the close - First picturebox on the right
Code: Select all
end
simple just ends the program

Nest we are going to do the Maximize - Go to the settings page and add 2 settings
my location and my size they are both to be set to system.drawing.point instead of a string

now double click and add this code to the maximize button
Code: Select all
 
 If Me.Height = Screen.PrimaryScreen.Bounds.Height - 40 Then
            Me.Size = My.Settings.My_size
            Me.Location = My.Settings.My_location
        Else
            Me.Height = Screen.PrimaryScreen.Bounds.Height - 40
            Me.Width = Screen.PrimaryScreen.Bounds.Width
            Me.Location = New Point(0, 0)
        End If
Next we are going to add the form minimize event which is this
Code: Select all
 Me.WindowState = FormWindowState.Minimized

Okay now that is that part done simple to understand it just controls the three buttons at the top of the form that you have on prity mutch ALL programs.

Next for the form Resize we need to start with a few thing soo add this to the top of the code
Code: Select all
 Private WithEvents Resize_Form_BR As New Timer
    Private WithEvents Resize_Form_B As New Timer
    Private WithEvents Resize_Form_R As New Timer
    Private WithEvents Resize_From_L As New Timer
    Dim PrevWindowState As String
    Dim AppLoc, CurLoc As New Point(0, 0)
    Dim AppSize, CurPos As New Point(0, 0)
    Dim CursX As Integer = 0
    Dim CursY As Integer = 0
    Dim AppHeight As Integer = 0
    Dim AppWidth As Integer = 0
    Dim AppH As Integer = 0
    Dim AppW As Integer = 0
    Private Sub Definitions()
        AppLoc = Location
        CurLoc = Cursor.Position
        CursX = Cursor.Position.X
        CursY = Cursor.Position.Y
        AppHeight = Me.Height
        AppWidth = Me.Width
        AppSize = Me.Size
        CurPos = Cursor.Position
    End Sub
This is needed for everything to work

and now this sorry ive got bored now soo just copy and paste this and try to understand any problems message me and ill be happy to help :P
Code: Select all
    Private Sub Resize_Form_BR_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Resize_Form_BR.Tick
        Me.Height = AppHeight - CursY + Cursor.Position.Y
        Me.Width = AppWidth - CursX + Cursor.Position.X
    End Sub

    Private Sub Panel14_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Panel14.MouseEnter
        Me.Cursor = Cursors.SizeNWSE
    End Sub
    Private Sub Panel14_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Panel14.MouseLeave
        Me.Cursor = Cursors.Default
    End Sub

    Private Sub Panel14_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel14.MouseDown
        Resize_Form_BR.Enabled = True
        Resize_Form_BR.Start()
        Definitions()
    End Sub

    Private Sub Panel14_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel14.MouseUp
        Resize_Form_BR.Stop()
        Definitions()
    End Sub

    Private Sub Resize_Form_L_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Resize_From_L.Tick
        Me.Width = AppWidth - CursX + Cursor.Position.X
    End Sub

    Private Sub Panel2_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Panel2.MouseEnter
        Me.Cursor = Cursors.SizeWE
    End Sub

    Private Sub Panel2_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Panel2.MouseLeave
        Me.Cursor = Cursors.Default
    End Sub

    Private Sub Panel2_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel2.MouseDown
        Resize_From_L.Enabled = True
        Resize_From_L.Start()
        Definitions()
    End Sub

    Private Sub Panel2_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel2.MouseUp
        Resize_From_L.Stop()
        Definitions()
    End Sub

    Private Sub Resize_Form_R_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Resize_Form_R.Tick
        Me.Width = AppWidth - CursX + Cursor.Position.X
    End Sub

    Private Sub Panel3_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Panel3.MouseEnter
        Me.Cursor = Cursors.SizeWE
    End Sub

    Private Sub Panel3_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Panel3.MouseLeave
        Me.Cursor = Cursors.Default
    End Sub

    Private Sub Panel3_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel3.MouseUp
        Resize_Form_R.Stop()
        Definitions()
    End Sub

    Private Sub Panel3_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel3.MouseDown
        Resize_Form_R.Enabled = True
        Resize_Form_R.Start()
        Definitions()
    End Sub
    Private Sub Resize_Form_B_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Resize_Form_B.Tick
        Me.Height = AppHeight - CursY + Cursor.Position.Y
    End Sub

    Private Sub Panel4_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Panel4.MouseEnter
        Me.Cursor = Cursors.SizeNS
    End Sub

    Private Sub Panel4_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Panel4.MouseLeave
        Me.Cursor = Cursors.Default
    End Sub

    Private Sub Panel4_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel4.MouseDown
        Resize_Form_B.Enabled = True
        Resize_Form_B.Start()
        Definitions()
    End Sub

    Private Sub Panel4_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel4.MouseUp
        Resize_Form_B.Stop()
        Definitions()
    End Sub

    Dim NewPoint As New System.Drawing.Point()
    Dim X, Y As Integer
    Private Sub Child_Top_Panel_MouseDown1(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseDown
        X = Control.MousePosition.X - Me.Location.X
        Y = Control.MousePosition.Y - Me.Location.Y
    End Sub

    Private Sub Child_Top_Panel_MouseMove1(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseMove
        If e.Button = MouseButtons.Left Then
            NewPoint = Control.MousePosition
            NewPoint.X -= (X)
            NewPoint.Y -= (Y)
            Me.Location = NewPoint
        End If
    End Sub
User avatar
visualtech
VIP - Donator
VIP - Donator
Posts: 265
Joined: Sat Nov 19, 2011 2:19 pm

Re: Custom Form Tutorial
visualtech
Nice
Image
User avatar
noypikami
VIP - Donator
VIP - Donator
Posts: 151
Joined: Sat Dec 22, 2012 1:49 am

Re: Custom Form Tutorial
noypikami
nice, wanna try it sometime...
3 posts Page 1 of 1
Return to “Tutorials”