By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,853 Members | 1,563 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,853 IT Pros & Developers. It's quick & easy.

Redrawing graphics in userControl - Button

P: n/a
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

Jul 10 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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.

Sugan wrote:
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
Jul 10 '06 #2

P: n/a
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.
Göran Andersson wrote:
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.
Jul 10 '06 #3

P: n/a
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
_________

Jul 10 '06 #4

P: n/a
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?
Sugan wrote:
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
_________
Jul 11 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.