12/05/2011
(cid:49)(cid:857)i dung
Introduction
Windows form
Control Properties and Layout
Ch(cid:1223)(cid:1215)ng 3 CONTROL
PictureBoxes
GroupBoxes and Panels
Labels, TextBoxes and Buttons
CheckBoxes and RadioButtons
2 1
1. Introduction
2. Windows form
(cid:127) Cho phép ng(cid:585)(cid:861)i phát tri(cid:640)n t(cid:606)o ra các giao di(cid:644)n ng(cid:585)(cid:861)i
(cid:127) Giao di(cid:644)n là ràng bu(cid:857)c, giao (cid:585)(cid:859)c (cid:255)(cid:608)m b(cid:608)o cho các l(cid:859)p
dùng s(cid:877) d(cid:869)ng các thành ph(cid:612)n khác nhau (components).
hay các c(cid:610)u trúc s(cid:634) th(cid:881)c hi(cid:644)n m(cid:857)t (cid:255)(cid:76)(cid:638)u gì (cid:255)ó.
(cid:127) (cid:48)(cid:857)t giao di(cid:644)n (cid:255)(cid:585)a ra m(cid:857)t s(cid:881) thay th(cid:636) cho các l(cid:859)p tr(cid:875)u
(cid:87)(cid:585)(cid:867)ng (cid:255)(cid:640) t(cid:606)o ra các s(cid:881) ràng bu(cid:857)c gi(cid:879)a nh(cid:879)ng l(cid:859)p và các thành ph(cid:612)n client c(cid:871)a nó.
(cid:127) (cid:48)(cid:857)t Form (cid:255)(cid:585)(cid:867)c ch(cid:606)y trên m(cid:857)t máy tính c(cid:869)c b(cid:857) (local machine) và m(cid:857)t form có th(cid:640) truy c(cid:618)p (cid:255)(cid:636)n các tài nguyên khác nhau nh(cid:585) b(cid:857) nh(cid:859), các th(cid:585) m(cid:869)c, các t(cid:644)p tin, các c(cid:583) s(cid:863) d(cid:879) li(cid:644)u…
(cid:127) Do (cid:255)ó Windows Form phù h(cid:867)p cho các (cid:873)ng d(cid:869)ng
desktop nh(cid:585) các (cid:873)ng d(cid:869)ng qu(cid:608)n lý thông tin, các (cid:873)ng (cid:71)(cid:869)ng t(cid:585)(cid:583)ng tác tr(cid:881)c ti(cid:636)p v(cid:859)i ng(cid:585)(cid:861)i dùng.
(cid:127) Khi m(cid:857)t l(cid:859)p th(cid:881)c thi m(cid:857)t giao di(cid:644)n, l(cid:859)p này ph(cid:608)i th(cid:881)c thi (cid:87)(cid:610)t c(cid:608) các ph(cid:585)(cid:583)ng th(cid:873)c c(cid:871)a giao di(cid:644)n. (cid:264)ây là m(cid:857)t b(cid:620)t bu(cid:857)c mà các l(cid:859)p ph(cid:608)i th(cid:881)c hi(cid:644)n.
(cid:127) Vai trò c(cid:871)a Windows Form:
(cid:127) Trong ch(cid:585)(cid:583)ng này chúng ta s(cid:634) th(cid:608)o lu(cid:618)n :
(cid:127) Cách t(cid:606)o, th(cid:881)c thi và s(cid:877) d(cid:869)ng các giao di(cid:644)n. (cid:127) Cách th(cid:881)c thi nhi(cid:638)u giao di(cid:644)n cùng v(cid:859)i cách k(cid:636)t h(cid:867)p
– (cid:59)(cid:877) lý d(cid:879) li(cid:644)u (cid:255)(cid:585)(cid:867)c nh(cid:618)p b(cid:863)i ng(cid:585)(cid:861)i dùng. – Hi(cid:640)n th(cid:648) (trình bày) các thông tin t(cid:859)i ng(cid:585)(cid:861)i dùng. – (cid:46)(cid:636)t n(cid:849)i (cid:255)(cid:636)n các ngu(cid:851)n CSDL khác nhau trên các máy tính c(cid:869)c b(cid:857)
ho(cid:628)c máy tính khác
và m(cid:863) (cid:85)(cid:857)ng giao di(cid:644)n
1
4 3
12/05/2011
Các tính n(cid:259)ng c(cid:871)a form
Windows form tính n(cid:259)ng m(cid:859)i
(cid:127) ClickOne Deployment: là m(cid:857)t k(cid:347) thu(cid:618)t cho phép t(cid:606)o các (cid:873)ng d(cid:869)ng
(cid:127) Trong .NET thì (cid:255)(cid:640) t(cid:606)o m(cid:857)t Windows Form ng(cid:347)a là
(cid:87)(cid:606)o m(cid:857)t (cid:255)(cid:849)i t(cid:585)(cid:867)ng t(cid:875) l(cid:859)p Form
(cid:127) (cid:47)(cid:859)p này n(cid:622)m trong Namespace có tên là
mà có th(cid:640)(cid:3)(cid:255)(cid:585)(cid:867)c cài (cid:255)(cid:628)t v(cid:859)i ít thao tác c(cid:871)a ng(cid:585)(cid:861)i dùng nh(cid:610)t. (cid:127) Application Settings (các thi(cid:636)t l(cid:618)p (cid:873)ng d(cid:869)ng): tính n(cid:259)ng này cho phép l(cid:585)u tr(cid:879) các thông tin toàn c(cid:869)c c(cid:376)ng nh(cid:585) các thông tin liên quan t(cid:859)i ng(cid:585)(cid:861)i dùng vào trong các ngu(cid:851)n l(cid:585)u tr(cid:879) (file XML, CSDL, các t(cid:644)p tin…)
System.Windows.Forms
(cid:127) New Windows Form Controls: tính n(cid:259)ng này cung c(cid:610)p các (cid:255)(cid:76)(cid:638)u
khi(cid:640)n m(cid:859)i, cho phép t(cid:606)o ra các (cid:873)ng d(cid:869)ng v(cid:859)i giao di(cid:644)n (cid:255)a d(cid:606)ng, phong phú h(cid:583)n.
(cid:127) New Data Binding Model (mô hình liên k(cid:636)t d(cid:879) li(cid:644)u m(cid:859)i): tính này
(cid:127) Nói cách khác :
(cid:81)(cid:259)ng cung c(cid:610)p m(cid:857)t cách (cid:255)(cid:583)n gi(cid:608)n, thu(cid:618)n ti(cid:644)n, m(cid:606)nh m(cid:634)(cid:3)(cid:255)(cid:640) liên k(cid:636)t các (cid:255)(cid:76)(cid:638)u khi(cid:640)n v(cid:859)i m(cid:857)t ngu(cid:851)n d(cid:879) li(cid:644)u
– (cid:47)(cid:859)p Form là l(cid:859)p tr(cid:875)u t(cid:585)(cid:867)ng hóa t(cid:610)t c(cid:608) các Windows
Form trong các (cid:873)ng d(cid:869)ng.
(cid:127) Rich Graphics (cid:11)(cid:255)(cid:851) h(cid:845)a phong phú): tính n(cid:259)ng này là s(cid:881) m(cid:863) r(cid:857)ng c(cid:871)a GDI lên GDI+ (cid:255)(cid:585)(cid:867)c s(cid:877) d(cid:869)ng cho vi(cid:644)c v(cid:634) và thao tác v(cid:859)i các hình (cid:608)nh
– (cid:48)(cid:855)i m(cid:857)t Windows Form là m(cid:857)t th(cid:640) hi(cid:644)n c(cid:869) th(cid:640) ((cid:255)(cid:849)i
(cid:87)(cid:585)(cid:867)ng) c(cid:871)a l(cid:859)p Form
6 5
(cid:55)(cid:606)o form
(cid:127) (cid:37)(cid:606)n có th(cid:640) s(cid:877) d(cid:869)ng tính n(cid:259)ng tr(cid:881)c quan (cid:255)(cid:640) thi(cid:636)t
(cid:127) Ch(cid:1233)n m(cid:1257)c Visual Studio .NET trong menu Start (cid:127) File (cid:214) New (cid:214) Project
(cid:79)(cid:618)p các (cid:255)(cid:76)(cid:638)u khi(cid:640)n
(cid:127) (cid:37)(cid:606)n c(cid:376)ng có th(cid:640) s(cid:877) d(cid:869)ng ch(cid:873)c n(cid:259)ng vi(cid:636)t code
(cid:255)(cid:640) t(cid:606)o các (cid:255)(cid:76)(cid:638)u khi(cid:640)n
(cid:127) (cid:37)(cid:606)n có th(cid:640) k(cid:636)t h(cid:867)p c(cid:608) 2 cách trên khi t(cid:606)o form
2
7 8
12/05/2011
3. Control Properties and Layout
9 10
Chi ti(cid:636)t l(cid:859)p form
Các ph(cid:585)(cid:583)ng th(cid:873)c
(cid:127) Show (cid:127) Hide (cid:127) ShowDialog
Hi(cid:640)n th(cid:648) m(cid:857)t Form (cid:613)n Form Hi(cid:640)n th(cid:648) Form d(cid:585)(cid:859)i d(cid:606)ng m(cid:857)t h(cid:857)p tho(cid:606)i Kích ho(cid:606)t Form
(cid:127) Activate
Height StartPosition Location Left Top Right Bottom FormBorderStyle
Tag
Name (cid:127) autosize (cid:127) Text (cid:127) (cid:127) Width (cid:127) (cid:127) (cid:127) (cid:127) (cid:127) (cid:127) (cid:127) (cid:127) (cid:127) MaximizeBox (cid:127) MinimizeBoz (cid:127)
TopMost
(cid:127)
Controls
tên form (cid:87)(cid:881) thay (cid:255)(cid:853)i kích th(cid:585)(cid:859)c form (cid:79)(cid:610)y/thi(cid:636)t l(cid:618)p tiêu (cid:255)(cid:638) c(cid:871)a Windows Form. (cid:255)(cid:857) r(cid:857)ng c(cid:871)a Form. chi(cid:638)u cao c(cid:871)a Form. ch(cid:646) ra v(cid:648) trí kh(cid:863)i (cid:255)(cid:857)ng ban (cid:255)(cid:612)u c(cid:871)a Form. ch(cid:646) ra v(cid:648) trí theo t(cid:845)a (cid:255)(cid:857) x,y. (cid:87)(cid:845)a (cid:255)(cid:857) trái. (cid:87)(cid:845)a (cid:255)(cid:857) trên. (cid:87)(cid:845)a (cid:255)(cid:857) bên ph(cid:608)i. (cid:87)(cid:845)a (cid:255)(cid:857) bên d(cid:585)(cid:859)i. ch(cid:646) ra ki(cid:640)u vi(cid:638)n c(cid:871)a Form. cho phép hi(cid:640)n th(cid:648) nút phóng to hay ko? cho phép hi(cid:640)n th(cid:648) nút thu nh(cid:847) ko. thu(cid:857)c tính này th(cid:585)(cid:861)ng (cid:255)(cid:585)(cid:867)c s(cid:877) d(cid:869)ng (cid:255)(cid:640)(cid:3)(cid:255)ính kèm (cid:71)(cid:879) li(cid:644)u vào Form. cho phép Form luôn (cid:255)(cid:585)(cid:867)c hi(cid:640)n th(cid:648) trên t(cid:610)t c(cid:608) các Form khác ko. M(cid:628)c (cid:255)(cid:648)nh là ko (false). là t(cid:618)p h(cid:867)p các (cid:255)(cid:76)(cid:638)u khi(cid:640)n trên Form.
(cid:127)
3
12 11
12/05/2011
Các s(cid:881) ki(cid:644)n
Các (cid:255)(cid:76)(cid:638)u khi(cid:640)n
(cid:127) Init (cid:127) Load
(cid:127) Basic Controls (các khi(cid:640)n c(cid:583) b(cid:608)n) (cid:127) Value Setting Controls (các (cid:255)(cid:76)(cid:638)u khi(cid:640)n thi(cid:636)t l(cid:618)p
giá tr(cid:648))
(cid:127) Selection List Controls (các (cid:255)(cid:76)(cid:638)u khi(cid:640)n danh sách
ch(cid:845)n)
(cid:127) Grouping Controls (các (cid:255)(cid:76)(cid:638)u khi(cid:640)n nhóm) (cid:127) Graphics Controls (các (cid:255)(cid:76)(cid:638)u khi(cid:640)n (cid:255)(cid:851) h(cid:845)a)
(cid:127) FormClosing (cid:127) FormClosed
(cid:59)(cid:608)y ra sau khi Form (cid:255)(cid:585)(cid:867)c t(cid:606)o ra. (cid:59)(cid:608)y ra khi Form (cid:255)(cid:585)(cid:867)c n(cid:606)p vào b(cid:857) nh(cid:859) vào sau (cid:255)ó (cid:255)(cid:585)(cid:867)c hi(cid:640)n th(cid:648). S(cid:881) ki(cid:644)n này là th(cid:861)i (cid:255)(cid:76)(cid:640)m thích h(cid:867)p (cid:255)(cid:640) chúng ta l(cid:610)y d(cid:879) li(cid:644)u và gán cho các (cid:255)(cid:76)(cid:638)u khi(cid:640)n trên Form. X(cid:608)y ra tr(cid:585)(cid:859)c khi Form (cid:255)(cid:585)(cid:867)c (cid:255)óng. (cid:59)(cid:608)y ra sau khi Form (cid:255)(cid:585)(cid:867)c (cid:255)óng và tr(cid:585)(cid:859)c khi Form (cid:255)(cid:585)(cid:867)c gi(cid:608)i phóng kh(cid:847)i b(cid:857) nh(cid:859)
14 13
Quy t(cid:620)t (cid:255)(cid:628)t tên
4. Labels, TextBoxes and Buttons
(cid:127) Xem file QuyTacDatTen.pdf
(cid:127) Labels:
– Các nhãn – Gi(cid:608)i thích; minh ho(cid:606)
(cid:127) TextBoxes:
– Dùng nh(cid:618)p li(cid:644)u
(cid:127) Buttons:
– Các nút (cid:255)(cid:76)(cid:638)u khi(cid:640)n
4
16 15
12/05/2011
Labels
(cid:127) Font (cid:127) ForeColor (cid:127) Size (cid:127) TabIndex (cid:127) Text (cid:127) TextAlign
(cid:127) AutoSize (cid:127) Backcolor (cid:127) BorderColor (cid:127) BorderStyle (cid:127) Location(X, Y) (cid:127) Name
namespace WindowsFormsApplication3 {
18 17
code
TextBoxes
partial class Form1code {
private System.ComponentModel.IContainer components = null; protected override void Dispose(bool disposing) {
if (disposing && (components != null)) {
(cid:127) (cid:49)(cid:583)i (cid:255)(cid:585)a d(cid:879) li(cid:644)u vào bi(cid:636)n nh(cid:859) (cid:127) (cid:49)(cid:583)i (cid:255)(cid:585)a d(cid:879) li(cid:644)u t(cid:875) bi(cid:636)n nh(cid:859) ra hi(cid:640)n th(cid:648) (ít s(cid:877)
} base.Dispose(disposing);
(cid:71)(cid:869)ng)
this.label1 = new System.Windows.Forms.Label();
} #region Windows Form Designer generated code private void InitializeComponent() {
private System.Windows.Forms.Label label1;
this.label1.BackColor = System.Drawing.SystemColors.ActiveCaptionText; this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.label1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.label1.ForeColor = System.Drawing.SystemColors.MenuHighlight; this.ClientSize = new System.Drawing.Size(384, 262); components.Dispose(); this.label1.Location = new System.Drawing.Point(18, 40); this.label1.Name = "label1"; this.Controls.Add(this.label1); this.label1.Size = new System.Drawing.Size(100, 15); this.label1.TabIndex = 4; this.Name = "Form1"; this.label1.Text = "L(cid:1247)p CDTH11QN"; this.Text = "Chào b(cid:1186)n 1"; this.SuspendLayout(); this.label1.TextAlign = System.Drawing.ContentAlignment.TopCenter; this.ResumeLayout(false); //(cid:264)(cid:648)nh ngh(cid:347)a label this.PerformLayout(); //l(cid:644)nh khai báo các trình bày //khai báo label //khai báo form
} #endregion //(cid:255)(cid:648)nh ngh(cid:347)a label trong l(cid:859)p riêng
}
}
5
20 19
12/05/2011
namespace WindowsFormsApplication3 {
TextBoxes
partial class Form1code {
private System.ComponentModel.IContainer components = null; protected override void Dispose(bool disposing) {
if (disposing && (components != null)) {
components.Dispose();
} base.Dispose(disposing);
1.
L(cid:1188)y d(cid:1227) li(cid:1205)u t(cid:1225) textbox (cid:284)(cid:1223)a vào bi(cid:1201)n nh(cid:1216)
} #region Windows Form Designer generated code private void InitializeComponent() {
2. (cid:26)(cid:1223)a d(cid:1227) li(cid:1205)u t(cid:1225) bi(cid:1201)n nh(cid:1216) lên textbox
//(cid:264)(cid:648)nh ngh(cid:347)a TextBox
//l(cid:644)nh khai báo các trình bày
(cid:127) (cid:264)(cid:648)nh ngh(cid:347)a (cid:127) Khai báo: – Font – Color – Point – Multiline – Name – Enabled – Size – TabIndex
//khai báo TextBox //khai báo form, kích ho(cid:606)t textbox
(cid:127) Kích ho(cid:606)t (cid:127) Khai báo bi(cid:636)n riêng
} #endregion //(cid:255)(cid:648)nh ngh(cid:347)a text trong l(cid:859)p riêng
}
}
22 21
(cid:59)(cid:877) lý d(cid:879) li(cid:644)u
(cid:127) (cid:47)(cid:610)y d(cid:879) li(cid:644)u t(cid:875) textbox (cid:255)(cid:585)a vào bi(cid:636)n nh(cid:859):
so2 = Convert.ToInt32(txtso2.Text); ho(cid:628)c so1=Int32.Parse(txtso2.Text)
(cid:127) (cid:264)(cid:585)a d(cid:879) li(cid:644)u t(cid:875) bi(cid:636)n nh(cid:859) lên textbox:
Console.WriteLine("Tong cua so "+intso1+" va so "+intso2+" la "+inttong); ho(cid:628)c txtso3.Text = "" + so3;
this.txtso1 = new System.Windows.Forms.TextBox(); this.SuspendLayout(); this.txtso1.Font = new System.Drawing.Font("Times New Roman", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.txtso1.ForeColor = System.Drawing.Color.Maroon; this.txtso1.Location = new System.Drawing.Point(162, 103); this.txtso1.Name = "txtso1"; this.txtso1.Size = new System.Drawing.Size(70, 35); this.txtso1.TabIndex = 5; this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(384, 262); this.Controls.Add(this.txtso1); this.Name = "Form1"; this.Text = "Chao ban!"; this.ResumeLayout(false); this.PerformLayout(); private System.Windows.Forms.TextBox txtso1;
6
24 23
12/05/2011
Buttons
(cid:264)(cid:648)nh ngh(cid:347)a
this.bttinh = new System.Windows.Forms.Button();
(cid:127) Nút xác (cid:255)(cid:648)nh các (cid:86)(cid:881) ki(cid:644)n liên quan (cid:127) (cid:55)(cid:606)o Buttons: – (cid:264)(cid:648)nh ngh(cid:347)a – Khai báo
(cid:127) Thu(cid:857)c tính (cid:127) (cid:54)(cid:881) ki(cid:644)n (events)
– Kích ho(cid:606)t – Khai báo button thu(cid:857)c (cid:79)(cid:859)p riêng
26 25
Thu(cid:857)c tính
Ph(cid:585)(cid:583)ng th(cid:873)c và s(cid:881) ki(cid:644)n
(cid:127) Focus: Cho phép thi(cid:636)t l(cid:618)p khi kh(cid:863)i t(cid:606)o Form (cid:585)u
tiên (cid:255)(cid:76)(cid:638)u khi(cid:640)n TextBox
(cid:127) Click: (cid:59)(cid:608)y ra khi (cid:255)(cid:76)(cid:638)u khi(cid:640)n Button (cid:255)(cid:585)(cid:867)c nh(cid:610)n
(cid:127) Command: (cid:59)(cid:608)y ra khi (cid:255)(cid:76)(cid:638)u khi(cid:640)n Button (cid:255)(cid:585)(cid:867)c nh(cid:610)n. CommandName và CommandArgument (cid:255)(cid:585)(cid:867)c truy(cid:638)n qua s(cid:881) ki(cid:644)n
this.bttinh.Font = new System.Drawing.Font("Times New Roman", 14F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.bttinh.ForeColor = System.Drawing.Color.Red; this.bttinh.Location = new System.Drawing.Point(283, 103); this.bttinh.Name = "bttinh"; this.bttinh.Size = new System.Drawing.Size(66, 28); this.bttinh.TabIndex = 8; this.bttinh.Text = "Tính"; this.bttinh.UseVisualStyleBackColor = true; this.bttinh.Click += new System.EventHandler(this.bttinh_Click);
7
27 28
12/05/2011
Xác (cid:255)(cid:648)nh events
Kích ho(cid:606)t trong form
this.Controls.Add(this.lbtong);
private void bttinh_Click(object sender, EventArgs e) {
int so1, so2, so3; so1 = Convert.ToInt32(txtso1.Text); so2 = Int32.Parse(txtso2.Text); so3 = so1 + so2; txtso3.Text = Convert.ToString(so3);
}
“" + so3;
30 29
Khai báo button trong l(cid:859)p riêng
5. GroupBoxes and Panels
private System.Windows.Forms.Button bttinh;
(cid:127) Groupboxes:
– Vùng nhóm các trình bày – Thông th(cid:585)(cid:861)ng GroupBoxes s(cid:634) ch(cid:873)a:
(cid:127) RadioButton (cid:127) CheckBox
(cid:127) Panels:
– Vùng giao di(cid:644)n – Ch(cid:873)a nhi(cid:638)u (cid:255)(cid:849)i t(cid:585)(cid:867)ng
8
32 31
12/05/2011
GroupBoxes
namespace WindowsFormsApplication5 {
partial class Form1 {
private System.ComponentModel.IContainer components = null; protected override void Dispose(bool disposing) {
if (disposing && (components != null)) {
components.Dispose();
} base.Dispose(disposing);
} #region Windows Form Designer generated code private void InitializeComponent() {
this.groupBox1 = new System.Windows.Forms.GroupBox(); this.SuspendLayout(); // groupBox1 // Form1
} #endregion private System.Windows.Forms.GroupBox groupBox1;
}
}
34 33
// groupBox1
// Form1
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(584, 364); this.Controls.Add(this.groupBox1); this.Name = "Form1"; this.Text = "Form1"; this.ResumeLayout(false);
this.groupBox1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(255)))), ((int)(((byte)(192))))); this.groupBox1.Location = new System.Drawing.Point(97, 42); this.groupBox1.Name = "groupBox1"; this.groupBox1.Size = new System.Drawing.Size(241, 119); this.groupBox1.TabIndex = 0; this.groupBox1.TabStop = false; this.groupBox1.Text = "Nhóm công vi(cid:644)c";
9
35 36
12/05/2011
Panels
namespace WindowsFormsApplication5 {
partial class Form1 {
private System.ComponentModel.IContainer components = null; protected override void Dispose(bool disposing) {
if (disposing && (components != null)) {
components.Dispose();
} base.Dispose(disposing);
} #region Windows Form Designer generated code private void InitializeComponent() {
this.panel1 = new System.Windows.Forms.Panel(); this.SuspendLayout(); // panel1 // Form1
} #endregion private System.Windows.Forms.Panel panel1;
}
}
37 38
// panel1
// Form1
this.panel1.AutoScroll = true; this.panel1.BackColor = System.Drawing.SystemColors.ActiveCaption; this.panel1.Location = new System.Drawing.Point(34, 152); this.panel1.Name = "panel1"; this.panel1.Size = new System.Drawing.Size(448, 189); this.panel1.TabIndex = 1;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(584, 364); this.Controls.Add(this.panel1); this.Name = "Form1"; this.Text = "Form1"; this.ResumeLayout(false);
10
40 39
12/05/2011
6. CheckBoxes and RadioButtons
CheckBoxes
namespace WindowsFormsApplication5 {
(cid:127) CheckBoxes:
partial class Form1 {
private System.ComponentModel.IContainer components = null; protected override void Dispose(bool disposing) {
– Có nhi(cid:638)u l(cid:881)a ch(cid:845)n – (cid:37)(cid:606)n (cid:255)(cid:585)(cid:867)c phép:
if (disposing && (components != null)) {
components.Dispose();
} base.Dispose(disposing);
} #region Windows Form Designer generated code private void InitializeComponent() {
(cid:127) Ch(cid:845)n 1 ho(cid:628)c nhi(cid:638)u h(cid:583)n 1 (cid:127) Ch(cid:845)n t(cid:610)t c(cid:608) (cid:127) Không ch(cid:845)n (cid:127) RadioButtons
this.checkBox1 = new System.Windows.Forms.CheckBox(); this.SuspendLayout(); // checkBox1 // Form1
– Có nhi(cid:638)u l(cid:881)a ch(cid:845)n – (cid:37)(cid:606)n ch(cid:646)(cid:3)(cid:255)(cid:585)(cid:867)c ch(cid:845)n 1 mà thôi
} #endregion
(cid:127) (cid:54)(cid:877) d(cid:869)ng CheckBoxes và RadioButtons
private System.Windows.Forms.CheckBox checkBox1; }
}
41 42
// checkBox1
// Form1
this.checkBox1.AutoSize = true; this.checkBox1.Location = new System.Drawing.Point(33, 18); this.checkBox1.Name = "checkBox1"; this.checkBox1.Size = new System.Drawing.Size(48, 17); this.checkBox1.TabIndex = 0; this.checkBox1.Text = "Nam"; this.checkBox1.UseVisualStyleBackColor = true;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(519, 364); this.Controls.Add(this.groupBox2); this.Controls.Add(this.panel1); this.Controls.Add(this.groupBox1); this.Name = "Form1"; this.Text = "Form1"; this.groupBox1.ResumeLayout(false); this.groupBox1.PerformLayout(); this.groupBox2.ResumeLayout(false); this.groupBox2.PerformLayout(); this.ResumeLayout(false);
11
44 43
12/05/2011
// groupBox2
RadioButtons
namespace WindowsFormsApplication5 {
partial class Form1 {
private System.ComponentModel.IContainer components = null; protected override void Dispose(bool disposing) {
if (disposing && (components != null)) {
components.Dispose();
} base.Dispose(disposing);
} #region Windows Form Designer generated code private void InitializeComponent() {
this.radioButton1 = new System.Windows.Forms.RadioButton(); this.SuspendLayout(); // radioButton1 // Form1
this.groupBox2.Controls.Add(this.checkBox2); this.groupBox2.Controls.Add(this.checkBox1); this.groupBox2.Location = new System.Drawing.Point(233, 28); this.groupBox2.Name = "groupBox2"; this.groupBox2.Size = new System.Drawing.Size(108, 81); this.groupBox2.TabIndex = 2; this.groupBox2.TabStop = false; this.groupBox2.Text = "Gi(cid:859)i tính";
} #endregion
private System.Windows.Forms.RadioButton radioButton1; }
}
45 46
// radioButton1
// Form1
this.radioButton1.AutoSize = true; this.radioButton1.Location = new System.Drawing.Point(37, 25); this.radioButton1.Name = "radioButton1"; this.radioButton1.Size = new System.Drawing.Size(77, 17); this.radioButton1.TabIndex = 0; this.radioButton1.TabStop = true; this.radioButton1.Text = "Nh(cid:618)p (cid:255)(cid:76)(cid:632)m"; this.radioButton1.UseVisualStyleBackColor = true;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(519, 364); this.Controls.Add(this.groupBox1); this.Name = "Form1"; this.Text = "Form1"; this.groupBox1.ResumeLayout(false); this.groupBox1.PerformLayout(); this.ResumeLayout(false);
12
48 47
12/05/2011
// groupBox1
(cid:54)(cid:877) d(cid:869)ng RadioButton và Checkbox
(cid:127) (cid:48)(cid:869)c (cid:255)ích:
– Ki(cid:640)m soát ng(cid:585)(cid:861)i dùng click vào nút nào – Xác (cid:255)(cid:648)nh hành (cid:255)(cid:857)ng ti(cid:636)p theo là gì
(cid:127) Câu l(cid:644)nh:
radioButton3.Checked == true / false
this.groupBox1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(255)))), ((int)(((byte)(192))))); this.groupBox1.Controls.Add(this.radioButton4); this.groupBox1.Controls.Add(this.radioButton3); this.groupBox1.Location = new System.Drawing.Point(34, 27); this.groupBox1.Name = "groupBox1"; this.groupBox1.Size = new System.Drawing.Size(160, 83); this.groupBox1.TabIndex = 0; this.groupBox1.TabStop = false; this.groupBox1.Text = "Nhóm công vi(cid:644)c";
checkBox1.Checked == true / false
private void button1_Click(object sender, EventArgs e) { if (radioButton3.Checked==true)
congviec.Text="Nh(cid:618)p (cid:255)(cid:76)(cid:640)m";
if (radioButton4.Checked == true)
congviec.Text = "Tính (cid:255)(cid:76)(cid:640)m";
if (checkBox1.Checked == true)
gioitinh.Text = "Ng(cid:585)(cid:861)i Nam";
if (checkBox2.Checked == true)
gioitinh.Text = "Ng(cid:585)(cid:861)i N(cid:879)";
if ((checkBox1.Checked==true) && (checkBox2.Checked==true))
gioitinh.Text="Nam và N(cid:879)";
if ((checkBox1.Checked == false) && (checkBox2.Checked == false))
gioitinh.Text = "";
}
49 50
13
52 51
12/05/2011
7. PictureBoxes
7. PictureBoxes
(cid:127) AnchorStyles (cid:127) Name (cid:127) BackColor (cid:127) Image (cid:127) Size (cid:127) SizeMode
53 54
7. PictureBoxes
(cid:42)(cid:620)n event khi click vào (cid:608)nh
this.anh1 = new System.Windows.Forms.PictureBox();
private void pictureBox1_Click(object sender, EventArgs e)
((System.ComponentModel.ISupportInitialize)(this.anh1)).BeginInit();
{
this.SuspendLayout(); // anh1 this.anh1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.To p | System.Windows.Forms.AnchorStyles.Bottom)
//Câu l(cid:644)nh MessageBox.Show("B(cid:606)n (cid:255)ã ch(cid:845)n hoa t(cid:881) tr(cid:851)ng");
}
| System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right)));
this.anh1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; this.anh1.Image = global::Control.Properties.Resources.IMG_3264; this.anh1.Location = new System.Drawing.Point(44, 50); this.anh1.Name = "anh1"; this.anh1.Size = new System.Drawing.Size(155, 143); this.anh1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; this.anh1.TabIndex = 0; this.anh1.TabStop = false;
14
55 56
12/05/2011
Hi(cid:640)n th(cid:648) t(cid:875)ng (cid:608)nh trong picturebox
private void button1_Click(object sender, EventArgs e)
{
Thanks
imageNum = imageNum + 1; if (imageNum > 3) imageNum = 1; pictureBox1.Image =
Image.FromFile("D:/GIANGDAY/C#/Csharp_Basic/MINHHO A/picture/anh" + imageNum + ".jpg"); }
15
57 58