Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VB.net Draw permanent line

Posted on 2012-04-04
6
Medium Priority
?
555 Views
Last Modified: 2012-04-05
Hi
When I use the following code the line drawn seems to dissapear when
the next line is drawn. How do I make it permanent

 Sub oDrawLine()

        Dim Gr As Graphics = Me.TreeView_From.CreateGraphics()
        ' Create pen.

        Dim orangePen As Pen
        orangePen = New Pen(Color.DarkOrange, 2)

       Dim point1 As New Point(10, 10)
        Dim point2 As New Point(100, 500)

        Gr.DrawLine(orangePen, point1, point2)

    End Sub
0
Comment
Question by:Murray Brown
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 37805410
Draw it in the Paint event.
0
 

Author Comment

by:Murray Brown
ID: 37805450
Hi. Thanks. Where do I find that and how would the code look?
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 37805874
There is an OnPaint event.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Murray Brown
ID: 37806045
Hi. This is all a little obscure. What triggers the OnPaint event? There is no event  like that behind a TreeView. I a need a little more detail please.Thanks for the help
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 37806621
You can either:

(1) INHERIT from TreeView, set UserDraw to True, and override OnPaint().

(2) Use NATIVEWINDOW to trap the WM_PAINT message:
Public Class Form1

    Private WithEvents TVS As TreeViewSink

    Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        TVS = New TreeViewSink(Me.TreeView1)
    End Sub

    Private Sub TVS_Paint(TV As System.Windows.Forms.TreeView) Handles TVS.Paint
        Using G As Graphics = TV.CreateGraphics
            Debug.Print("Drawing Line")
            G.DrawLine(Pens.Red, 0, 0, TreeView1.Width, TreeView1.Height)
        End Using
    End Sub

End Class

Public Class TreeViewSink
    Inherits NativeWindow

    Private TV As TreeView
    Private Ignore As Boolean = False
    Private Const WM_PAINT As Integer = &HF

    Public Event Paint(ByVal TV As TreeView)

    Public Sub New(ByVal TV As TreeView)
        If Not IsNothing(TV) AndAlso TV.IsHandleCreated Then
            Me.TV = TV
            Me.AssignHandle(TV.Handle)
        End If
    End Sub

    Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
        Select Case m.Msg
            Case WM_PAINT
                If Not Ignore Then
                    Ignore = True
                    TV.Refresh()
                End If
                Ignore = False

                RaiseEvent Paint(Me.TV)

        End Select

        MyBase.WndProc(m)
    End Sub

End Class

Open in new window

0
 

Author Closing Comment

by:Murray Brown
ID: 37812405
Thanks very much
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question