|
The Form design, mainform.cs
Rename
the Form Form1.cs created and add new controls to it
Classes used in this Form: Timer,
ImageList, ToolBar, Label, Panel, PictureBox, Button,
MainMenu
1-
Rename the Form
- On the View
menu , click Solution
Explorer
- In Solution
Explorer, expand the work_VCnet
project node and select
Form1.cs
- In
Properties windows, Type the new
File Name
|
Old |
New |
Filename : |
Form1.cs |
mainform.cs | | |
2- Picture files used by this form
...
- The folder
c:\work_VCNet10\work_VCNet10\pic stored the
bmp files
z_calculator.bmp,
z_booknot.bmp,
z_agenda.bmp, z_intro.bmp,
z_about.bmp
calculator_2.bmp, address book_2,
agenda_1. bmp, intro_icon_2.bmp,
about_icon_2
|
3- Modify the Form Properties
...
- On the View
menu , click Solution
Explorer
- In Solution
Explorer, expand the work_VCnet
project node
- Right click the
mainform.cs 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 940,
758 work VC#
2010,
main Maximized | | | |
- On the Project
menu , click work_VCnet Properties ...,
the work_VCnet Property Pages dialog box
appears
- In the Startup
object combo box, choose and select
mainform
- Click OK
|
1- |
The mainform.cs
design |
|
 |
