Thursday, May 26, 2016

Add a border in FormBorderStyle = None




Add a border in FormBorderStyle = None

When we are using Forms with the property FormBorderStyle = None is alwaysconsider adding a border into your Form. Why? Well, imagine a Operative System that the DesktopBackgroundis a black . Now, imagineyour program with Forms with a black back color.
In this case, the user will be confused because he doesn´t know where is the form of your program. But if you add a white border it will be better right?

How to crte a project in Visual Studio?

Exists many ways to crte a new project in VS. For example, when you open your VS program, in theStart Pageyou will see the optionNew Project ...
If you can´t see the Start Page you can also click inFile > New Project > Select Visual Basic > Forms Appliion
Rename your project name if you want and clickOK.
It´s sy!

Adding the border ...

For this case, I will crte a rectangle with a same size and loion that your form. You can also chose the width of the rectangle. In the end, it will work as a border. Simple it isn´t?
For this example, you need 2 event of your Form. Paint and Load. To open the file that contains the press Ctrl + Alt+ 0
You will also need some lines of out of Events space but after the Public Class of your Form like in the next .

In that space add this lines
Private borderColor As Color = Color.FromArgb(9, 74, 178)Private borderWidth As Integer = 2Private formRegion As Rectangle
Now in the Paint Event:
Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint ControlPaint.DrawBorder(e.Graphics, formRegion, borderColor, _ borderWidth, ButtonBorderStyle.Solid, borderColor, borderWidth, _ ButtonBorderStyle.Solid, borderColor, borderWidth, ButtonBorderStyle.Solid, _ borderColor, borderWidth, ButtonBorderStyle.Solid)End Sub
In the Load event:
Don´t forget to check the size of your form. The first 2 s are the loion. The next 2 s are the size.
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.LoadformRegion = New Rectangle(0, 0, 626, 372) 'size form 626; 372End Sub
I hope this was helpfull!
See you next time!


No comments:

Post a Comment