HERE IS MY CODE BUT ALL I GET IS THIS BLANK FORM?????
using
System;
using
System.Drawing;
using
System.Windows.Forms;
namespace
Line_Drawing_Demo
{
publicpartialclassForm1:Form
{
PictureBoxpb;
Timertimer;
Bitmapsurface;
Graphicsdevice;
Randomrand;
publicForm1()
{
InitializeComponent();
}
privatevoidForm1_Load(objectsender,EventArgse)
{
//set up the form
this.Text ="Line Drawing Demo";
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.MaximizeBox =false;
this.Size =newSize(600, 500);
//create a new picturebox
pb =
newPictureBox();
pb.Parent =
this;
pb.Dock =
DockStyle.Fill;
pb.BackColor =
Color.Black;
//create graphics device
surface =
newBitmap(this.Size.Width,this.Size.Height);
pb.Image = surface;
device =
Graphics.FromImage(surface);
//create random generator
rand =
newRandom();
//set up the timer
timer =
newTimer();
timer.Interval = 20;
timer.Enabled =
true;
timer.Tick +=
newSystem.EventHandler(TimerTick);
}
publicvoiddrawLine()
{
//make a random color
intA = rand.Next(0, 255);
intR = rand.Next(0, 255);
intG = rand.Next(0, 255);
intB = rand.Next(0, 255);
Colorcolor =Color.FromArgb(A, R, G, B);
//make pen out of color
intwidth = rand.Next(2, 8);
Penpen =newPen(color, width);
//random line ends
intx1 = rand.Next(1,this.Size.Width);
inty1 = rand.Next(1,this.Size.Height);
intx2 = rand.Next(1,this.Size.Width);
inty2 = rand.Next(1,this.Size.Height);
//draw the line
device.DrawLine(pen, x1, y1, x2, y2);
//refresh the drawing surface
pb.Image = surface;
}
publicvoidTimerTick(objectsource,EventArgse)
{
drawLine();
}
privatevoidForm1_FormClosed(objectsender,FormClosedEventArgse)
{
device.Dispose();
surface.Dispose();
timer.Dispose();
}
}
}