1. Trang chủ
  2. » Công Nghệ Thông Tin

Bài giảng Lập trình C# 2010: Chương 2 - ĐH Công nghệ Đồng Nai

46 12 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 46
Dung lượng 4,09 MB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Bài giảng Lập trình C# 2010: Chương 2 trình bày các kiến thức về Windows Forms and Windows Forms Controls trình bày cách tạo form, các thuộc tính phổ biến, các thao tác cơ bản và một số nội dung khác.

Trang 2

Component Control

Label Textbox Button

LinkLabel

ScrollableControl ContainerControl

Form

Trang 3

an application’s user interface

Trang 4

Create Form

1.Right Click on Project Name

2.Choose Add Item

3.Choose Windows Form…

Trang 7

Properties

Trang 8

Name Description

Text Gets or sets the text associated

with this control

Size Gets or sets the size of the form

WindowState Gets or sets the form's window state.

Normal; Minimized; Maximized

Font Gets or sets the font of the text

displayed by the control

Trang 9

Name Description

StartPosition Gets or sets the starting position

of the form at run time

Manual CenterScreen WindowsDefaultLocation WindowsDefaultBounds CenterParent

TopMost Gets or sets a value indicating

whether the form should be displayed as a topmost form

Trang 10

Name Description

FormBorderStyle Gets or sets the border

style of the form

None FixedSingle Fixed3D

FixedDialog Sizable

FixedToolWindow SizableToolWindow

Trang 11

Name Description

BackColor Gets or sets the background

color for the controlBackGroundImage Gets or sets the background

image displayed in the controlMainMenuStrip Gets or sets the primary

menu container for the formForceColor Gets or sets the foreground

color of the control

Trang 12

Name Description

Cursor Gets or sets the cursor that is

displayed when the mouse pointer is over the controlLocation Gets or sets the Point that

represents the upper-left corner

of the Form in screen coordinatesIcon Gets or sets the icon for the form

Opacity Gets or sets the opacity level of

the form

Trang 13

Name Description

AcceptButton Gets or sets the button on the

form that is clicked when the user presses the ENTER key

CancelButton Gets or sets the button control

that is clicked when the user presses the ESC key

Trang 14

Windows Forms

Trang 16

Name Description

Click Occurs when the control is

clicked (Inherited from Control.) DoubleClick Occurs when the control is double

-clicked (Inherited from Control.) Load Occurs before a form is displayed

for the first time

FormClosing Occurs before the form is closed

FormClosed Occurs after the form is closed

Trang 17

Name Description

KeyDown Occurs when a key is pressed

while the control has focus

(Inherited from Control.) KeyPress Occurs when a key is pressed

while the control has focus

(Inherited from Control.)KeyUp Occurs when a key is released

while the control has focus

(Inherited from Control.)

Trang 18

Name Description

MouseClick Occurs when the control is

clicked by the mouse (Inherited from Control.)

MouseDouble

Click Occurs when the control is double clicked by the mouse

(Inherited from Control.)MouseDown Occurs when the mouse pointer

is over the control and a mouse button is pressed.(Control)

Trang 19

Name Description

MouseEnter Occurs when the mouse pointer

enters the control.(Control)MouseHover Occurs when the mouse pointer

rests on the control(Control)MouseLeave Occurs when the mouse pointer

leaves the control (Control)MouseMove Occurs when the mouse pointer is

moved over the control (Control)

Trang 20

Name Description

MouseUp Occurs when the mouse pointer

is over the control and a mouse button is released.(Control)

MouseWheel Occurs when the mouse wheel

moves while the control has focus.(Control)

Trang 21

Events

Trang 22

MessageBox class

Trang 24

MessageBox.Show("Hello Tèo 2011");

MessageBox.Show("Hello Tèo 2011","Title");

MessageBox.Show("Hello Tèo 2011","Title",

MessageBoxButtons.YesNoCancel);

MessageBox.Show("Hello Tèo 2011","Title",

MessageBoxButtons.OK, MessageBoxIcon.Question);

Trang 27

LinkLabel

TextBox

Button

Trang 28

LinkLabel Events

Name Description

LinkClicked The LinkClicked event is handled to

perform tasks when the user clicks

