|
Hi,
I can't find how to resize a "homemade" line control, move the location of one end of it, or attach it to another control such as in a drawing program. I created the line control as follows (hope this is correct). I only need the line object at runtime so I haven't developed it for the design time environment. Would appreciate help or hints! I've looked all over and can't find the info :( . Nancy
Public Class frmDesign ....<form related code> Private Sub btnLink_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles btnLink.Click
Dim total As Integer Dim NewGraphics As Graphics NewGraphics = pnlDesignArea.CreateGraphics Dim nLink As New Link(NewGraphics, NewLinkA, NewLinkB)
total = pnlDesignArea.Controls.Count() nLink.Name = "Link" & total.ToString pnlDesignArea.Controls.Add(nLink)
AddHandler nLink.DoubleClick, AddressOf AllNodes_DoubleClick AddHandler nLink.MouseDown, AddressOf Terminal_MouseDown AddHandler nLink.MouseMove, AddressOf Terminal_MouseMove AddHandler nLink.MouseUp, AddressOf Terminal_MouseUp
NewGraphics.Dispose() End Sub .... End Class 'frmDesign
Public Class Link Inherits Control
Private mPointA As New Point(0, 0) Private mPointB As New Point(0, 0) Private mName As String
Public Sub New(ByVal nGraphics As Graphics, ByVal APoint As Point, ByVal BPoint As Point) MyBase.New() mPointA = APoint mPointB = BPoint Me.Height = 12 Me.Width = 70 nGraphics.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias SetStyle(ControlStyles.ResizeRedraw Or ControlStyles.Selectable _ Or ControlStyles.StandardClick Or ControlStyles.SupportsTransparentBackColor, True) Me.nDrawLink(nGraphics) End Sub
Public Property PointA() As Point Get Return mPointA End Get Set(ByVal Value As Point) mPointA = Value End Set End Property
Public Property PointB() As Point Get Return mPointB End Get Set(ByVal Value As Point) mPointB = Value End Set End Property
Public Property LName() As String Get Return mName End Get Set(ByVal Value As String) mName = Value End Set End Property
Public Sub nDrawLink(ByVal xLink As Graphics) Dim nPen As New Pen(Color.Black, 3) nPen.SetLineCap(Drawing.Drawing2D.LineCap.ArrowAnchor, _ Drawing.Drawing2D.LineCap.ArrowAnchor, Drawing.Drawing2D.DashCap.Flat) nPen.DashStyle = Drawing.Drawing2D.DashStyle.Solid
xLink.DrawLine(nPen, Me.mPointA, Me.mPointB)
nPen.Dispose() End Sub
Protected Overrides Sub OnPaint(ByVal pe As System.Windows.Forms.PaintEventArgs) MyBase.OnPaint(pe)
Dim graphics1 As Graphics graphics1 = pe.Graphics nDrawLink(graphics1)
graphics1.Dispose() End Sub
End Class 'Link |