Link to home
Start Free TrialLog in
Avatar of standardxx
standardxx

asked on

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.
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

>> 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
Avatar of standardxx
standardxx

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of twopienka
twopienka

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
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
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