Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

лабораторные С#

.pdf
Скачиваний:
38
Добавлен:
12.03.2015
Размер:
778.43 Кб
Скачать

& ) FlowLayoutPanel

11.! ) " # % FlowLayoutPanel. ( , "

%FlowLayoutPanel Toolbox , " % TabPage. 2 # $ Fill % Dock , " %

FlowLayoutPanel.

12.( $! , " % Button Toolbox

, "

%

Panel.

"

" (

# "!& , ": %"$

# #

, "

%

 

FlowLayoutPanel — . / $ , $ , " !

%

, ! FlowLayoutPanel, %#% & # * "

& " % % " ( * # & , # %. # % " FlowDirection, "% " ! * # $! $ FlowLayoutPanel: LeftToRight — %"$ , RightToLeft , TopDown —

&% BottomUp — % &.

13. #! ( % button5 # * $ ! button5_Click #% ( #:

flowLayoutPanel1.SetFlowBreak(button6, true);

& ) TableLayoutPanel

14.! % ) "! ( , & # "). ) " ! # % TableLayoutPanel. ( , " %

TableLayoutPanel Toolbox TabPage. 2 # %

CellBorderStyle ( # # $ '! & #) $

Inset, % AutoScroll True.

15.( , " % Button Toolbox % & $% , " % TableLayoutPanel.

16.#! ( Button9 # * $ !

Button9_Click #% ( #:

Button aButton = new Button(); tableLayoutPanel1.Controls.Add(aButton, 1, 1);

& ) SplitContainer

17.% ! # % SplitContainer. ( , " % SplitContainer Toolbox TabPage. 2 # % BorderStyle $ Fixed3D.

18.( # , " % Button Toolbox l1 , " % SplitContainer. 2 # " Text , &$ Fix/Unfix l1 Fix/Unfix Splitter. " " !, $! .

19.* % 12 # % Text $ Collapse/Uncollapse l1. " " ! , $!.

20.#! ( % Fix/Unfix Panel1 # *$ ! Click #% ( #:

if (splitContainer1.FixedPanel == FixedPanel.Panel1) splitContainer1.FixedPanel = FixedPanel.None;

21

else

splitContainer1.FixedPanel = FixedPanel.Panel1;

21. #! ( % Fix/Unfix Splitter # *$ ! Click #% ( #

splitContainer1.IsSplitterFixed = !(splitContainer1.IsSplitterFixed);

22. #! ( % Collapse/Uncollapse Panell # *$ ! Click #% ( #:

splitContainer1.Panel1Collapsed = !(splitContainer1.Panel1Collapsed);

23.% .

24.# GroupBox $# ! $ # " " # .

25.# Panel " " ) "! " (* "!0. *, * ! %.

26.# FlowLayoutPanel " " ) "! " (* "!0. ", $ "$ " * " .

4

% button5 *, * # * *

, " %

button6 (, ! ! " " #

SetFlowBreak).

27.# TableLayoutPanel ( % button9, #.

28.# SplitContainer " " ! ) "!, " ! # , # % Splitter. $# ( #%

%

", ,

"

, "

%

 

" * " !.

 

 

6.

 

 

! , % , ! %$*

* *

, "

%

 

LinkLabel ) " * , $! ! *

# , 0 ( % * " .

& ) LinkLabel

1.Visual Studio # ! Windows Forms.

WinLinkLabel.

2.( # , " % LinkLabel Toolbox

) "%.

3. Properties

#

, " # % Text

$ Open Form, #

– $ Microsoft.

4." Project ! Add Windows Form # *% ) "% Windows " " Form2.

5.% ( # , " % Button ) "% Form2. 2 # % Text , & $ Accept

Cancel. & " " % % ) "!.

22

6.2 # % DialogResult Accept $ $, % DialogResult Cancel — $ Cancel.

