Line across form

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mike L

    #1

    Line across form

    In VB.NET Windows Form, how do I add a line across the form?
  • Chris

    #2
    Re: Line across form

    Mike L wrote:[color=blue]
    > In VB.NET Windows Form, how do I add a line across the form?[/color]

    I did this inside of the forms paint method. Hope it helps.

    Chris

    Private Sub Main_Paint(ByVa l sender As Object, ByVal e As
    System.Windows. Forms.PaintEven tArgs) Handles MyBase.Paint

    Dim Pen As New Pen(Color.Mediu mBlue, 2)
    Dim TopLine As Integer = 150
    Dim BottomLine As Integer = 388
    e.Graphics.Draw Line(Pen, 0, TopLine, 640, TopLine)


    End Sub

    Comment

    • Armin Zingler

      #3
      Re: Line across form

      "Mike L" <Cadel@nospam.n ospam> schrieb[color=blue]
      > In VB.NET Windows Form, how do I add a line across the form?[/color]



      http://msdn.microsoft.com/library/en..._usecsharp.asp

      (same via <F1>)

      Armin

      Comment

      • Herfried K. Wagner [MVP]

        #4
        Re: Line across form

        "Chris" <no@spam.com> schrieb:[color=blue][color=green]
        >> In VB.NET Windows Form, how do I add a line across the form?[/color]
        >
        > I did this inside of the forms paint method. Hope it helps.
        >
        > Chris
        >
        > Private Sub Main_Paint(ByVa l sender As Object, ByVal e As
        > System.Windows. Forms.PaintEven tArgs) Handles MyBase.Paint
        >
        > Dim Pen As New Pen(Color.Mediu mBlue, 2)
        > Dim TopLine As Integer = 150
        > Dim BottomLine As Integer = 388
        > e.Graphics.Draw Line(Pen, 0, TopLine, 640, TopLine)[/color]

        'Pen' objects should be disposed if they are not needed any more. It's
        better to store the 'Pen' object in a private variable, for example, instead
        of creating a new pen every time the form is drawn.

        --
        M S Herfried K. Wagner
        M V P <URL:http://dotnet.mvps.org/>
        V B <URL:http://classicvb.org/petition/>

        Comment

        • Ken Tucker [MVP]

          #5
          Re: Line across form

          Hi,

          A line and shape control I created.



          Ken
          -----------------
          "Mike L" <Cadel@nospam.n ospam> wrote in message
          news:2B5A7051-B557-4FA3-928E-BB6907A00F4D@mi crosoft.com...
          In VB.NET Windows Form, how do I add a line across the form?


          Comment

          • Herfried K. Wagner [MVP]

            #6
            Re: Line across form

            "Mike L" <Cadel@nospam.n ospam> schrieb:[color=blue]
            > In VB.NET Windows Form, how do I add a line across the form?[/color]

            Shapes and lines:

            Advanced Shape Control
            <URL:http://www.codeproject .com/vb/net/advanced_shape_ control.asp>

            LineControls.ex e
            <URL:http://www.gotdotnet.c om/team/vb/LineControls.ex e>
            <URL:http://download.micros oft.com/download/7/e/0/7e070297-47fe-4443-9194-ab57acd8ea01/LineControls.ms i>

            Creating transparent Windows Forms controls.
            <URL:http://www.bobpowell.n et/transcontrols.h tm>

            Rules:

            Wrapping Win32 Controls in .NET - Horizontal and Vertical Rules
            <URL:http://www.codeproject .com/cs/miscctrl/hvrules1.asp>

            Alternatively you can use a label control with width or height set to 2, and
            'BorderStyle' set to 'Fixed3D' to create an inset line.

            --
            M S Herfried K. Wagner
            M V P <URL:http://dotnet.mvps.org/>
            V B <URL:http://classicvb.org/petition/>

            Comment

            • Chris

              #7
              Re: Line across form

              Herfried K. Wagner [MVP] wrote:[color=blue]
              > "Chris" <no@spam.com> schrieb:
              >[color=green][color=darkred]
              >>> In VB.NET Windows Form, how do I add a line across the form?[/color]
              >>
              >>
              >> I did this inside of the forms paint method. Hope it helps.
              >>
              >> Chris
              >>
              >> Private Sub Main_Paint(ByVa l sender As Object, ByVal e As
              >> System.Windows. Forms.PaintEven tArgs) Handles MyBase.Paint
              >>
              >> Dim Pen As New Pen(Color.Mediu mBlue, 2)
              >> Dim TopLine As Integer = 150
              >> Dim BottomLine As Integer = 388
              >> e.Graphics.Draw Line(Pen, 0, TopLine, 640, TopLine)[/color]
              >
              >
              > 'Pen' objects should be disposed if they are not needed any more. It's
              > better to store the 'Pen' object in a private variable, for example,
              > instead of creating a new pen every time the form is drawn.
              >[/color]

              Thanks for the info. If I use the same pen for the life of the form
              should I still dispose of it when the form is closed, or will the
              auto-disposing of the form take care of it for me?

              chris

              Comment

              • Herfried K. Wagner [MVP]

                #8
                Re: Line across form

                "Chris" <no@spam.com> schrieb:[color=blue][color=green][color=darkred]
                >>> Private Sub Main_Paint(ByVa l sender As Object, ByVal e As
                >>> System.Windows. Forms.PaintEven tArgs) Handles MyBase.Paint
                >>>
                >>> Dim Pen As New Pen(Color.Mediu mBlue, 2)
                >>> Dim TopLine As Integer = 150
                >>> Dim BottomLine As Integer = 388
                >>> e.Graphics.Draw Line(Pen, 0, TopLine, 640, TopLine)[/color]
                >>
                >>
                >> 'Pen' objects should be disposed if they are not needed any more. It's
                >> better to store the 'Pen' object in a private variable, for example,
                >> instead of creating a new pen every time the form is drawn.
                >>[/color]
                >
                > Thanks for the info. If I use the same pen for the life of the form
                > should I still dispose of it when the form is closed, or will the
                > auto-disposing of the form take care of it for me?[/color]

                You may want to call the pen's 'Dispose' method in the form's overridden
                'Dispose' method.

                --
                M S Herfried K. Wagner
                M V P <URL:http://dotnet.mvps.org/>
                V B <URL:http://classicvb.org/petition/>

                Comment

                • Mike L

                  #9
                  Re: Line across form

                  Your answer worked best, I used the simple label control, set it to black and
                  resized using the mouse. Did it in less than a second and I didn't have to
                  write one line of code. Thank you.

                  "Herfried K. Wagner [MVP]" wrote:
                  [color=blue]
                  > "Mike L" <Cadel@nospam.n ospam> schrieb:[color=green]
                  > > In VB.NET Windows Form, how do I add a line across the form?[/color]
                  >
                  > Shapes and lines:
                  >
                  > Advanced Shape Control
                  > <URL:http://www.codeproject .com/vb/net/advanced_shape_ control.asp>
                  >
                  > LineControls.ex e
                  > <URL:http://www.gotdotnet.c om/team/vb/LineControls.ex e>
                  > <URL:http://download.micros oft.com/download/7/e/0/7e070297-47fe-4443-9194-ab57acd8ea01/LineControls.ms i>
                  >
                  > Creating transparent Windows Forms controls.
                  > <URL:http://www.bobpowell.n et/transcontrols.h tm>
                  >
                  > Rules:
                  >
                  > Wrapping Win32 Controls in .NET - Horizontal and Vertical Rules
                  > <URL:http://www.codeproject .com/cs/miscctrl/hvrules1.asp>
                  >
                  > Alternatively you can use a label control with width or height set to 2, and
                  > 'BorderStyle' set to 'Fixed3D' to create an inset line.
                  >
                  > --
                  > M S Herfried K. Wagner
                  > M V P <URL:http://dotnet.mvps.org/>
                  > V B <URL:http://classicvb.org/petition/>
                  >
                  >[/color]

                  Comment

                  Working...