Customizable Form (Tut)
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.
1 post
Page 1 of 1
Hello in this Tut I am going to be showing you my work round to create a custom form in which
the user can then customize it them self.
First you are going to add a new user control and name is Menu.vb
Then add
x1 panel (Dock = fill)
x3 Picutrebox (Dock = right)
name picturebox1 "Close"
name picturebox2 "max"
name picturebox3 "min"
name panel1 "bar"
you should now have a form looking some what like this
![Image]()
Okay so with that done Lets go to MyProject and then to the Settings tab.
Here create the following settings
Bar = string
Min = string
close = string
max = string
So you should then have something like this
![Image]()
Now its time for the Code, go to the form load event and add this code
Now double click the close button and add this code
Double click the max button and add
no press the minimize button and add
okay now were going to create the form drag event so add this code
This is it for the UserControl this is now ready to add to any form and work, but at the moment the users are not able to customize it so lets cheat a little copy the controls from our user control into
a panel in a new form.
No on this form add the following code to the click of each event
That's it you have now created a customizable form control
sorry about offsite link I was unable to use upload attachment on site just kept saying page could not be found


This file is hosted off-site.
the user can then customize it them self.
First you are going to add a new user control and name is Menu.vb
Then add
x1 panel (Dock = fill)
x3 Picutrebox (Dock = right)
name picturebox1 "Close"
name picturebox2 "max"
name picturebox3 "min"
name panel1 "bar"
you should now have a form looking some what like this

Okay so with that done Lets go to MyProject and then to the Settings tab.
Here create the following settings
Bar = string
Min = string
close = string
max = string
So you should then have something like this

Now its time for the Code, go to the form load event and add this code
Code: Select all
This code checks to see if their is a saved image and if so sets the control background image to the image that is saved. Try
If Not My.Settings.Bar = Nothing Then
Bar.BackgroundImage = Image.FromFile(My.Settings.Bar)
End If
If Not My.Settings.Close = Nothing Then
close.BackgroundImage = Image.FromFile(My.Settings.Close)
End If
If Not My.Settings.min = Nothing Then
min.BackgroundImage = Image.FromFile(My.Settings.min)
End If
If Not My.Settings.max = Nothing Then
max.BackgroundImage = Image.FromFile(My.Settings.max)
End If
Catch ex As Exception
MsgBox("Their was an errir loading you custom theme. if this error persists contact admin" + vbNewLine + vbNewLine + vbNewLine + vbNewLine + ex.ToString)
End Try
Now double click the close button and add this code
Code: Select all
This just finds the active form and closes it. FindForm.Close()
Double click the max button and add
Code: Select all
This will check the windowstate of the active form and maximize it or make it normal dependant on state If FindForm.WindowState = FormWindowState.Maximized Then
FindForm.WindowState = FormWindowState.Normal
Else
FindForm.WindowState = FormWindowState.Maximized
End If
no press the minimize button and add
Code: Select all
this minimizes the active form FindForm.WindowState = FormWindowState.Minimized
okay now were going to create the form drag event so add this code
Code: Select all
this code here is not all mine it was actually created in a help topic. but ill explain anyway basically its setting 2 integers of the mouse x and y axis its also then making a Boolean and on the mousedown is changing that to true and setting mouse x and y integers we set to the cursors positions and forms top left, then on the mouse move if drag is true it is moving the form and finally on the mouse up we set drag to false Dim drag As Boolean
Dim mousex As Integer
Dim mousey As Integer
Private Sub panel1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Bar.MouseDown
drag = True
mousex = Windows.Forms.Cursor.Position.X - FindForm.Left
mousey = Windows.Forms.Cursor.Position.Y - FindForm.Top
End Sub
Private Sub panel1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Bar.MouseMove
If drag Then
FindForm.Top = Windows.Forms.Cursor.Position.Y - mousey
FindForm.Left = Windows.Forms.Cursor.Position.X - mousex
End If
End Sub
Private Sub panel1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Bar.MouseUp
drag = False
End Sub
This is it for the UserControl this is now ready to add to any form and work, but at the moment the users are not able to customize it so lets cheat a little copy the controls from our user control into
a panel in a new form.
No on this form add the following code to the click of each event
Code: Select all
Here we are setting the location of the image in my.settings.bar and were changing the image on the form so the user can see their change. Do this for all the controls that we copied over just be sure to change the my.settings.(yourcontrol) to the control you are using and same for the image the users sees. Dim OpenFileDialog1 As New OpenFileDialog
With OpenFileDialog1
.CheckFileExists = True
.ShowReadOnly = False
.FilterIndex = 2
If .ShowDialog = DialogResult.OK Then
My.Settings.Bar = .FileName
Bar.BackgroundImage = Image.FromFile(.FileName)
End If
End With
That's it you have now created a customizable form control

sorry about offsite link I was unable to use upload attachment on site just kept saying page could not be found


This file is hosted off-site.
1 post
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023