Results 1 to 10 of 10

Thread: how to draw arrow line using GDI? (to draw class association such as inheritance)

  1. #1
    icy7th is offline VB.NET Forum Newbie
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Oct 2008
    Posts
    6
    Reputation
    0

    Question how to draw arrow line using GDI? (to draw class association such as inheritance)

    I'm developing a class diagram editor now. but i'm stuck till now cause I can't find way to draw arrow using GDI.Help me...
    and also how to draw line to separate attributes and methods in a class?
    thx for the help!

  2. #2
    Robert_Zenz's Avatar
    Robert_Zenz is offline VB.NET Forum Idol
    .NET Framework
    .NET 2.0
    Join Date
    Jun 2008
    Location
    Vienna, Austria
    Posts
    503
    Reputation
    350
    Hello

    You'll have to create a GraphicsPath and transform that one.

    Bobby
    Don't give TypeCasting Errors a chance, turn ON Option Strict!

  3. #3
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    14,451
    Reputation
    2727
    Create a Pen and set its EndCap to be ArrowAnchor, drawing a line with this pen will produce an arrow. GDI+ Pens. Part 1.

  4. #4
    icy7th is offline VB.NET Forum Newbie
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Oct 2008
    Posts
    6
    Reputation
    0
    Quote Originally Posted by Robert_Zenz View Post
    Hello

    You'll have to create a GraphicsPath and transform that one.

    Bobby
    @Robert_Zenz
    I never used GraphicsPath before. Can you give me any example code? Thank's a lot. Sorry i I'm keeping on asking. I'm still at the early age to become .net programmer...

  5. #5
    icy7th is offline VB.NET Forum Newbie
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Oct 2008
    Posts
    6
    Reputation
    0
    Quote Originally Posted by JohnH View Post
    Create a Pen and set its EndCap to be ArrowAnchor, drawing a line with this pen will produce an arrow. GDI+ Pens. Part 1.
    @JohnH
    Thank's a lot. It is very helpfl. But now I need another kind of EndCap for line of implementation and aggregation. By the way, can I change the size of EndCap? It's very small till I can't see it clearly.

  6. #6
    icy7th is offline VB.NET Forum Newbie
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Oct 2008
    Posts
    6
    Reputation
    0
    I'm facing another problem now (again). Haha. I need an event that enables me to select the line (class association) and then delete it. I've tried the advice given by Robert and John (thank's a lot for both of you!). This is what I write on my code. I create line first, then I draw it on form by cloning the bitmap object. But in this way, I can only delete the line in sequence order, from the last one. What I want t build is that user can select a line that has been drawed and then they can delete it. Help me.. (again).. Hahaha

  7. #7
    Robert_Zenz's Avatar
    Robert_Zenz is offline VB.NET Forum Idol
    .NET Framework
    .NET 2.0
    Join Date
    Jun 2008
    Location
    Vienna, Austria
    Posts
    503
    Reputation
    350
    Hello!

    Of course I can give you an example of this.
    This code was originally designed to be placed within a control...

    Code:
            'this will draw an simple arrow
            'center is the center of the Object (f.e. Me.Width/2)
            Dim path As New GraphicsPath()
            path.AddPolygon(New Point() {New Point(center, 0), _
                                         New Point(center * 0.9, Me.Height * 0.2), _
                                         New Point(center * 0.97, Me.Height * 0.15), _
                                         New Point(center, Me.Height / 2), _
                                         New Point(center * 1.03, Me.Height * 0.15), _
                                         New Point(center * 1.1, Me.Height * 0.2)} _
                            )
    
            'rotate it 90° clockwise using the center of the object
            Dim rot As New Matrix()
            rot.RotateAt(90, New PointF(Me.Width / 2, Me.Height / 2))
            path.Transform(rot)
    
            'draw it
            e.Grphics.FillPath(Brushes.Black, path)
    If you want to select something you've drawn, then you'll have to process the Click-Event and interpret the Y-Position of the cursor. But I don't really understand what you mean with that you can only delete the last line. Keep the lines in a List or a Collection and you'll be able to delete any line in here.

    Bobby
    Don't give TypeCasting Errors a chance, turn ON Option Strict!

  8. #8
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    14,451
    Reputation
    2727
    Quote Originally Posted by icy7th View Post
    @JohnH
    Thank's a lot. It is very helpfl. But now I need another kind of EndCap for line of implementation and aggregation. By the way, can I change the size of EndCap? It's very small till I can't see it clearly.
    You can change the line width of the Pen to get a bolder line and larger end cap.
    Quote Originally Posted by icy7th View Post
    I'm facing another problem now (again). Haha. I need an event that enables me to select the line (class association) and then delete it. I've tried the advice given by Robert and John (thank's a lot for both of you!). This is what I write on my code. I create line first, then I draw it on form by cloning the bitmap object. But in this way, I can only delete the line in sequence order, from the last one. What I want t build is that user can select a line that has been drawed and then they can delete it. Help me.. (again).. Hahaha
    You'd have to manage your point pairs and draw them dynamically with some Paint event, keeping a collection of GraphicsPath seems viable, you should also be able to hittest a MouseDown on each of these paths. Haha.

  9. #9
    icy7th is offline VB.NET Forum Newbie
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Oct 2008
    Posts
    6
    Reputation
    0
    Quote Originally Posted by Robert_Zenz View Post

    If you want to select something you've drawn, then you'll have to process the Click-Event and interpret the Y-Position of the cursor. But I don't really understand what you mean with that you can only delete the last line. Keep the lines in a List or a Collection and you'll be able to delete any line in here.

    Bobby

    Sorry. My English is not so good!
    What I mean is that I need to place an event on line that I draw so I can select them and then delete. So far what I can do is only deleting the line sequencely from the last one to the first. By the way, may I know how do you keep the line you've drawed in the form so that it won't be gone after you make a new line. I find the solution but I'm, not sure. I draw it and then using MouseUp event I clone the line as the form background. Is it correct? Or maybe there's another solution? One more question. Is there any third arty component that can help me? Thank's alot Robert!!!

  10. #10
    icy7th is offline VB.NET Forum Newbie
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Oct 2008
    Posts
    6
    Reputation
    0
    Quote Originally Posted by JohnH View Post
    You can change the line width of the Pen to get a bolder line and larger end cap.

    You'd have to manage your point pairs and draw them dynamically with some Paint event, keeping a collection of GraphicsPath seems viable, you should also be able to hittest a MouseDown on each of these paths. Haha.
    I've tried it John but the size is not really proportional. By the way, may I know how do you place the line you've drawed so that it will stay in the form after you've draw new one? I clone it as the form background everytime I finish drawing but it makes everything difficult especially when I want to delete the line. Help me...

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Harvest time tracking