Results 1 to 10 of 10

Thread: Drawing Questions

  1. #1

    Thread Starter
    Member UConnVendetta's Avatar
    Join Date
    Jul 2003
    Location
    Madison, CT, USA
    Posts
    36

    Question Drawing Questions

    I remember in VB 6.0, I could draw a line. It really helped out with doing some GUI. But now it doesnt exist in .net and I really need it. Its too bad my version of 6.0 was only working model and i can't make stand-alone exes with it.

    I've had my share of "fun" working with TreeView and I'm trying a different approach that uses a collection of buttons and one sub that handles all the click events. The problem here is that I want the button layout to LOOK like a TreeView control so I need to be able to draw some lines between the buttons.

    I have already tried the following code:

    Private Sub frmButton_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim pen As New Drawing.Pen(System.Drawing.Color.Black, 5)
        Me.CreateGraphics.DrawLine(pen, 24, 56, 24, 504)
        pen.Dispose()
    End Sub


    When I try to compile I get no errors, but when the form loads, I do not see the line at all (and I'm sure that the line is NOT under the buttons on the form ). Any ideas what I might be doing wrong?
    Jazzman Will Rosenberg
    Chief Admin of [Vendetta]
    http://vendetta.n3.com
    AIM: UConnVendetta, CollegeGuy184

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Paste a lable into the form , make the height =1 and the width =any number . Now , it's like the line control in VB6 .
    Last edited by Pirate; Jul 27th, 2003 at 07:09 AM.

  3. #3

    Thread Starter
    Member UConnVendetta's Avatar
    Join Date
    Jul 2003
    Location
    Madison, CT, USA
    Posts
    36

    Hmmm

    Though that does work, I really want to know how to do it codewise. Someone please help!
    Jazzman Will Rosenberg
    Chief Admin of [Vendetta]
    http://vendetta.n3.com
    AIM: UConnVendetta, CollegeGuy184

  4. #4
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    The code you posted draws a line .

  5. #5
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    try this , you should get a red line across your form
    VB Code:
    1. Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
    2.         With e.Graphics
    3.             Dim p As New Pen(Color.Red, 5)
    4.             .DrawLine(p, 0, 50, Me.Width, 50)
    5.         End With
    6.     End Sub
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  6. #6

    Thread Starter
    Member UConnVendetta's Avatar
    Join Date
    Jul 2003
    Location
    Madison, CT, USA
    Posts
    36

    YaY

    Originally posted by dynamic_sysop
    try this , you should get a red line across your form
    VB Code:
    1. Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
    2.         With e.Graphics
    3.             Dim p As New Pen(Color.Red, 5)
    4.             .DrawLine(p, 0, 50, Me.Width, 50)
    5.         End With
    6.     End Sub
    This works but how is it called? Should I call it from my form_load?
    Jazzman Will Rosenberg
    Chief Admin of [Vendetta]
    http://vendetta.n3.com
    AIM: UConnVendetta, CollegeGuy184

  7. #7
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Re: YaY

    Originally posted by UConnVendetta
    This works but how is it called? Should I call it from my form_load?
    It loads by itself when the form is created.

  8. #8
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    if you do it in Form_Paint , as i did , it will always put the line there ( starting from the moment you load the form )
    also you should try to avoid calling an item by a keyword / expression ( eg: Pen as Pen ) use something else like " P as Pen " or MyPen as Pen " , this occassionally causes errors and can mislead you
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  9. #9

    Thread Starter
    Member UConnVendetta's Avatar
    Join Date
    Jul 2003
    Location
    Madison, CT, USA
    Posts
    36

    I see........

    So you're right. OK. I don't know why it wasnt workings for me. Maybe because I was trying to put it in Form_Load instead of Form_Paint. But Whatever....

    Well here's some random knowledge about VB.net:

    VB Code:
    1. If you_make_a_form_hide And show_a_new_form Then
    2.     'when you decide to close the form by hitting the X
    3.     theFormWill.Close()
    4.     'but the previous form that was hidden will remain in memory.
    5. End If
    6.  
    7. 'to make sure no part of your program stays in the memory,
    8. 'after closing your app you need the following sub:
    9. Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
    10. 'and inside the sub you need the word
    11.     End 'this will close all forms, and all open project files.
    12. End Sub
    Jazzman Will Rosenberg
    Chief Admin of [Vendetta]
    http://vendetta.n3.com
    AIM: UConnVendetta, CollegeGuy184

  10. #10
    Hyperactive Member
    Join Date
    May 2002
    Location
    Wisconsin, USA
    Posts
    279
    You could draw a line in the Paint event, and every time the object is painted, it will draw that line.

    VB Code:
    1. Private Sub Button1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Button1.Paint
    2.      'This example will draw two lines creating an X on the Button1 object.
    3.      Dim myPen As Pen = New Pen(Color.Red)
    4.      e.Graphics.DrawLine(myPen, 0, 0, e.ClipRectangle.Width, e.ClipRectangle.Height)
    5.      e.Graphics.DrawLine(myPen, 0, e.ClipRectangle.Height, e.ClipRectangle.Width, 0)
    6.  
    7. End Sub

Posting Permissions

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



Click Here to Expand Forum to Full Width