2- |
From the Toolbox/Windows Form add these
controls ...
5 PictureBox
controls, 3 Label controls, 2
Panel controls, 1 Timer control,
1 ImageList control, 1
Button control, 1
ToolBar control, 1 MainMenu
control |
|
- Add
5 PictureBox
controls
- PictureBox1,
PictureBox
Properties
Name: Image: Size
Mode: |
PictureBox1 System.Drawing.Bitmap Autosize | |
Bitmap
file added =
C:\work_VCNet10\work_VCNet10\pic\
z_calculator.bmp
- PictureBox2
-
Bitmap file added =
C:\work_VCNet10\work_VCNet10\pic\
z_booknot.bmp
- PictureBox3
-
Bitmap file added =
C:\work_VCNet10\work_VCNet10\pic\
z_agenda.bmp
- PictureBox 4
-
Bitmap file added =
C:\work_VCNet10\work_VCNet10\pic\z_intro.bmp
- PictureBox 5
-
Bitmap file added =
C:\work_VCNet10\work_VCNet10\pic\z_about.bmp
|
- Add
the 3 Label
control
- Lrbt, Label
Properties:
Font: Name: Size: Text: TextAlign: |
Times New Roman, 14pt,
style=Bold,
Italic Lrbt 152,
22 work2010
system MiddleCenter | |
- ltimer
-
Text:
timer
- lblb
-
Text:
""
|
- Add
2
Panel
controls
- Panel1, Panel
Properties
Name: Size: |
Panel1 156,
632 | |
- Panel11
-
Size: 156,
576
|
- Add
the
ImageList control
- ImageList,
ImageListProperties:
Name: Images: ImageSize: |
ImageList1 (Collection)
- of 5
Bitmap
images 56,
36 | |
The
folder
c:\work_VCNet10\work_VCNet10\pic stored the
5 bmp files
calculator_2.bmp, address
book_2, agenda_1. bmp,
intro_icon_2.bmp,
about_icon_2.bmp
- Add
the
Button control
- Btntools , Button
Properties:
Name: BackColor: Size: Text: |
Btntools DarkGray 150,
20 tools | |
- Add
the Timer
control
- Timer1,
Timer Properties:
Name: Enabled: Interval: |
Timer1 True 100 | |
- Add the ToolBar
control,
ToolBar1
ToolBar
controls are used to display ToolBarButton
controls that can appear as a
standard button, a
toggle-style button, or a drop-down style button. You
can assign images to the
buttons by creating an
ImageList, assigning it to the ImageList property of
the ToolBar, and assigning the
image index value to the
ImageIndex property each
ToolBarButton. You can then assign text to be
displayed underneath or to the
right of the image by
setting the Text
property of the
ToolBarButton.
ToolBar
control added to this
form - ToolBar1
- 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
MainMenu1
Item |
Name |
Text |
1 1.1 1.2 1.3
1.4
1.5
2
2.1 |
Menutools Menubooknote Menuagenda Menucal
Menuintroductory
Menuabout
Menuexit
Menuquit |
tools book
note agenda calculator
introductory
about work 2010
exit
quit |
| | | |
|
How create Public Event in
Visual C# 2010
mainform.cs file, the
code ...
|
|
using
System;
using
System.Collections.Generic;
using
System.ComponentModel;
using System.Data;
using
System.Drawing;
using System.Linq;
using System.Text;
using
System.Windows.Forms;
namespace
work_VCnet10
{
public
partial
class
mainform
:
Form
{
//variable
System.Windows.Forms. DialogResult
response;
string msg_inf;
//private System.Windows.Forms.Label ltimer;
bool flg_close;
public
class
mainform_cl
{
public
static
string Title =
"work .net 2010 application, Message";
//cuurent directory
public
static
string current_path
=
"C:\\work_VCnet10\\work_VCnet10";
}
public mainform()
{
InitializeComponent();
}
private
void
mainform_Load(object
sender,
EventArgs
e)
{
int var;
//resize
this.Lrbt.Left =
this.ToolBar1.Width
- (this.Lrbt.Width
+ 30);
this.Lrbt.Top = 2;
this.ltimer.Left =
this.Lrbt.Left
+ ((this.Lrbt.Width
-
this.ltimer.Width) /
2);
this.ltimer.Top =
this.Lrbt.Top
+
this.Lrbt.Height;
this.lblb.Width =
this.Panel1.Width
/ 5;
this.lblb.Left = 4;
this.lblb.Top =
this.ToolBar1.Top
+
this.ToolBar1.Height
+ 6;
this.Panel1.Left =
this.lblb.Left;
this.Panel1.Top =
this.lblb.Top;
this.Panel1.Height =
this.Height
- (this.ToolBar1.Height
* 6 / 2);
this.Panel11.Width =
this.Panel1.Width;
this.Btntools.Width
=
this.Panel11.Width;
this.Panel11.Height
=
this.Panel1.Height -
(this.Btntools.Height
* 1) + 8;
this.Panel11.Left =
0;
this.Pic_booknote.Left
=
this.Pic_calculator.Left;
this.Pic_agenda.Left
=
this.Pic_calculator.Left;
this.Pic_intro.Left
=
this.Pic_calculator.Left;
this.Pic_about.Left
=
this.Pic_about.Left;
var = ( this.Panel11.Height
- (this.Pic_calculator.Height
* 5)) / 7;
this.Pic_calculator.Top
= var;
this.Pic_booknote.Top
=
this.Pic_calculator.Top
+
this.Pic_calculator.Height
+ var;
this.Pic_agenda.Top
=
this.Pic_booknote.Top
+
this.Pic_booknote.Height
+ var;
this.Pic_intro.Top =
this.Pic_agenda.Top
+
this.Pic_agenda.Height
+ var;
this.Pic_about.Top =
this.Pic_intro.Top
+
this.Pic_intro.Height
+ var;
this.Lrbt.Visible =
true;
this.ltimer.Visible
=
true;
flg_close =
true;
// Time ...
// this.ltimer.Text = System.DateTime.Now.ToLongTimeString();
}
private
void
mainform_Closing(object
sender, System.ComponentModel.CancelEventArgs
e)
{
if (flg_close ==
true)
{
msg_inf =
"are you
sure want to exit Work .net";
response =
MessageBox.Show(msg_inf,
"work VC# 2010, main",
MessageBoxButtons.YesNo,
System.Windows.Forms.MessageBoxIcon.Information);
flg_close =
false;
}
if (response ==
DialogResult.Yes)
{
Application.Exit();
}
if (response ==
DialogResult.No)
{
e.Cancel =
true;
flg_close =
true;
}
}
private
void
mainform_MouseMove(object
sender, System.Windows.Forms.MouseEventArgs
e)
{
this.Panel1.Visible
=
false;
}
private
void
Menuquit_Click(object
sender,
EventArgs
e)
{
sub_close();
}
private
void
sub_close()
{
if (flg_close ==
true)
{
msg_inf =
"are you
sure want to exit Work .net";
response =
MessageBox.Show(msg_inf,
"work VC# 2010, main",
MessageBoxButtons.YesNo,
System.Windows.Forms.MessageBoxIcon.Information);
flg_close =
false;
}
if (response ==
DialogResult.Yes)
{
Application.Exit();
}
if (response ==
DialogResult.No)
{
flg_close =
true;
}
}
private
void
Timer1_Tick(object
sender,
EventArgs
e)
{
// Time ...
this.ltimer.Text =
System.DateTime.Now.ToLongTimeString();
}
private
void
lblb_MouseMove(object
sender, System.Windows.Forms.MouseEventArgs
e)
{
this.Panel1.Visible
=
true;
Sub_Top1();
}
private
void
Btntools_Click(object
sender,
EventArgs
e)
{
Sub_Top1();
}
private
void
Sub_Top1()
{
this.Panel1.Visible
=
true;
this.Btntools.Top =
4;
}
private
void
Menubooknote_Click(object
sender,
EventArgs
e)
{
sub_booknote();
}
private
void
sub_booknote()
{
book_note Fbook_note
=
new
book_note();
Fbook_note.Show();
}
private
void
Menuagenda_Click(object
sender,
EventArgs
e)
{
sub_agenda();
}
private
void
sub_agenda()
{
agenda Fagenda =
new
agenda();
Fagenda.Show();
}
private
void
Menucal_Click(object
sender,
EventArgs
e)
{
sub_calculator();
}
private
void
sub_calculator()
{
calculator
Fcalculator =
new
calculator();
Fcalculator.Show();
}
private
void
Menuintroductory_Click(object
sender,
EventArgs
e)
{
sub_intro();
}
private
void
sub_intro()
{
introductory Fintro
=
new
introductory();
Fintro.Show();
}
private
void
Menuabout_Click(object
sender,
EventArgs
e)
{
sub_about();
}
private
void
sub_about()
{
about Fabout =
new
about();
Fabout.Show();
}
private
void
ToolBar1_ButtonClick(object
sender, System.Windows.Forms.ToolBarButtonClickEventArgs
e)
{
switch (this.ToolBar1.Buttons.IndexOf(e.Button))
{
//calculator
case 2:
sub_calculator();
break;
//Book note
case 5:
sub_booknote();
break;
//agenda
case 8:
sub_agenda();
break;
//introductory
case 11:
sub_intro();
break;
//about
case 14:
sub_about();
break;
}
}
private
void
Pic_calculator_Click(object
sender,
EventArgs
e)
{
sub_calculator();
}
private
void
Pic_booknote_Click(object
sender,
EventArgs
e)
{
sub_booknote();
}
private
void
Pic_agenda_Click(object
sender,
EventArgs
e)
{
sub_agenda();
}
private
void
Pic_intro_Click(object
sender,
EventArgs
e)
{
sub_intro();
}
private
void
Pic_about_Click(object
sender,
EventArgs
e)
{
sub_about();
}
}
}
| | |
|
|