.


:




:

































 

 

 

 





 

, , , , , . . . ( Paint), , . Paint. - :

 

private void Form_Paint(object sender, System.Windows.Forms.PaintEventArgs e)

 

, e. :

 

Graphics dc = e.Graphics;

 

.

. .

Paint Invalidate(), System.Windows.Forms.Form. . , . .

 

2.

, , 150 5 .

1. Form1 :

 

private int xWidth;

 

2. - Paint, Paint . , :

 

private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)

{

Graphics dc = e.Graphics;

dc.DrawRectangle(Pens.RoyalBlue,10,100,xWidth,50);

}

 

3. Timer Toolbox, Enable true Interval 150.

4. - . , :

 

private void timer1_Tick(object sender, System.EventArgs e)

{

xWidth += 5;

Invalidate();

}

. .

:

1. , ?

2. ?

3. ?

4. , ?

5. , ?

6. , ?

7. , ?

8. , , ?

9. ?

10. ? ?

11. , ?

12. , ?

13. , ?

14. ?

15. , ?

16. , Paint, ?

17. , Paint?

:

 

1. , .

2. , , .

3. , ( ).

4. , .

5. , , .

6. , .

7. , , ( ).

8. , , ( ).

9. , 8.

10. , 8.


 

7

, , . . . . . , .

MainMenu, ContextMenu MenuItem, Menu. Menu MenuItemCollection, MainMenu, ContextMenu MenuItem.

MainMenu:

 

public MainMenu()

public MainMenu (MenuItem[] menuItems)

public MainMenu (IContainer container)

 

MainMenu, Menu MainMenu. Menu , . , .


ContextMenu:

 

public ContextMenu ()

public ContextMenu (MenuItem[] menuItems)

 

, , , . , , ContextMenu , Contol. ContextMenu , .

. , :

public void Show (Control control, Point pos),

, , , .

MenuItem:

 

public MenuItem (),

public MenuItem (string text),

public MenuItem (string text, EventHandler onClick),

public MenuItem (string text, MenuItem[] items),

public MenuItem (string text, EventHandler onClick, Shortcut shortcut),

:

text ,

onClick EventHandler, .

onClick .

shortcut .

Shortcut - . 150 . , .

, . MessageBox , . ALT+1 ALT+2.

 

1:

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

 

namespace Menu1

{

public partial class Form1: Form

{

//

MainMenu MnMen1; //

//

MenuItem pnkt1;

MenuItem pnkt1_1; //

MenuItem pnkt1_2; //

//

MenuItem pnkt2;

MenuItem pnkt2_1; //

MenuItem pnkt2_2; //

 

public Form1() //

{

InitializeComponent();

 

this.Text = "";//

 

// - pnkt1_1 = new MenuItem(" 1_1", new EventHandler(Msg1_1), Shortcut.Alt1);

pnkt1_2 = new MenuItem(" 1_2", new EventHandler(Msg1_2), Shortcut.Alt2);

pnkt1 = new MenuItem(" 1", new MenuItem[] { pnkt1_1, pnkt1_2 });

 

// -

pnkt2_1 = new MenuItem(" 2_1", new EventHandler(Msg2_1));

pnkt2_2 = new MenuItem(" 2_2", new EventHandler(Msg2_2));

pnkt2 = new MenuItem(" 2", new MenuItem[] { pnkt2_1, pnkt2_2 });

 

// -

MnMen1 = new MainMenu(new MenuItem[] { pnkt1, pnkt2 });

 

this.Menu = MnMen1;//

}

 

 

//

 

void Msg1_1(object sr, EventArgs e)

{

MessageBox.Show(" 1_1");

}

void Msg1_2(object sr, EventArgs e)

{

MessageBox.Show(" 1_2");

}

void Msg2_1(object sr, EventArgs e)

{

MessageBox.Show(" 2_1");

}

void Msg2_2(object sr, EventArgs e)

{

MessageBox.Show(" 2_2");

}

}

}

.

, , , .

, :

MenuItem pnkt = new MenuItem(-);

.

MenuItem . , ..

:

1. Shortcut - ,

2. ShowShortcut - false , , , true -

3. Text -

4. Visible (true) - (false) .

5. Enabled false true. .

6. DefaultItem true , , , , . .

7. Checked true , .

 

Menu MenuItemCollection, MainMenu, ContextMenu MenuItem. MenuItemCollection , .


:

 

Menultem Add(string caption)

Menultem Add(string caption, EventHandler onClick)

Menultem Add(string caption, MenuItem [] items)

int Add(MenuItem item)

int Add(int index, MenuItem item)

void AddRange(MenuItem[] items)

 

Count MenuItemCollection.

Add .

.

 

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

 

namespace CntMn

