Invokepaint to paint another controls image on your control

Ok

Does anyone know why this doesn't work

Public Class UserControl1
    Inherits System.Windows.Forms.UserControl

    Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
        Dim CB As New ComboBox()
        CB.Bounds = Me.Bounds
        CB.Font = Me.Font
        Me.InvokePaint(CB, e)
        MyBase.OnPaint(e)
    End Sub
End Class

yet this does work

Public Class UserControl1
    Inherits System.Windows.Forms.UserControl

    Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
        Dim CB As New button()
        CB.Bounds = Me.Bounds
        CB.Font = Me.Font
        Me.InvokePaint(CB, e)
        MyBase.OnPaint(e)
    End Sub
End Class

It's driving me nuts.

Please let me know

Joe


Answer this question

Invokepaint to paint another controls image on your control

  • jhnnym

    I was just going to post on this.  Hopefully someone will reply :)
  • gigo318

    Well I solved the problem.

    I have a project posted at PSC

    http://www.planet-source-code.com/vb/scripts/ShowCode.asp txtCodeId=1332&lngWId=10

    Hope it helps anyone that comes across this isssue.

    Joe

  • Nowandever29

    It would appear as though the listcontrol that the combo box and listbox inherit from does not paint in the same way as the buttonbase. Though they all inherit from control, it appears that some just don't paint in the same method.

    My one solution so far was to make a new control and inherit the combobox like this

    Public Class UserControl2
        Inherits System.Windows.Forms.ComboBox
        Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
            e.Graphics.DrawRectangle(New Pen(Color.Black), New Rectangle(0, 0, Me.Width, Me.Height))
            MyBase.OnPaint(e)
        End Sub
    End Class

    Now if the user uses this control in thier project it works just fine. Now if they use the invokepaint it will paint a rectangle with a black border.

    So every control that doesn't work and that I want to use this feature I must add this bit of code and make what looks like the paint of the control. 

    I know for a fact that the combo box must not use the onpaint since if you use this control with the modifications as above it paints normally and you got your normal combo box.

    This seems to be the issue with anything that inherits the listcontrol.

    Joe

  • Invokepaint to paint another controls image on your control