Redrawing graphics in userControl - Button

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sugan

    #1

    Redrawing graphics in userControl - Button

    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

  • Göran Andersson

    #2
    Re: Redrawing graphics in userControl - Button

    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
    >

    Comment

    • Sugan

      #3
      Re: Redrawing graphics in userControl - Button

      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.

      Comment

      • Sugan

        #4
        Re: Redrawing graphics in userControl - Button

        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_vbuButtonGrap hics As Graphics

        Private Sub vbuButton_Paint (ByVal eventSender As System.Object, ByVal
        eventArgs As System.Windows. Forms.PaintEven tArgs) Handles MyBase.Paint
        m_vbuButtonGrap hics = Me.CreateGraphi cs()
        DrawButton(m_vb uButtonGraphics )
        'DrawButton(eve ntArgs.Graphics )
        End Sub

        -Sugan
        _________

        Comment

        • Göran Andersson

          #5
          Re: Redrawing graphics in userControl - Button

          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_vbuButtonGrap hics As Graphics
          >
          Private Sub vbuButton_Paint (ByVal eventSender As System.Object, ByVal
          eventArgs As System.Windows. Forms.PaintEven tArgs) Handles MyBase.Paint
          m_vbuButtonGrap hics = Me.CreateGraphi cs()
          DrawButton(m_vb uButtonGraphics )
          'DrawButton(eve ntArgs.Graphics )
          End Sub
          >
          -Sugan
          _________
          >

          Comment

          Working...