on a link in the control

It is passed an instance of the

LinkLabelLinkClickedEventArgs class

Trang 29

LinkLabelLinkClickedEventArgs e) { switch (e.Button)

{

case MouseButtons.Left:

System.Diagnostics.Process.Start(linkLabel1.Text);

break;

case MouseButtons.Right:

MessageBox.Show("Right Click");

break;

case MouseButtons.Middle:

MessageBox.Show("Middle Click", "Title",

Trang 30

How add LinkLabel control & event at Runtime?

Trang 31

private void Form 1_Load( object sender, EventArgs e)

{ / /Create the linklabel

linkTeo = new LinkLabel();

//set location for linklabel

linkTeo.Location = new System D raw ing Point (100, 100);

//Set the text for linklabel

linkTeo.Text= "http://thanhxeiko.w ordpress.com " ;

//Add the controls to the form

M essageBox Show ((( LinkLabel )sender).Text);

M essageBox Show ( "Add event at runtim e" );

}

Trang 32

TextBox – Properties - Events

Name Description

Anchor Gets or sets the edges of the

container to which a control is bound and determines how a control is resized with its parent

Top Lef Right Bottom

Trang 33

Name Description

Dock Gets or sets which control borders are

docked to its parent control and determines how a control is resized with its parent

None Top Lef Right Bottom Fill

Trang 34

Name Description

Multiline Gets or sets a value indicating

whether this is aPasswordChar Gets or sets the character used to

mask characters of a password in a single-line TextBox control

ReadOnly Gets or sets a value indicating

whether text in the text box is read-only

Trang 35

Name Description

UseSystemPas

swordChar Gets or sets a value indicating whether the text in the TextBox

control should appear as the default password character

Visible Gets or sets a value indicating

whether the control and all its child controls are displayed

Enabled Gets or sets a value indicating

whether the control can respond

to user interaction

Trang 36

Name Description

TextChanged Occurs when the Text property

value changes

(object sender, EventArgs e)

{

this.Text = txtN am e.Text;

}

Trang 38

private void b tnA ddB utton_C lick( object sender,

EventA rg s e)

{

pnButton.Controls.Clear();

for ( int i = 0; i < Int32 Parse(txtN um berControl.Text); i+ + )

{ Button btnRuntim e = new Button ();

btnRuntim e.BackColor = Color Red;

btnRuntim e.Location = new System D raw ing Point

(pnButton.W idth/2-btnRuntim e.W idth/2,

i * btnRuntim e.H eight);

btnRuntim e.Text = "a_" + i;

Button btn = ( Button )sender;

lblM essage.Text = "Button : " + btn.Text + " w as clicked" ;

}

Trang 39

GroupBox & RadioButton

Name Description

Checked Gets or sets a value indicating

whether the control is checkedCheckAlign Gets or sets the location of the check

box portion of the RadioButton

Trang 40

private void frm G roupBoxRadio_Load ( object sender, EventArgs e)

{ radRed CheckedChanged + = rad_CheckedChanged;

radG reen CheckedChanged + =

rad_CheckedChanged;

radBlue CheckedChanged + = rad_CheckedChanged;

}

private void rad_CheckedChanged ( object sender, EventArgs e)

{ RadioButton rad = ( RadioButton )sender;

Trang 41

PictureBox control

Trang 42

Name Description

BackgroundImage Gets or sets the background

image displayed in the controlBackgroundImage

Layout Gets or sets the background image layout as defined in the

ImageLayout enumeration

Trang 43

Name Description

Image Gets or sets the image that is

displayed by PictureBoxSizeMode Indicates how the image is

displayed

Trang 44

Get Picture from OpenFileDialog

picDemo

Trang 45

private void btnO penPic_Click

(object sender, EventArgs e)

{

O penFileD ialog fi leO penD lg = new O penFileD ialog ();

fi leO penD lg.Filter = "(*.jpg)|*.jpg|(*.doc)|*.doc" ;

if (fi leO penD lg.Show D ialog() = = D ialogResult O K)

Trang 46

END

Ngày đăng: 08/05/2021, 12:18

TỪ KHÓA LIÊN QUAN

🧩 Sản phẩm bạn có thể quan tâm