First of all I would suggest you break down your code into classes, this way it would be much easier to localized the problem, don't put all your codes into one form.
In my attached class I've broken down the drawing routine to the colorbox class, you can extend this class to allow mouse detection as well.
Then you can use the attached colorbox class in your form like this (I'm using .NET 2 btw)
Code:Collection<ColorBox> colorBoxes = new Collection<ColorBox>();//you can change this to arraylist if you're using .net 1 public Form1() { InitializeComponent(); this.AutoScroll = true; this.AutoScrollMinSize = new Size(800, 600); colorBoxes.Add(new ColorBox(Color.Red, new Point(0, 0), 100, 30)); } protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); foreach (ColorBox colorBox in colorBoxes) { colorBox.Draw(e.Graphics, this.AutoScrollPosition); } }




Reply With Quote