7.( # , " % TextBox Toolbox ) "%.

8.2 # % Modifiers # , " % TextBox

$ Internal. Text # & * % !".

9.( # , " % Label Toolbox ) "% " & # " , " " % TextBox.

10.2 # " Text , " % Label $

&First Name &Last Name.

11.*, $ % UseMnemonic & # %$ True.

12.Tablndex Properties,

.

.

/

label1

0

textBox1

1

label2

2

textBox2

3

button1

4

button2

5

13. ! % # % # ) "! Form1. #! ( ! , " % linkLabel1 # #$ ! linkLabel1_LinkClicked. * #% ( #:

DialogResult aResult; Form2 aForm = new Form2();

aResult = aForm.ShowDialog();

if (aResult == System.Windows.Forms.DialogResult.OK)

{

MessageBox.Show("Your name is " + aForm.textBox1.Text + " " + aForm.textBox2.Text);

}

linkLabel1.LinkVisited = true;

-

14. ! % # % # ) "! Form1. #! ( , " % linkLabel2 # #$ ! linkLabel2_LinkClicked. * #% ( #:

System.Diagnostics.Process.Start("www.limtu.com"); linkLabel2.LinkVisited = true;

15.% .

16.4 , " % linkLabel – Open Form, $! ! * ) "%. # % (% ) " ' # * Accept Cancel.

17.4 , " % linkLabe2 – Microsoft, $! ! * %$ '.

23

7.

 

TextBox , , " % ,

 

" (*

"

" * # "! * "

 

 

*

 

#

* .

%( %

" *

# *

,

( "$! ,

 

(

 

 

" * # .

 

 

 

 

/ " %

MaskedTextBox — , # " ! , "

%

TextBox,

(

# *

# *

% ! 0 #

* * #

. " (* Mask " % * * !

* ! " !

# "!& " (% ! ' ) !)

" * ) " #

.

1.! " #!#%( " % 0

WinLinkLabel.

2.% # ) "! Form2.

3. * , " % TextBox ) "% #!" , " ". ( , " % Label ) "% " , , ".

4.2 # % Text , " % Label $

Address.

5., " % TextBox # #% ( :

 

 

$

Multiline

True

"$!

WordWrap

False

& # #

 

 

# % %

ScrollBars

Both

%

6." " ! , " % TextBox , $! " ( #. & # " %$* " ! ) "! " Accept Cancel.

7.( , " ! % MaskedTextBox Label

Toolbox ) "% " & # # ! , " !.

8.

% Text , " %

Label # $ Phone

Number.

 

 

9.

2 # $ (999)-000-0000

% Mask

, "

% MaskedTextBox.

 

 

10.

2 # $ Internal % Modifiers #

# &

, " % TextBox MaskedTextBox.

 

11.# ) "! Form1.

12.$ ! linkLabel1_LinkClicked # * if,

! # # ", ! ! # #!#%( " % , #% ( #

MessageBox.Show("Your address is " + aForm.textBox3.Text); MessageBox.Show("Your phone number is " + aForm.maskedTextBox1.Text);

24

13. % . #). *, $ " % " "% ) " %.

8. !

" ( ) " , " % " #, # # #, ! ( , , ". 3 $*$ # , " % ' $ #, %( " " %# # * ) "% %# * , " !, % , $ .

! , " " % * % 1 ControlsCollection, # ( # " #, ! !& %#%* ! # " % .

1. # RegistrationForm.

2. * ) "%

# ,

#

!&

, %,

, " ! CheckBox GroupBox

 

 

 

 

 

 

3. #% (

$

) "!

, "

% :

 

 

 

 

 

 

 

 

+

 

 

 

 

 

 

 

Form1

FormBorderStyle

Fixed3D

 

 

 

 

 

 

Text

 

'

 

 

 

 

 

Size

 

400;310

 

 

 

 

 

label1

Location

 

30;10

 

 

 

 

 

 

Text

 

!

'

 

 

label2

Location

 

16; 32

 

 

 

 

 

 

Text

 

Name

 

 

 

 

 

label3

Location

 

16; 64

 

 

 

 

 

 

Text

 

PIN

 

 

 

 

 

button1

Location

 

80; 248

 

 

 

 

 

 

Text

 

'

 

 

 

 

textBox1

Location

 

96; 32

 

 

 

 

 

 

Text

 

 

 

 

 

 

 

 

Size

 

184; 20

 

 

 

 

 

textBox2

Location

 

96; 64

 

 

 

 

 

 

Size

 

184; 20

 

 

 

 

 

 

Text

 

 

 

 

 

 

 

checkBox1

Location

 

40; 40

 

 

 

 

 

 

Size

 

232; 24

 

 

 

 

 

 

Text

 

0 ! "

 

 

groupBox1

Text

 

# ' ! # !

 

 

 

Location

 

16; 80

 

 

 

 

 

 

Size

 

344; 144

 

 

 

 

 

 

 

25

 

 

 

 

4. ' " # %# , " ' ! ""! % $ ! CheckedChanged: ( # #! , " checkBox1 # * #% ( #:

if (checkBox1.Checked == true)

{

Label lbl = new Label();

lbl.Location = new System.Drawing.Point(16, 96); lbl.Size = new System.Drawing.Size(32, 23); lbl.Name = "labelll";

lbl.TabIndex = 2; lbl.Text = "PIN2";

groupBox1.Controls.Add(lbl); TextBox txt = new TextBox();

txt.Location = new System.Drawing.Point(96, 96); txt.Size = new System.Drawing.Size(184, 20); txt.Name = "textboxx";

txt.TabIndex = 1; txt.Text = "";

groupBox1.Controls.Add(txt);

}

else{

}

5. " % % . *, $ % ) / checkBox “0 ! "” ) "

 

# *

# # # * !& # !&.

6.

%#

/ ) "! " % " * " #!: Clear

(%# & , " '), Remove (%# , "

') RemoveAt (%# , "

# "% # %).

else # * # # %# /

# %:

int lcv;

lcv = groupBox1.Controls.Count;// определяется количество while (lcv > 4)

{

groupBox1.Controls.RemoveAt(lcv - 1); lcv -= 1;

}

 

 

 

7. 2 %

. # *, $

 

$

“0 ! "” # * ! , " !

 

) ", !$ – $ .

 

 

9. " # $ . KeyPress Validating. ErrorProvider

$ " * " " & %$ & % * # "! # !" ". ", ' ! ", ) # ! # * %, " - ' ). , " % " ' , ! " %( *, * % ! ! .

/ KeyPress

1. RegistrationForm.

26

2.!# $# ! TextBox1 TextBox2,Properties # $ ! KeyPress, (0 .

3.$ ! KeyPress #

TextBox1 % #% ( # (#

, " TextBox1

# % "!" $ " %#% ' ) !):

 

if (char.IsDigit(e.KeyChar) )

{

e.Handled = true;

MessageBox.Show("Поле Name не может содержать цифры");

}

4. , " TextBox2, , # % "!" $ " %#% % !, $ ! KeyPress # TextBox2 % #:

if (!char.IsDigit(e.KeyChar) )

{

e.Handled = true;

MessageBox.Show("Поле PIN не может содержать буквы");

}

5.

" % % . %

 

Name ' ) !,

PIN – % !.

 

 

6.

( !

, (

 

%

$ $ "0 ! "", & # " %$%# * ! KeyPress. $ ! CheckedChanged # , " CheckBox1 % #:

txt.KeyPress+= new System.Windows.Forms.KeyPressEventHandler(this.textBox2_KeyPress);

7. 2 % % .

" Validating

! KeyPress % $* % !. % " "

! Validating,

( *

%, % ( # % #

* .

8.2 "" % $ , " TextBox2.

9." # ) "! Properties , " TextBox2 # $ ! Validating 0 #% ( #:

if(textBox2.Text =="")

{

e.Cancel=false;

}

else

{

try

{

double.Parse(textBox2.Text); e.Cancel = false;

}

catch

{

e.Cancel = true;

MessageBox.Show("Поле PIN не может содержать буквы");

27

}

}

10. 2 % . $ ) % #% "' " & # ! Validating.

" ) ErrorProvider

/ " % ErrorProvider %# " *, # % ! # * *0% % %$ 0 #.

11. " # ToolBox ) "% , "

%ErrorProvider.

12.# ) "! $ textBox1_KeyPress # * #% (% %:

errorProvider1.SetError(textBox1, "Must be letter");

13. 2 % . 0 # " (% # " , # ! ( ( 0.

3. )

%$ , " % %$ ! & " # * 0 .

1.

# % %( % ( " , " " % "

! * !, $! $*

# &

 

 

' % )% ' * *.

 

 

 

 

%( % #

! "!&

* "

, "

% :

 

 

 

 

 

(composite), ! #

 

1 #

 

# % & , " % Windows Forms;

 

 

 

(custom), # "!

 

%

 

# ( ! # #

;

 

!

(extended),

!

 

 

#

 

)% ' * * % %( % ( "% , " % %

 

Windows Forms.

 

 

 

 

 

! , " ! % #% UserControl,

# ! % * )% ' *,

$(

# # % & , " % , , " # !. UserControl " ! %, - ( * * Visual Studio IDE # * !& , " % Toolbox & * % * &.

, " % ! # # , " % , # % ( ' ) ! $!. ! # , " % Label, ( * " , " Timer, #%

28

% #% (

Label.

# Enabled , "

% Timer, !

# #

* " " * $*

$* $!.

 

 

)

1.# Visual Studio Windows Forms.

WinTimer1.

2." Project ! Add User Control ( Add # " Add New Item. " UserControlTimer " #. 0 "% % %# # % * * , " % , ! %.

3. Toolbox ( Label * * , "

%.

4.# # ! Text / Label.

5." " ! * * , " % ,

$! ! * " % , " % Label.

6.Toolbox ( * * , " % " Timer.

7.Properties " Timer % Interval$ 1000 % Enabled $ True.

8.#! ( " Timer, $! ! * #$ ! Timer.Tick %"$ # * #% (% % ""!:

label1.Text = DateTime.Now.ToLongTimeString();

9. # # * #% ( 1 :

public bool TimeEnabled

{

get { return timer1.Enabled; } set { timer1.Enabled = value; }

}

10." File ! Save All, $! & * 0 0.

11." Build ! Build Solution.

" )

12.! # % % Forml. Toolbox ( UserControlTimer ) "%. ) " # , " 0 * * , " % $ $! * #% % #%. ", $ ! " * ,, % TimeEnabled $ False Properties.

13.% . ", $ * * , " % " ! # %

, %.

)

14. 7 ! * % , " % , ! #% ( # :

a.# Visual Studio – 0 ) Windows.

29

b. %"$

 

#

, "

 

% .

 

 

 

 

 

c.

* , " !

%

 

#,

 

% 1.

 

 

 

 

 

d.

! , " % , ! # " *

 

# ( # " %$ , label1,

 

timer1), # #

Modifiers (1)

 

, , " %

 

$ Private.

e. # % DLL,

 

.

2. %

 

' !&

, "

%

%( %

* * )

%"$ , # !

# *

* #,

& # "! #

 

)$ #-

. / " % ! # , $! %$*$ % * #, " & # ", # * % % "% )% ' * * # " # * "

' ! , " ! % #% Control. / $ )% ' * *, % "% #

, "

% .

#

% )% ' * *,

& # "% #

" # , " % *

$* .

 

 

 

$ #$

' , "

%

 

' # "

* * ).

3 " # * ' " # OnPaint, ! ! " #! ,

# , " %

,.

 

 

 

!

,

% ,

!

%$*

# *

' ! , " % ,

# (

' ) ! $!.

# , " %

%

 

#!#%(

% ,

$ " Timer

#

 

* * ) % . # * ! " # # # , , " % " , $! * * , " % Label.

)

1.# Visual Studio Windows Forms.

WinTimer2.

2." Project ! Add New Item. ! Custom Control # " Add New Item ( Add. "

UserControlTimer2 " Add (#). % %# # ! ' ! , " % . "#.

30