drawing

  • Thread starter Thread starter Bad_Kid
  • Start date Start date
B

Bad_Kid

How to make this:

I have a panel and I draw something on it (some lines, a complex
function...).
I want this:
When I move mouse over that panel to draw a vertical line from top of the
panel to panel.height on the X position of the mouse? While I'm moving a
mouse over a panel that vertical line is moving too aloong with the mouse
cursor.
Do I have to redraw a whole panel for every mouse movement??? That's not a
good idea, ist' VERY slow...

any suggestions, PLEASE??
thanks!
 
I have a few ideas, but am not totally sure if it will help solve your
problem...

First suggestion: By calling the Panel's Invalidate method, you can
specificy the region that needs to be repainted via the use of the
Rectangle Struct. This should only redraw part of the Panel rather
than the entire thing.

Another option is to set the style used on the Form. When I've had to
do quick animations in .NET without using DirectX, I've managed to
solve a lot of my problems with this approach (it can get rid of
annoying flickering that can happen when your drawing requires a lot of
repainting/refreshing).

Here's a link to what MSDN has to say about it:

http://msdn.microsoft.com/library/d...systemwindowsformscontrolstylesclasstopic.asp

Here's the bit of code that I found to be the most useful when dealing
with any sort of animation:

public class Form1: System.Windows.Forms.Form
{
public Form1()
{
SetStyle( ControlStyles.UserPaint, true );
SetStyle( ControlStyles.AllPaintingInWmPaint, true );
SetStyle( ControlStyles.DoubleBuffer, true );
}
}

These SetStyle calls (all three of these together) will turn on double
buffering for your form and should make things run a bit faster.

Hope this helps...

-- Dan
 
How to make this:

I have a panel and I draw something on it (some lines, a complex
function...).
I want this:
When I move mouse over that panel to draw a vertical line from top of the
panel to panel.height on the X position of the mouse? While I'm moving a
mouse over a panel that vertical line is moving too aloong with the mouse
cursor.
Do I have to redraw a whole panel for every mouse movement??? That's not
a
good idea, ist' VERY slow...

any suggestions, PLEASE??
thanks!
[PD] You can invalidate only parts of the control when you move the mouse.
Look at the different overloads of the Control.Invalidate method.
 
Back
Top