• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 232
  • Last Modified:

create line control

How i cane create a Line class that is based on System.Drawing namespace that provides access to GDI+ basic graphics functionality?
Note:
A Line control is a graphical control that displays a horizontal, vertical, or diagonal one-pixel-wide line that can't be changed directly. The Line control can be changed dynamically at run time.
0
standardxx
Asked:
standardxx
  • 3
  • 2
1 Solution
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
>> line that can't be changed directly.

Do you want the lines to be created/changed by you, the programmer, at design time...or do you want to create these at run-time?

Where should they be displayed?  On the form?  In a panel?  Over other controls?

Explain more what you are after here...

~IM
0
 
standardxxAuthor Commented:
hi, i need it as a control, just like the one was in VB6, i found some samples in the net, but they create the line and resize it as if its inside a rectangle. thats what i dont need, i need to move it and resize it just like in VB6, and there maybe label or text that should appear even if very neer to the line or on it
0
 
twopienkaCommented:
Please try this control - but it is just a basic version - line width, color and orientation settings could be done better:

Public Class ctrlLine
    Inherits System.Windows.Forms.UserControl

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'UserControl overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        components = New System.ComponentModel.Container()
    End Sub

#End Region

    Private _Orientation As String

    Private Sub ctrlLine_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
        Select Case _Orientation
            Case "HORIZONTAL"
                e.Graphics.DrawLine(New Pen(Color.Black), 0, 0, Me.Width, 0)
            Case "VERTICAL"
                e.Graphics.DrawLine(New Pen(Color.Black), 0, 0, 0, Me.Height)
            Case "DIAGONAL1"
                e.Graphics.DrawLine(New Pen(Color.Black), 0, 0, Me.Width, Me.Height)
            Case "DIAGONAL2"
                e.Graphics.DrawLine(New Pen(Color.Black), 0, Me.Height, Me.Width, 0)
        End Select
    End Sub

    Public Property Orientation() As String
        Get
            Return _Orientation
        End Get
        Set(ByVal Value As String)
            _Orientation = Value
            Me.Refresh()
        End Set
    End Property

    Private Sub ctrlLine_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize
        Me.Refresh()
    End Sub
End Class
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
standardxxAuthor Commented:
thats ok, But there is a problem
I need it to be transparent like a window showing all other controls at its back, when you send it to front , all other controls should appear at the back
for example if (Label1) at the back of horisontal line , it will appear this way


---------------Label1-----------------------

where ----- is the line control
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Hi standardxx,

The short answer is you can't get a control to behave that way.  It is possible to make a "transparent" control, but it is not actually a true transparency.  It only draws the background of the parent container.  If there is another control inbetween, it will not render itself so that control shows through but instead renders so the parent container shows through.  There is no way to make a line control like the one in VB6 either.

Sorry,

Idle_Mind
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
You should use an Enum instead of a String for the Orientation property:

Public Class Line
    Inherits System.Windows.Forms.UserControl

    Public Enum LineOrientation
        Horizontal = 0
        Vertical = 1
        DiagonalA = 2
        DiagonalB = 3
    End Enum

    Private _Orientation As LineOrientation = LineOrientation.Horizontal
    Private _Color As Color = System.Drawing.Color.Black

    Public Property Orientation() As LineOrientation
        Get
            Return _Orientation
        End Get
        Set(ByVal Value As LineOrientation)
            _Orientation = Value
            Me.Refresh()
        End Set
    End Property

    Public Property Color() As Color
        Get
            Return _Color
        End Get
        Set(ByVal Value As Color)
            _Color = Value
            Me.Refresh()
        End Set
    End Property

    Private Sub ctrlLine_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
        Dim p As New Pen(_Color)

        Select Case _Orientation
            Case LineOrientation.Horizontal
                e.Graphics.DrawLine(p, 0, 0, Me.Width, 0)

            Case LineOrientation.Vertical
                e.Graphics.DrawLine(p, 0, 0, 0, Me.Height)

            Case LineOrientation.DiagonalA
                e.Graphics.DrawLine(p, 0, 0, Me.Width, Me.Height)

            Case LineOrientation.DiagonalB
                e.Graphics.DrawLine(p, 0, Me.Height, Me.Width, 0)
        End Select

        p.Dispose()
    End Sub

    Private Sub Line_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize
        Me.Refresh()
    End Sub

End Class
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now