Home All Groups Group Topic Archive Search About

Redrawing graphics in userControl - Button

Author
10 Jul 2006 7:19 AM
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

Author
10 Jul 2006 8:54 AM
Göran_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.

Sugan wrote:
Show quoteHide quote
> 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
>
Author
10 Jul 2006 9:05 AM
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.


Göran Andersson wrote:
Show quoteHide quote
> 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.
Author
10 Jul 2006 10:06 AM
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
_________
Author
11 Jul 2006 12:11 AM
Göran_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?


Sugan wrote:
Show quoteHide quote
> 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
> _________
>