little gliche in complex mouse tracking program
Hi ,
Some time ago i made this little program that paints all .NET colors
on a form. It elegantly figures how many boxes can fit on to the
client and then paints them accordingly.It also figures the right text
color.
I've added mouse tracking to it already. If can figure which box the
mouse is on , and if you *click* a box , it hight lights. Now , this
works like a treat if you've *maximized* the window. If you restore or
resize the wnd and scroll, everything gets muddled up , it really
turns into a mess. Since it's set to resize redraw , minimze , then
restore the window and it nicely repaints everything. So , could
someone help me fix that!??
Also , if there is a better way of doing anything somewhere , plz tell
me.
Source:http://gidsfiles.googlepages.com/FrmColors.cs
-i've tried adding comments on each line , plz tell me if something is
still not clear.
I'm guessing this is possible because i'm thinking listviews in
LargeView are pretty much the same thing. And listviews can scroll
safely without getting mucked up.
Thanks so much
(i'm new to drawing btw , i've just started GDI+ and i have'nt done
GDI or something earlier)
Gideon
1 Attachment(s)
Re: little gliche in complex mouse tracking program
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);
}
}
Re: little gliche in complex mouse tracking program
second of all, don't link to exe's. no one in their right mind would click on that.
Re: little gliche in complex mouse tracking program
hi Luthv,
yea , that makes sense. I just finished reading the mouse tracking chapter from petzolds book. He started out with a simpler program , much like mine , which sparked this idea in the first place. Towards the end of the chapter he re-does the program by making a seperate class just like you , only he inherits from UserControl , so it has a keyboard interface too.
I'm still happy i tried this. I will still keep this program intact lol! I wrote some pretty insane mouse tracking code =P I'll make a new one from scratch!
Thanks so much!
I'm sorry mariocatch , i did'nt think before putting that link. It'll be removed.
Gideon