, ? , , , : .
, , , .
.
using System;
using System.Windows.Forms;
class MyButtonClass: Form
{
private Button mrButton;
// -
public MyButtonClass()
{
mrButton = new Button();
mrButton.Text = " ";
//
mrButton.Click += new System.EventHandler(MyButtonClickEventHandler);
this.Controls.Add(mrButton);
}
//
static void Main()
{
Application.Run(new MyButtonClass());
}
// -
void MyButtonClickEventHandler(object sender, EventArgs e)
{
mrButton.Text = " !";
}
}
:
" mrButton Click , MyButtonClickEventHandler".
, " !".
, , F5 . , . , ( Example5).
. , . . , .
public MyButtonClass()
{
mrButton = new Button();
mrButton.Text = " ";
mrButton.Top = 100;
mrButton.Left = 100;
mrButton.Height = 50;
mrButton.Width = 70;
mrButton.Click += new System.EventHandler(MyButtonClickEventHandler);
this.Controls.Add(mrButton);
}
. , , MouseEventArgs, , , .
public void TheMouseIsDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
this.Text = " ";
}
, . : " , TheMouseIsDown", , :
|
|
this.MouseDown += new MouseEventHandler(TheMouseIsDown);
, , , .
public void TheMouseWasClicked(object sender, MouseEventArgs e)
{
//
if (e.Button == MouseButtons.Left)
//
this.Width = this.Width + 100;
else if (e.Button == MouseButtons.Right)
//
this.Width = this.Width 100;
}
, :
public void TheMouseMoved(object sender, MouseEventArgs e)
{
//
System.Drawing.Graphics g = this.CreateGraphics();
//
System.Drawing.Pen redPen = new System.Drawing.Pen(System.Drawing.Color.Red, 3);
// .
// .
// X Y
// .
g.DrawEllipse(redPen, e.X, e.Y, 40, 40);
//
g.Dispose();
}
, :