I am trying to draw some rectangles by pressing the mouse button and dragging. Each time a new rectangle is being drawn, the previous one disappears. The question is how can I avoid this? I am programming in C.
I don't know the answer to your question, but I know what would really help someone who does: some code.
Off the top of my head, though, I would guess that some sort of draw() function is being implemented each time the mouse is released. It's likely that this just outputs a bitmap. You'd probably have to save the previous rectangle somehow and then include that in the data the program is drawing. The draw() function could also turn on a pixel if it's on in one data structure OR the other.
Then again, without code, it's pretty hard to tell.
You'd have to combine the pixel values. I suppose you could do a logical OR between the two bitmaps. Basically, if a pixel is on in either of the bitmaps (one for the existing drawing, one for the new rectangle), the pixel will be on (black) for the resulting bitmap.
In terms of procedure, you could just loop through each (2-dimensional?) array and do an OR on each pair of values.
For Each ctrl As Control In Me.Controls("pnlMainPanel").Controls
If ctrl.GetType Is GetType(System.Windows.Forms.Panel) Then
For Each subCtrl As Control In ctrl.Controls
If subCtrl.GetType Is GetType(System.Windows.Forms.TextBox) Then
If subCtrl.GetType Is ...