Click here to Skip to main content
15,894,825 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am close to making an embedded control to my listview. Right now the only obstacle is using a 64x painting solution.

here is the code I am using now:


 Private Const WM_PAINT As Integer = &HF
Protected Overloads Overrides Sub WndProc(ByRef m As Message)
            Select Case m.Msg
                Case WM_PAINT
                    Dim rc As Rectangle
                    For Each ec As EmbeddedControl In _embeddedControls
                        rc = Me.GetSubItemBounds(ec.Item, ec.Column)
                        ec.Control.Bounds = rc
                    Next
                    Exit Select
            End Select
            MyBase.WndProc(m)
        End Sub


I have thought about using:

Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
           Select Case e.Graphics
               Case
           Dim rc As Rectangle
                   For Each ec As EmbeddedControl In _embeddedControls
                       rc = Me.GetSubItemBounds(ec.Item, ec.Column)
                       ec.Control.Bounds = rc
                   Next
                End Select


           MyBase.OnPaint(e)
       End Sub


The issue I am having is I do not understand what WM_PAINT is other than it has a 32bit system usage and not a 64 bit, which is what my program is built in.

What I have tried:

I have built a paint event, however, I am not sure what to make the case for it to refer to.
Posted
Updated 13-May-18 17:42pm

WM_PAINT is the message that tells windows to draw your control. A VB.NET control should not have any real use for it. There's no reason I can see for it not to fire in a 64 bit environment, your controls are being drawn.

Control.Paint Event (System.Windows.Forms)[^]

This is the .NET equivalent, which I think is the same as what you said. Just use the .NET version unless you need interop.
 
Share this answer
 
Comments
Member 11856456 11-May-18 0:41am    
I had seen this post originally and that is what gave me the idea to use a paint event instead. However, I am still having issues with how to approach what should be in the case portion.

Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
Dim blackPen As New Pen(Color.Black, 3)

Select Case e.Graphics
Case
Dim rc As Rectangle
For Each ec As EmbeddedControl In _embeddedControls
rc = Me.GetSubItemBounds(ec.Item, ec.Column)
ec.Control.Bounds = rc
Next
e.Graphics.DrawRectangle(blackPen, rc.X, rc.Y, rc.Width, rc.Height)
End Select


' Draw rectangle to screen.


MyBase.OnPaint(e)
End Sub

This should hoepfully replace the old method for the 32 bit system. any suggestions?
Richard Deeming 11-May-18 9:50am    
You don't need anything in the "case" part; you just need to remove the Select Case from that code.

You'll probably also want to move the DrawRectangle call inside the loop.
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
    Dim rc As Rectangle
    Dim blackPen As New Pen(Color.Black, 3)
    
    For Each ec As EmbeddedControl In _embeddedControls
        rc = Me.GetSubItemBounds(ec.Item, ec.Column)
        ec.Control.Bounds = rc
        
        e.Graphics.DrawRectangle(blackPen, rc.X, rc.Y, rc.Width, rc.Height)
    Next
    
    MyBase.OnPaint(e)
End Sub
Member 11856456 11-May-18 9:59am    
it's not embedding the control like the WM_PAINT was doing. This should have worked as an equivalent.
After many hours of searching I finally figured out that a regular paint eventargs was not what I needed. Apparently, I needed a protected overrides using a subitem draw event.

Protected Overrides Sub OnDrawSubItem(ByVal e As System.Windows.Forms.DrawListViewSubItemEventArgs)

      Dim rc As Rectangle
      For Each ec As EmbeddedControl In _embeddedControls
          rc = Me.GetSubItemBounds(ec.Item, ec.Column)
          ec.Control.Bounds = rc
      Next

      With e.Graphics
          .DrawLines(New Pen(SystemColors.ButtonShadow), New Point() {New Point(e.Bounds.Left, e.Bounds.Top - 1), New Point(e.Bounds.Left + e.Bounds.Width, e.Bounds.Top - 1), New Point(e.Bounds.Left + e.Bounds.Width, e.Bounds.Top + e.Bounds.Height), New Point(e.Bounds.Left, e.Bounds.Top + e.Bounds.Height)})
      End With

      e.DrawText()

      MyBase.OnDrawSubItem(e)

  End Sub


This still didnt solve my CPU issue, however, the reference to the 32bit dll is removed and the WM_paint event has now been replaced.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900