|
The Form design, Mainform.vb
Rename
the Form Form1.vb created and add new controls to
it
Classes used in this Form:
MainMenu, Timer,
PictureBox, Label and StausBar
1-
Rename the Form
- On the View
menu , click Solution Explorer
- In Solution
Explorer, expand the APP-VBNet project node and
select Form1.vb
- In Properties
windows, Type the new File Name
|
Old |
New |
Filename : |
Form1.vb |
MainForm.vb |
|
|
2- Add Folder and two picture files ..
- Create
new Folder
- On the View
menu , click Solution Explorer
- In Solution
Explorer, expand the APP-VBNet project node, click
Right mouse Button, click Add of the Popup menu, and
the click New Folder
- New Folder
appears in the Solution Explorer. Rename it - Pic
|
- Add
Picture Files
- From the CD-Rom -
Teach_VNet, copy the
bmp file ingraphic1.bmp (\\APP-VBNet\Pic\ingraphic1.bmp) to
the folder-
c:\APP-VBNet\Pic
- From the CD-Rom -
Teach_VNet, copy the icon
file App-VBNet.ico (\\APP-VBNet\Pic\App-VBNet.ico) to the folder
-
c:\APP-VBNet\Pic
- On the Projet
menu , click Add Existing Item ..., Add
Existing Item - APP-VBNet dialog box appears, select the
files ingraphic1.bmp and App-VBNet.ico of the folder c:\APP-VBNet\Pic,
and then click Open.
|
|
3-
Modify the Form Properties ...
- On the View
menu , click Solution Explorer
- In Solution
Explorer, expand the APP-VBNet project node
- Right click the
MainForm.vb and click View Designer on
the shortcut menu to open the Properties Windows.
- In Properties
windows, modify ...
|
Old |
New |
Name:
FormBorderStyle
Icon:
Menu:
Size:
Text:
Window State: |
Form1
Sizable
Icon
(none)
300,300
Form1
Normal |
MainForm
FixedSingle
Icon
mainMenu1
504,485
Main Form ...
Maximized |
|
|
|
- On the Project
menu , click APP-VBNet Properties ..., the APP-VBNet
Property Pages dialog box appears
- In the Startup
object combo box, choose and select MainForm
- Click OK
|
1- |
The MainForm.vb
design |
|

|
2- |
From
the Toolbox/Windows Form
add these controls ...
|
|
-
Add the PictureBox control
-
PictureBox1, PictureBox Properties:
Name:
Image:
Size Mode: |
PictureBox1
System.Drawing.Bitmap
Autosize |
|
Bitmap file added =
C:\APP-VBNet\Pic\ingraphic1.bmp
-
Add the Label control
-
Label1, Label Properties:
Font:
Name:
Size:
Text:
TextAlign: |
Times New Roman, 9.75pt, style=Bold, Italic
Label1:
360,16
Learn how to write Microsoft Visual Basic .Net
application ...
MiddleCenter |
|
-
Add the StatusBar control
-
StatusBar1, StatusBar Properties:
Name:
Panels:
Show Panels:
Size:
Text: |
StatusBar1
(collection)
True
496,16
StatusBar1 |
|
The
StatusBarPanel Collection Editor dialog box stores info
about the panels added to this control.
StatusBarPanel Properties ....
Name |
Alignment |
AutoSize |
Text |
ToolTipText |
Width |
StatusBarPanel1
StatusBarPanel2
StatusBarPanel3 |
left
center
center |
None
Spring
Spring |
none
-
- |
Status...
Date ...
Time ... |
200
140
140 |
|
-
Add the Timer control
-
Timer1, Timer Properties:
Name:
Enabled:
Interval: |
Timer1
True
100 |
|
-
Add the MainMenu control,
MainMenu1
The MainMenu control
represents the container for the menu structure of a form. A
menu is composed of MenuItem objects that represent the
individual menu commands in the menu structure. Each
MenuItem can be a command for your application or a
parent menu for other submenu items.
Add to this menu - MainMenu1 the following items
menu
Item |
Name |
Text |
0
1
2
3
4
5 |
MenuItem1
MenuItem2
MenuItem3
MenuItem4
MenuItem5
MenuItem6 |
Info
Menu
Book
-
About
-
Exit |
The
menu design
...
|
|
|
|
|
How create Public Event in Visual Basic .Net
MainForm.vb
file, the code ...
The
text
Code
is
red color,
corresponding to Load data in the Statusbar control
The
text
Code is
Navy color,
corresponding to Run the Form Book.vb
The
text
Code is
Maroon color,
corresponding to Run the Form About.vb |
|
Public
Class
MainForm
Inherits
System.Windows.Forms.Form
Windows Form Designer generated code |
Private
Sub
MainForm_Load(ByVal
sender As
System.Object, ByVal
e As
System.EventArgs)
Handles
MyBase.Load
' Resize
...
'
PictureBox control
Me.PictureBox1.Left
= (Me.Width
- Me.PictureBox1.Width)
/ 2
Me.PictureBox1.Top
= Me.Height
/ 4
' Label
control
Me.Label1.Width
= Me.Width
- 100
Me.Label1.Left
= (Me.Width
- Me.Label1.Width)
/ 2
Me.Label1.Top
= Me.Height
* 3 / 4
'
StatusBar Panel 1, Message ...
Me.StatusBarPanel1.Text
= "Hello ..."
'
StatusBarPanel2, Date ...
Dim VDate As New
DateTime
Me.StatusBarPanel2.Text
= VDate.Now.ToLongDateString
End
Sub
Private
Sub
MenuItem6_Click(ByVal
sender As
System.Object, ByVal
e As
System.EventArgs)
Handles
MenuItem6.Click
' close
all forms
Application.Exit()
End
Sub
Private
Sub
Timer1_Tick(ByVal
sender As
System.Object, ByVal
e As
System.EventArgs)
Handles
Timer1.Tick
Dim vtime As New
System.DateTime
'
StatusBarPanel2, Time ...
Me.StatusBarPanel3.Text
= vtime.Now.ToLongTimeString.ToString
End
Sub
Private
Sub
MenuItem4_Click(ByVal
sender As
System.Object, ByVal
e As
System.EventArgs)
Handles
MenuItem4.Click
'
StatusBar Panel 1 = Message
Me.StatusBarPanel1.Text
= "About Form, moment ..."
Dim f As New
About
f.Show()
End
Sub
Private
Sub
MenuItem2_Click(ByVal
sender As
System.Object, ByVal
e As
System.EventArgs)
Handles
MenuItem2.Click
'
StatusBar Panel 1 = Message
Me.StatusBarPanel1.Text
= "Book Form, moment ..."
Dim f As New
Book
f.Show()
End
Sub
End
Class |
|
|
|
|