{

public partial class Form1: Form

{

MenuItem myClr; //

ContextMenu ctmn;//

public Form1()

{

InitializeComponent();

ctmn = new ContextMenu();//

//

EventHandler ev = new EventHandler(MnClick);

//

ctmn.MenuItems.Add("Red", ev);

ctmn.MenuItems.Add("Blue", ev);

ctmn.MenuItems.Add("Green", ev);

 

foreach (MenuItem itm in ctmn.MenuItems)

itm.RadioCheck = true;

//

myClr = ctmn.MenuItems[2];

myClr.Checked = true;

//

this.BackColor = Color.FromName(myClr.Text);

//

this.ContextMenu = ctmn;

}

//

void MnClick(object sr, EventArgs e)

{

myClr.Checked = false;//

myClr = (MenuItem)sr; //

myClr.Checked = true;//

this.BackColor = Color.FromName(myClr.Text);

}

}

}

Visual Studio.Net.

, ( ) . .

 

1. ToolBox MainMenu ContextMenu.

2. . mainMenu1 .

3. contextMenu1 .

4. , :

 

private int width;

private int height;

private Color myColor;

 

5. Form1():

public Form1()

{

InitializeComponent();

myColor = Color.Red;

width = 10;

height = 10;

}

 

6. , - Paint , :

private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)

{

Graphics dc = e.Graphics;

Pen myPen = new Pen(myColor);

dc.DrawRectangle(myPen,50,50,width,height);

}

7. mainMenu1 - . , :

 

private void menuItem2_Click(object sender, System.EventArgs e)

{

width = 100;

height = 100;

Invalidate();

}

 

8. :

 

private void menuItem3_Click(object sender, System.EventArgs e)

{

width = 10;

height = 10;

Invalidate();

 

}

 

9. contextMenu1 :

 

private void menuItem4_Click(object sender, System.EventArgs e)

{

myColor = Color.Red;

Invalidate();

}

 

10. contextMenu1 :

 

private void menuItem5_Click(object sender, System.EventArgs e)

{

myColor = Color.Blue;

Invalidate();

}

 

11. - , :

 

private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)

{

Point myPoint = new Point(e.X,e.Y);

if(e.Button.ToString() == "Right")

contextMenu1.Show(this,myPoint);

}

 

12. .

 

 

:

1. ?

2. ?

3. ?

4. ?

5. ?

6. ?

7. ?

8. ?

9. ?

10. ?

11. ?

 

:

1. 1. 1 . , , .

2. 2. . . .

3. 3. . . .

4. 3. . , , ( ) . .

5. , , , .

6. 3. . , , .

7. 3. , , .

8. , , , .

9. , (, , ), .

10. , , , , .


8

Thread.

:

public Thread (ThreadStart start)

 

start ThreadStart , .

ThreadStart System.Threading delegate :

 

public delegate void ThreadStart();

 

, , void .

, , - void funcThread(), start:

 

ThreadStart start = new ThreadStart(funcThread);

 

ThreadStart , .

start funcThread.

, Thread start :

 

Thread thrd = new Thread(start);

 

Start, thrd:

 

thrd.Start();

 

Name :

thrd.Name = ThrName;,

:

strig nm = thrd.Name;

, , , . . . , IsAlive, . true, (false), . . :

public static void Sleep(int time)

Thread, time .

, .

1:

using System;

using System.Collections.Generic;

using System.Text;

using System.Threading;

namespace ConsoleApplication4

{

class MyThread

{

private int count; //

//

public Thread thrd;

public MyThread(string name)

{

count = 0;

// FnThr

thrd = new Thread(new ThreadStart(this.FnThr));

thrd.Name = name; // .

thrd.Start(); // .

}

//

public void FnThr()

{

Console.WriteLine(thrd.Name + " .");

do

{

Thread.Sleep(300); // 0,3

Console.WriteLine(" " + thrd.Name + ", count - " + count);

count++;

} while (count <= 4);

Console.WriteLine(thrd.Name + " .");

}

}

class Program

{

static void Main(string[] args)

{

Console.WriteLine(" .");

//

MyThread[] mt = new MyThread[5];

// MyThread.

for (int j = 0; j < mt.Length; j++)

mt[j] = new MyThread(" #" + j.ToString());

bool live;

do

{

live=false;

Console.Write(".");

Thread.Sleep(100); //

for (int j = 0; j < mt.Length; j++)

{

live = live | mt[j].thrd.IsAlive;

}

 

} while (live);

Console.WriteLine(" .");

 

}

 

}

}

MyThread. MyThread :

 

thrd = new Thread(new ThreadStart(this.FnThr));

 

, Start() , FnThr().

FnThr () , "" 0 4. , . Sleep(), FnThr () , , , . Main() Thread:

 

//

MyThread[] mt = new MyThread[5];

// MyThread.

for (int j = 0; j < mt.Length; j++)

mt[j] = new MyThread(" #" + j.ToString());

 

MyThread, , , , Main() .

:

 

for (int j = 0; j < mt.Length; j++)

{

live = live | mt[j].thrd.IsAlive;

}

 

} while (live);

 

Main() .

 

 





:


: 2016-11-02; !; : 820 |


:

:

.
==> ...

1757 - | 1614 -


© 2015-2024 lektsii.org - -

: 0.219 .