C# 2008 Simple graphics render question - RealWorld forums

Log-in or register.

C# 2008 Simple graphics render question

Unsticky after solved please.
progmgp
on September 9th 2009

I have a class that holds a bitmap. At any given time I set a form's background image to the class bitmap. I'm watching for mouse_up events and checking mouse positions. If the user chooses a particular region in the form, I want to draw a rectangle around a specified area. If the user moves the mouse with the region selected, I want to redraw just the rectangle so as to represent where the image is to be redrawn. When the user releases the mouse after a move, I redraw the class image and reset the forms background image to the class bitmap. My problem is when I'm drawing the rectangle during a move, the rectangle barely gets drawn then disappears. I have the form's double_buffer set on. If I turn double_buffer off, the rectangles show up better but the background flickers badly. How would every one suggest I handle the drawing so as to smoothly display my selection rectagles during a mouse move? The selection rectangles are drawn in the forms paint event. The Background is changed in a called method. I'm using c# 2008. Thanks for your thoughts!!

sixλxis
on February 19th 2010

I'll get Vlasta to take a look at this.

He's the coding expert.

I'll sticky this for the moment but please unsticky it after its solved.

Vlasta
on February 20th 2010

You should probably change the way you are approaching the problem.

Using background bitmap is good when the background is static or changes very rarely.

If you want to interactively change the content of the window, use a custom control (is it call canvas in .net? I do not remember anymore). Then, implement its OnPaint method. Only draw to the screen in this method. Do not draw in your mouse event handlers - instead, mark the affected region of the canvas as invalid and let the OnPaint method do the job.

In your current approach, the default OnPaint implementation interferes with your own drawing - or vice versa ;-).

Page views: 10609       Posts: 3      
Select background
Vista & Win 7 icons
I wish there were...