Redrawing graphics in userControl - Button

S

Sugan

Hi all,

I've created a Custom button control and i'm drawing the graphics for
the button when the paint event is fired. I used Invalidate method to
redraw the graphics in events like mousemove, click etc.

My problem is as follows: I created a test application to test the
created custom button control. I had two buttons on the form. When i
click on one button 1 a message box is showed. This message box covers
one part of the other button 2 in the form. When i dismiss the message
box in such a way that the mouse is not over button 2, a part of the
text in caption of button2 disappears. But what ever may be the case,
button 1 appears properly as i have called invalidate during the click
event for that button1.

I understand that some event would be fired in button2 when i dismiss
the message box, during which i need to call Invalidate? Can some one
tell me where to call Invalidate to repaint the graphics in the
button2.

Thanks in advance,
Sugan
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

You only have to invalidate the control when you have made something
that changes the apperance of the control. Normal drawing, e.g. when
windows move over and away from the control and such, is handled
automatically.

If the control isn't redrawn correctly when when it has been covered and
reappear, there is something wrong with your code that handles the Paint
event.
 
S

Sugan

The exact problem is when i click on button1, it throws a message box
which covers part of button2. When the message box is dismissed, the
area covered by the message box alone is refreshed( graphics in this
area is displayed as desired). The uncovered area of the button2 loses
the part of the caption( loses the previously drawn graphics). However
when i move the mouse over the button2, i'm invalidating the control
and hence the whole graphics gets redrawn perfectly as i desire.

I want the whole graphics to be redrawn when the message box is
dismissed. Pls note that button1 has the when i click on it. Then
message box is thrown that covers button2. when message box is
dismissed, i want to know the event that would be fired to refresh the
graphics in button2.

Thanks,
Sugan.
 
S

Sugan

Hi,

I found the answer for this issue myself.

What i did is, instead of using the eventArgs argument to draw graphics
in the UserControl, i declared a variable and assigned the graphics of
the button which helps to retain the graphics of the button after
dismissing the message box. Any way thanks and here is the code.



visual basic code:

Dim m_vbuButtonGraphics As Graphics

Private Sub vbuButton_Paint(ByVal eventSender As System.Object, ByVal
eventArgs As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
m_vbuButtonGraphics = Me.CreateGraphics()
DrawButton(m_vbuButtonGraphics)
'DrawButton(eventArgs.Graphics)
End Sub

-Sugan
_________
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

You have forgotten to call Dispose on the graphics object you create.

The graphics object that you get in the event arguments is what you are
supposed to use to redraw the control. If you don't, you risk to draw
more than you are supposed to, like if the control is partly covered by
another window, you would draw the control on top of that window.

What does the DrawButton method do?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top