10.1.txt

来自「《Microsoft Visual C# .NET 2003开发技巧大全》源代码」· 文本 代码 · 共 27 行

TXT
27
字号
Listing 10.1 Drawing Randomly Sized Rectangles with Random Colors
private void Form1_Click(object sender, System.EventArgs e)
{
Random randNum = new Random( DateTime.Now.Millisecond );
int width = randNum.Next( this.Width-mouseHit.X );
int height = randNum.Next( this.Height-mouseHit.Y );
int r = randNum.Next(255);
int g = randNum.Next(255);
int b = randNum.Next(255);
Graphics surface = this.CreateGraphics();
if( randNum.Next(2) == 0 )
{
surface.FillRectangle( new SolidBrush(Color.FromArgb(r,g,b)),
mouseHit.X, mouseHit.Y, width, height );
}
else
{
surface.DrawRectangle( new Pen( new SolidBrush(Color.FromArgb(r,g,b))),
mouseHit.X, mouseHit.Y, width, height );
}
surface.Dispose();
}
private void Form1_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)
{
mouseHit = new Point( e.X, e.Y );
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?