Professional Documents
Culture Documents
سبيلك المختصر لتعلم #C- برمجة الواجهات
سبيلك المختصر لتعلم #C- برمجة الواجهات
Net
:
" .
"
70 : 71
... ... ...
:
Khalid_Essaadani@Hotmail.Fr
10
13
15 Design environment
29 Controls
29 Properties
34
Events Controls
1 2. 3. 4.
39 39
Button
43 TextBox 46 RichTextBox
47 Label,LinkLabel
48 50
CheckBox
RadioButton 52 55 58 ListBox
ComboBox TreeView
62
ImageList 69 ListView
93
DataGridView MenuStrip
104 110
Panel PictureBox
19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32.
137 138
DateTimePicker
145 146
154
161
168
SDI
10
11
12
13
using System; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { Console.BackgroundColor = ConsoleColor.Yellow; Console.ForegroundColor = ConsoleColor.Red; Console.Write("Hi Brothers ! "); Console.ReadKey(); } } }
Hi Brothers !
14
Console.Beep();
Design environment
New project
File Ctrl+Shift+N
15
Windows Forms
Visual c# Application OK
ToolBox View
16
Ctrl+Alt+X
Form
17
Solution Explorer
Solutions Explorer
View Ctrl+Alt+L
18
Properties
F4
Properties
19
Toolbox Button
Text
20
21
BackColor
22
Namespaces
23
System.Console.WriteLine() Console.WriteLine()
System.Windows.Forms System.Windows.Forms.Control
Controls
24
namespace WindowsFormsApplication2
Classes using
partial
Form1.Designer.cs
25
Form1
Form1.Designer.cs
namespace WindowsFormsApplication2 { partial class Form1 { /// <summary> /// Variable ncessaire au concepteur. /// </summary> Form1 namespace WindowsFormsApplication2 { public partial class Form1 : Form
26
Form1
Constructors
Click
27
:
private void button1_Click(object sender, EventArgs e) { MessageBox.Show(";)"! }
28
Properties Control
29
Text
BackColor
Form
BackgroundImage
BackgroundImageLayout
ForeColor
Font
Name
30
Name
Text
Tab
TabIndex
Width
Height
False
True
Visible
False
Anchor
31
Parent
Cursor
ico
Icon
1 1 0
Opacity
MaximizeBox
32
MinimizeBox
WindowState
Normal
Maximized
Minimized Location
StartPosition
CenterParent
CenterScreen
33
WindowsDefaultLocation
Events
34
Button
35
Click
DoubleClick
BackColorChanged
FormClosing
36
FormClosed
Load
KeyDown
KeyUp
KeyPress KeyPress
KeyUp
KeyDown KeyUp
KeyPress
KeyDown GotFocus
Focus
LostFocus
37
Focus MouseDown
Click
MouseUp
Click MouseMove
Resize
Focus
Validated
38
Controls
Button Button
39
Comic Sans MS
40
Click
.
System.Drawing
using System; using System.Windows.Forms; using System.Drawing; namespace ButtonTest { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { this.BackColor=Color.Green; } } }
41
Click
private void button2_Click(object sender, EventArgs e) { this.Font = new Font("Comic Sans MS", 12); }
Font
Click
42
this
TextAlign
MaxLength
43
MultiLine
ReadOnly
PasswordChar
CharacterCasing
RighToLeft
44
Name
textName
textBox1 Click
private void button1_Click(object sender, EventArgs e) { MessageBox.Show("Salamo alaikom Mr: " + textName.Text); }
45
RichTextBox TextBox
this.richTextBox1.SelectionColor = Color.Red;
46
Label,LinkLabel
LinkLabel
Label HyperLink
LinkClicked
LinkLabel
System.Diagnostics
47
using System; using System.Windows.Forms; using System.Diagnostics; namespace LinkLabelTest { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { Process.Start("www.google.com"); } } }
CheckBox
48
True
ThreeState
Checked
UnChecked
49
private void button1_Click(object sender, EventArgs e) { // if (CheckVB.Checked == true && CheckCS.Checked == false) { MessageBox.Show("Your Favourite language is : Visual Basic.net"); } // else if (CheckVB.Checked == false && CheckCS.Checked == true) { MessageBox.Show("Your Favourite language is : CSharp.net"); } // else if (CheckVB.Checked == false && CheckCS.Checked == false) { MessageBox.Show("Please Choose Your language !"); } // else { MessageBox.Show("Your Favourite language is : Visual Basic.net and CSharp.Net"); } }
RadioButton
50
CheckBox
51
ListBox :
Items Load
Double Click
52
private void Form1_Load(object sender, EventArgs e) { this.listBox1.Items.Add("First Item"); this.listBox1.Items.Add("Second Item"); this.listBox1.Items.Add("Third Item"); }
initialize()
Form1
public partial class Form1 : Form { public Form1() { InitializeComponent(); this.listBox1.Items.Add("First Item"); this.listBox1.Items.Add("Second Item"); this.listBox1.Items.Add("Third Item"); } }
ListBox
Button
TextBox Label
53
Add To list
Add To list
Click
Add
54
this.listBox1.Items.Clear();
Arrays
namespace ListBoxFromArrays { public partial class Form1 : Form { public Form1() { InitializeComponent(); string[] WeekDay = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" }; this.listBox1.Items.AddRange(WeekDay); } } }
ListBox ComboBox
AddRang
55
ListBox
Items AddRange
56
namespace ComboboxTest { public partial class Form1 : Form { public Form1() { InitializeComponent(); string[] Countries = {"Egypt","Morrocco","Algeria","Iraq","Tunisia","Libya"}; this.comboBox1.Items.AddRange(Countries); } } }
SelectedIndexChanged
DropDownList
57
Files
Drives
58
Folders
Nodes
59
Node
Nodes
60
namespace TreeViewTest { public partial class Form1 : Form { public Form1() { InitializeComponent(); // treeView1.Nodes.Add("Animal"); treeView1.Nodes[0].Nodes.Add("Tiger"); treeView1.Nodes[0].Nodes.Add("Lion"); treeView1.Nodes[0].Nodes.Add("Cat"); treeView1.Nodes[0].Nodes.Add("Dog"); treeView1.Nodes[0].Nodes.Add("Cow"); // treeView1.Nodes.Add("Language"); treeView1.Nodes[1].Nodes.Add("Visual Basic.net"); treeView1.Nodes[1].Nodes.Add("Csharp.net"); treeView1.Nodes[1].Nodes.Add("J2EE"); treeView1.Nodes[1].Nodes.Add("Python"); treeView1.Nodes[1].Nodes.Add("C++"); treeView1.Nodes[1].Nodes.Add("Delphi"); } } }
ImageList
61
ImageList
10
Images TreeView
62
ImageList
63
64
ImageList1 1 0 TreeView
treeView1.Nodes.Add("Animal");
ImageList1
Add
65
treeView1.Nodes.Add("" ,"" , , ;)
public partial class Form1 : Form { public Form1() { InitializeComponent(); // treeView1.Nodes.Add("","Animal",0,0); treeView1.Nodes[0].Nodes.Add("", "Tiger", 1, 1); treeView1.Nodes[0].Nodes.Add("", "Lion", 1, 1); treeView1.Nodes[0].Nodes.Add("", "Cat", 1, 1); treeView1.Nodes[0].Nodes.Add("", "Dog", 1, 1); treeView1.Nodes[0].Nodes.Add("", "Cow", 1, 1); // treeView1.Nodes.Add("", "Language", 0,0); treeView1.Nodes[1].Nodes.Add("", "Visual Basic.net", 1, 1); treeView1.Nodes[1].Nodes.Add("", "Csharp.net", 1, 1); treeView1.Nodes[1].Nodes.Add("", "J2EE", 1, 1); treeView1.Nodes[1].Nodes.Add("", "Python", 1, 1); treeView1.Nodes[1].Nodes.Add("", "C++", 1, 1); treeView1.Nodes[1].Nodes.Add("", "Delphi", 1, 1); } }
F5
66
67
Checked
foreach (TreeNode Node in this.treeView1.Nodes) { if (Node.Checked == true) { //Do Something :) } }
68
ListView ListBox
11
Windows Explorer
69
. ListView
DropDownList
DropDownStyle
ImageList
ListView
ImageList1 ListView
70
71
ListView
Edit Groups
Tile
View
Large ImageList
72
ImageList1 Listview
namespace TreeViewTest { public partial class Form1 : Form { public Form1() { InitializeComponent(); listView1.Items.Add("Folder listView1.Items.Add("Folder listView1.Items.Add("Folder listView1.Items.Add("Folder listView1.Items.Add("Folder } } }
Add
73
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { if (comboBox1.Text == "LargeIcon") { listView1.View = View.LargeIcon; } else if (comboBox1.Text == "Details") { listView1.View = View.Details; } else if (comboBox1.Text == "SmallIcon") { listView1.View = View.SmallIcon; } else if (comboBox1.Text == "List") { listView1.View = View.List; } else { listView1.View = View.Tile; } }
Details
74
Edit Columns
public partial class Form1 : Form { public Form1() { InitializeComponent(); listView1.Columns.Add("Name"); listView1.Columns.Add("Description"); listView1.Items.Add("Folder 1", 0); listView1.Items.Add("Folder 2", 0); listView1.Items.Add("Folder 3", 0); listView1.Items.Add("Folder 4", 0); listView1.Items.Add("Folder 5", 0); } }
75
Methodes
76
ImageList
77
ImageList
ListView1
78
tvFolders
lvFiles
Type
79
80
ImageList1
81
System.IO
using System.IO;
strDrive
using System; using System.Windows.Forms; using System.IO; namespace WindowsFormsApplication1 { public partial class Form1 : Form { string strDrive;
Methods
82
:getDrives()
lvDrives
:getFolders() :getFiles(string strPath)
getDrives()
GetLogicalDrives() lvDrives
getFolders() void getFolders() { strDrive = lvDrives.FocusedItem.Text; DirectoryInfo Dir = new DirectoryInfo(strDrive); tvFolders.Nodes.Clear(); foreach (DirectoryInfo Folder in Dir.GetDirectories()) { tvFolders.Nodes.Add("", Folder.Name, 1, 1); } }
Directory
83
strDrive = lvDrives.FocusedItem.Text;
strDrive
strDrive
Dir DirectoryInfo
tvFolders.Nodes.Clear();
tvFolders Drives
foreach (DirectoryInfo Folder in Dir.GetDirectories()) { tvFolders.Nodes.Add("", Folder.Name, 1, 1); }
84
getFiles(string strPath)
void getFiles(string strPath) { ListViewItem lvi; DirectoryInfo Dir = new DirectoryInfo(strDrive+ strPath); lvFiles.Items.Clear(); foreach (FileInfo file in Dir.GetFiles()) { lvi = lvFiles.Items.Add(file.Name,2); lvi.SubItems.Add(file.Length.ToString()); lvi.SubItems.Add(file.LastAccessTime.ToString()); lvi.SubItems.Add(file.Extension); } }
strPath
ListViewItem lvi;
ListViewItem
lvi lvFiles
Drives
85
lvFiles.Items.Clear();
getDrives()
InitializeComponent()
public Form1() { InitializeComponent(); getDrives(); }
86
Double_Click
private void lvDrives_DoubleClick(object sender, EventArgs e) { getFolders(); }
After_Select tvFolders
private void tvFolders_AfterSelect(object sender, TreeViewEventArgs e) { getFiles(e.Node.FullPath); TreeNode node; DirectoryInfo Dir = new DirectoryInfo(strDrive + e.Node.FullPath); foreach (DirectoryInfo folder in Dir.GetDirectories()) { node = new TreeNode(folder.Name, 1, 1); e.Node.Nodes.Add(node); } }
getFiles(e.Node.FullPath);
e.Node.FullPath
87
TreeNode node;
node
88
89
using System; using System.Windows.Forms; using System.IO; namespace WindowsExplorer { public partial class Form1 : Form { string strDrive; //First method void getDrives() { foreach (string drive in Directory.GetLogicalDrives()) { this.lvDrives.Items.Add(drive,0); } } //Second Method void getFolders() { strDrive = lvDrives.FocusedItem.Text; DirectoryInfo Dir = new DirectoryInfo(strDrive); tvFolders.Nodes.Clear(); foreach (DirectoryInfo Folder in Dir.GetDirectories()) { tvFolders.Nodes.Add("", Folder.Name, 1, 1); } } //Third Method void getFiles(string strPath) { ListViewItem lvi; DirectoryInfo Dir = new DirectoryInfo(strDrive+ strPath); lvFiles.Items.Clear(); foreach (FileInfo file in Dir.GetFiles()) { lvi = lvFiles.Items.Add(file.Name,2); lvi.SubItems.Add(file.Length.ToString()); lvi.SubItems.Add(file.LastAccessTime.ToString()); lvi.SubItems.Add(file.Extension); } }
90
public Form1() { InitializeComponent(); getDrives(); } private void lvDrives_DoubleClick(object sender, EventArgs e) { getFolders(); } private void tvFolders_AfterSelect(object sender, TreeViewEventArgs e) { getFiles(e.Node.FullPath); // TreeNode node; DirectoryInfo Dir = new DirectoryInfo(strDrive + e.Node.FullPath); foreach (DirectoryInfo folder in Dir.GetDirectories()) { node = new TreeNode(folder.Name, 1, 1); e.Node.Nodes.Add(node); } } } }
ListView Grouping
91
ImageList
ListView
InitializeComponent()
//Create 3 groups listView1.Groups.Add("", "Programmes"); listView1.Groups.Add("", "Books"); listView1.Groups.Add("", "Media"); //Add 2 items to the first group listView1.Items.Add("Internet explorer", 1); listView1.Items[0].Group = listView1.Groups[0]; listView1.Items.Add("Adobe Photoshop", 0); listView1.Items[1].Group = listView1.Groups[0]; //Add 1 item to the second group listView1.Items.Add("" , 3); listView1.Items[2].Group = listView1.Groups[1]; //Add 1 item to the third group listView1.Items.Add("Western Film", 2); listView1.Items[3].Group = listView1.Groups[2];
92
DataGridView
12
Excel
93
. DataGridView
DataGridView
94
95
Add
96
97
Enable Editing
98
DataTable
99
Columns
Arrays Rows
System.Data
dTable
DataTable dTable = new DataTable();
dTable
DataColumn
DataColumn Name = new DataColumn("Name",typeof(string)); dTable.Columns.Add(Name); DataColumn Address = new DataColumn("Address",typeof(string)); dTable.Columns.Add(Address); DataColumn BirthDate = new DataColumn("Birth Date",typeof(DateTime)); dTable.Columns.Add(BirthDate);
100
DataTable TypeOf()
Column
DataColumn
dTable.Rows.Add(new object[] { "Khalid", "Morocco", new DateTime(1989, 5, 18) }); dTable.Rows.Add(new object[] { "Hamid", "France", new DateTime(1989, 10, 22) }); dTable.Rows.Add(new object[] { "Mohamed", "Canada", new DateTime(1988, 9, 1) }); dTable.Rows.Add(new object[] { "Younes", "Italia", new DateTime(187, 7, 12) });
dTable
Rows
dTable object
DataGridView
101
this.dataGridView1.DataSource = dTable;
namespace DataGridViewTest { public partial class Form1 : Form { public Form1() { InitializeComponent(); DataTable dTable = new DataTable(); DataColumn Name = new DataColumn("Name",typeof(String)); dTable.Columns.Add(Name); DataColumn Address = new DataColumn("Address",typeof(String)); dTable.Columns.Add(Address); DataColumn BirthDate = new DataColumn("Birth Date",typeof(DateTime)); dTable.Columns.Add(BirthDate); dTable.Rows.Add(new new DateTime(1989, 5, 18) }); dTable.Rows.Add(new DateTime(1989, 10, 22) }); dTable.Rows.Add(new new DateTime(1988, 9, 1) }); dTable.Rows.Add(new new DateTime(187, 7, 12) }); } } } object[] { "Khalid ESSAADANI", "Morocco", object[] { "Hamid MAKBOUL", "France", new object[] { "Mohamed ELKHAL", "Canada", object[] { "Younes MAADANE", "Italia",
this.dataGridView1.DataSource = dTable;
102
DataGridView
AllowUserToAddRows
False
True AllowUserToDeleteRows
False
True AllowUserToOrderColumns
False
True AllowUserToResizeColumns
False
True AllowUserToResizeRows
False
True AlternatingRowsDefaultCellStyle
103
ScrollBars
SelectionMode
FullRowSelect
MenuStrip
13
104
MenuStrip
105
MenuItem ComboBox
Forms MenuStrip
106
File
Form1
Windows Form
Add
Ctrl+Shift+A
107
OK
Form2 2
Form2 frm;
108
Form2
109
ContextMenuStrip
14
ContextMenuStrip .
110
MenuStrip
ContextMenuStrip1
ContextMenu
111
112
ContextMenuStrip
:DataGridView
113
ToolStrip
15
ToolStrip
114
Button
TextBox
2 Buttons
ToolStrip
115
TextChanged Label1
116
toolStripTextBox1 ToolStrip
Label1
size
public partial class Form1 : Form { int size = 12; public Form1() { InitializeComponent(); }
117
Click
private void toolStripButton1_Click(object sender, EventArgs e) { this.label1.Font =new Font("Tahoma", size); size += 4; }
4 4 -
private void toolStripButton2_Click(object sender, EventArgs e) { this.label1.Font = new Font("Tahoma", size); size -= 4; }
size
118
private void toolStripButton2_Click(object sender, EventArgs e) { if (size == 0) { size = 8; } this.label1.Font = new Font("", size); size -= 4; }
ToolStrip
119
StatusStrip
16
Microsoft Word
StatusLabel
120
InitializeComponent()
public partial class Form1 : Form { public Form1() { InitializeComponent(); this.toolStripStatusLabel1.Text = "Today is: " + DateTime.Now; this.toolStripStatusLabel1.Text += " The computer name is: " + Environment.MachineName; } }
DateTime MachineName
Now
Environnement
121
TabControl
17
Views
122
TabControl
Tabs
TabPages
SelectTab
123
tabControl1.SelectTab(1);
GroupBox Radio
18
Button
19
124
Visible Vertical GroupBox Horizontal Scrollbars FixedSingle BorderStyle True AutoScroll ScrollBars
PictureBox
20
BackGroundImage
Image
125
BackGroundImageLayout
ScrollBar VScrollBar
21
HScrollBar
126
HScrollBar
VScrollBar
Panel
VScrollBar
HScrollBar
127
TrackBar HScrollBar
128
250
Maximum
Minimum .
Scroll
private void RedSB_Scroll(object sender, ScrollEventArgs e) { this.BackColor = Color.FromArgb(RedSB.Value, GreenSB.Value, BlueSB.Value); } FromArgb
Scroll
129
TrackBar
22
130
PictureBox
TrackBar
131
trackBar1
132
ProgressBar
23
Minimum
133
Continuous
24
False True
Enabled
True Interval
134
1000
Interval timer1
True
ToLongTimeString
1000
Interval
135
Enabled
Timer
ProgressBar Interval
timer1
Tick
private void timer1_Tick(object sender, EventArgs e) { while (progressBar1.Value < progressBar1.Maximum) { progressBar1.Value += 2; } }
136
25
137
value
DateTime mydate = this.dateTimePicker1.Value;
MaskedTextBox TextBox
26
Mask
138
Blank
0 9 #
L ? & C A . , :
139
/ $ <
Lower Case
>
Upper case
|
NotifyIcon
27
InitializeComponent
140
notifyIcon1.Icon = this.Icon; notifyIcon1.BalloonTipIcon = ToolTipIcon.Warning; notifyIcon1.BalloonTipText = "Please update your program to the last version !"; notifyIcon1.BalloonTipTitle = "Warning Update"; notifyIcon1.ShowBalloonTip(12);
notifyIcon1
Icon
BalloonTipIcon
None
Error
Warning
141
Info
BalloonTipIcon
notifyIcon1.ShowBalloonTip(12);
12 s
142
ContextMenuStrip
NotifyIcon
143
ContextMenuStrip1
ContextMenuStrip
notifyIcon1
144
NumericUpDown
28
Minimum
145
DecimalPlaces 2
29
146
Items
147
SelectedIndex
this.domainUpDown1.SelectedIndex = 5;
30
WebBrowser
148
149
MaskedTextBox
150
Click
Go
webBrowser1.Navigate(textBox1.Text);
Navigate Click
webBrowser1.GoBack();
webBrowser1.GoForward();
GoHome Refresh
ColorDialog
31
Color
this.BackColor = colorDialog1.Color;
ColorDialog
151
Button
ColorDialog
152
Click
ColorDialog Button
ShowDialog
FontDialog Font
32
153
Click
Font
OpenFileDialog openFileDialog
33
154
Click
openFileDialog1.ShowDialog();
155
FileName
Filter
*.GIF
*.JPG *.TXT
156
Click
openFileDialog1.Filter = "Images Files|*.JPG;*.GIF,*.PNG"; openFileDialog1.Title = "Open your image"; if (openFileDialog1.ShowDialog() == DialogResult.OK) { pictureBox1.Image = Image.FromFile(openFileDialog1.FileName); }
157
OK pictureBox1
SaveFileDialog
34
158
FileName
159
*.GIF
*.JPG *.TXT
Save Text
Click
160
saveFileDialog1.Title = "Save Your Text"; saveFileDialog1.Filter = "Text Documents | *.TXT"; if (saveFileDialog1.ShowDialog() == DialogResult.OK) { System.IO.File.WriteAllText(saveFileDialog1.FileName, richTextBox1.Text); }
35
161
SelectedPath
string folderPath = folderBrowserDialog1.SelectedPath;
Print Tools
36
c#
162
PrintPreviewDialog
PrintDialog
163
PrintDocument
RichTextBox
164
printDocument1
Document printDocument1
165
PrintPage
PrintDocument
PrintDocument
Graphics
DrawString
RichTextBox 18 Tahoma
166
Click
Preview
printPreviewDialog1.ShowDialog();
Click
Click
printDialog1.ShowDialog();
DrawString Graphics
167
DrawImage
Graphics
SDI
MDI
37
168
MenuStrip
169
Click
frmChild this
170
True
IsMdiContainer
MdiParent
171
172
Khalid_ESSAADANI@Hotmail.Fr
173