Ok this is ridiculous but...how the heck do you draw a line on a windows
form in design mode? There used to be a toolbar for VB forms but I cannot
find it in VS.NET

thanks,
eRic

Re: Draw a Line on a windows form by Justin

Justin
Thu Oct 09 13:26:24 CDT 2003

Override onPaint on your form. Add something like this:

Dim g as Graphics = e.Graphics
Dim mylinePen As System.Drawing.Pen = New
System.Drawing.Pen(System.Drawing.Color.Black, 1!)
Dim mylinePointStart As System.Drawing.PointF = New
System.Drawing.PointF(50!, 210!)
Dim mylinePointEnd As System.Drawing.PointF = New
System.Drawing.PointF(50!, 50!)

g.DrawLine(mylinePen, mylinePointStart, mylinePointEnd)
mylinePen.Dispose
MyBase.onPaint(e)




Here's a class you can just instantiate and pass your e.Graphics event to:

'GDIPlus Architect Component Class Output
Public Class Untitled1
Inherits System.ComponentModel.Component

Private mylinePen As System.Drawing.Pen = New
System.Drawing.Pen(System.Drawing.Color.Black, 1!)

Protected mylinePointStart As System.Drawing.PointF = New
System.Drawing.PointF(50!, 210!)

Protected mylinePointEnd As System.Drawing.PointF = New
System.Drawing.PointF(50!, 50!)

Public Sub New()
MyBase.New
Me.InitializeGraphics
End Sub

Private Sub InitializeGraphics()
End Sub

Public Overridable Sub RenderGraphics(ByVal g As
System.Drawing.Graphics)
g.DrawLine(Me.mylinePen, Me.mylinePointStart, Me.mylinePointEnd)
End Sub

'Required to dispose of created resources
Private Sub DisposeGraphics()
Me.mylinePen.Dispose
End Sub

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
Me.DisposeGraphics
End If
End Sub
End Class


C# version:

// GDIPlus Architect Component Class Output
public class Untitled1 : System.ComponentModel.Component {

private System.Drawing.Pen mylinePen = new
System.Drawing.Pen(System.Drawing.Color.Black, 1F);

protected System.Drawing.PointF mylinePointStart = new
System.Drawing.PointF(50F, 210F);

protected System.Drawing.PointF mylinePointEnd = new
System.Drawing.PointF(50F, 50F);

public Untitled1() {
this.InitializeGraphics();
}

private void InitializeGraphics() {
}

public virtual void RenderGraphics(System.Drawing.Graphics g) {
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
g.TextRenderingHint =
System.Drawing.Text.TextRenderingHint.AntiAlias;
g.DrawLine(this.mylinePen, this.mylinePointStart,
this.mylinePointEnd);
}

// Required to dispose of created resources
private void DisposeGraphics() {
this.mylinePen.Dispose();
}

protected override void Dispose(bool disposing) {
if (disposing) {
this.DisposeGraphics();
}
}
}


--
Justin Weinberg

Designing a PrintDocument? Drawing to forms?
Check out GDI+ Architect at www.mrgsoft.com


"eRic" <ezadler@hotmail.com> wrote in message
news:exlYqEpjDHA.2424@TK2MSFTNGP10.phx.gbl...
> Ok this is ridiculous but...how the heck do you draw a line on a windows
> form in design mode? There used to be a toolbar for VB forms but I cannot
> find it in VS.NET
>
> thanks,
> eRic
>
>



Re: Draw a Line on a windows form by Tom

Tom
Thu Oct 09 13:34:03 CDT 2003

It's not a ridiculous question at all. In fact it's a commonly asked
question.

In general, when you have this kind of question, you should use Google
Groups to search for the answer. You can find it at:
http://groups.google.com/

To answer your specific question, you can draw a vertical or horizontal line
by using a panel (or label) control and setting it's horizonal or vertical
size to 1. For diagnonal or curved lines, there is no control to help you
out, but you can draw it fairly easily during the Paint event (or by
overriding OnPaint()).

Here's some VB code from a post by Jay B Harlow [MVP Outlook]

The following code will draw the line on the panel.

Private Sub Panel1_Paint(ByVal sender As Object, _
ByVal e As System.Windows.Forms.PaintEventArgs) _
Handles Panel1.Paint
Dim BlackPen As Pen = New Pen(Color.Black, 1)
Dim Point1 As Point = New Point(5, 40)
Dim Point2 As Point = New Point(765, 40)
e.Graphics.DrawLine(BlackPen, Point1, Point2)
End Sub

The following code will draw the line on the form itself:

Protected Overrides Sub OnPaint( _
ByVal e As System.Windows.Forms.PaintEventArgs)
MyBase.OnPaint(e)
Dim BlackPen As Pen = New Pen(Color.Black, 1)
Dim Point1 As Point = New Point(5, 40)
Dim Point2 As Point = New Point(765, 40)
e.Graphics.DrawLine(BlackPen, Point1, Point2)
End Sub



"eRic" <ezadler@hotmail.com> wrote in message
news:exlYqEpjDHA.2424@TK2MSFTNGP10.phx.gbl...
> Ok this is ridiculous but...how the heck do you draw a line on a windows
> form in design mode? There used to be a toolbar for VB forms but I cannot
> find it in VS.NET
>
> thanks,
> eRic
>
>



Re: Draw a Line on a windows form by eRic