I am shailendra kumar working as a junior programmer in a share trading company .The basic idea of the company is to create trading and graphics software.
I have been provided with some such works.What i have to do is to provide the user with a pen kind of utility and let the user sketch lines over the pre generated graphs.
The lines should be drawn as an object so that for deleting it user right clicks in it and delete it.
for example suppose the user has drawn 5 lines and he then thinks that the third line is useless sol delete it.
Other task to side by side is there are different sizes of the forms provided to the user .If the user selects small the graphs squizes so the lines should also respectively.
I am using vb express.
Please help me .I have searched it all over the net but was unable to find it.
Thanks and regards
Shailendra Kumar
New Delhi
Ruta KaryakartePosted Jan 4, 2007, 12:46 AM
And then take context menu on ur form.write module.
in that context menu.
And add dll of user control of folloing code. witr code for delete.
'''
#
Region "Imports"'''
Imports
System.ComponentModelImports
System.ComponentModel.Design.SerializationImports
System.TextImports
System.DrawingImports
System.Drawing.Drawing2DImports
System.GlobalizationImports
System.ReflectionImports
System.Windows.Forms'''
#
End Region'''
#
Region "Enums"'''
Public
Enum ShapesHorizontalLine
VerticalLine
NESWDiagonal
NWSEDiagonal
End
Enum'''
Public
Enum LineStylesNone
FixedSingle
Fixed3D
Sunken
End
Enum'''
#
End Region''''
#
Region "ShapeEx Control Class"
GetType(Drawing.Bitmap), "ShapeEx.bmp"), _ToolboxBitmap(
ToolboxItem(
True)> _Public
Class ShapeEx : Inherits System.Windows.Forms.UserControl '''#
Region "Private Variables" Private Event PorpertyChanged() Private Ln_Points(1) As Point Private Fill_Region As Region ''' Private __AlphaBlend As Byte Private __Shape As Shapes Private __LineColor As System.Drawing.Color ''' Private WithEvents __GradiantOptions As New GradiantProperties(Color.Empty, Color.Empty, LinearGradientMode.Horizontal) Private WithEvents __HatchOptions As New HatchProperties(Color.Empty, Color.Transparent, 0) Private WithEvents __LineOptions As New LineProperties(2, Color.Black, False, DashStyle.Solid, Border3DStyle.Flat, Color.Empty, Color.Empty, LinearGradientMode.Horizontal) ''' Private __DrawGradiant As Boolean Private __DrawHatch As Boolean Private __SmoothMode As SmoothingMode ''' Private __Rect As Rectangle '''#
End Region#
Region " Component Designer generated code " Public Sub New() MyBase.New() ' This call is required by the Component Designer.InitializeComponent()
'Add any initialization after the InitializeComponent() callSetStyle(ControlStyles.DoubleBuffer,
True)SetStyle(ControlStyles.ResizeRedraw,
True)SetStyle(ControlStyles.SupportsTransparentBackColor,
True) Me.BackColor = Color.Transparent AddHandler Me.PorpertyChanged, AddressOf Me.OnPropertyChange 'Add any initialization after the InitializeComponent() callLoadDefaults()
End Sub 'Required by the Control Designer Private components As System.ComponentModel.IContainer ' NOTE: The following procedure is required by the Component Designer ' It can be modified using the Component Designer. Do not modify it ' using the code editor.
Private Sub InitializeComponent()components =
New System.ComponentModel.Container End Sub#
End Region#
Region "Properties" '''
True), _Browsable(
Category("Design"), _
Description("Set True if you want to draw gradiant background")> _
Public Property SmoothMode() As SmoothingMode Get Return __SmoothMode End Get Set(ByVal value As SmoothingMode)__SmoothMode = value
Me.Invalidate() End Set End Property '''Browsable(
True), _Category("Design"), _
Description("Set True if you want to draw gradiant background")> _
Public Property DrawGradiant() As Boolean Get Return __DrawGradiant End Get Set(ByVal Value As Boolean)__DrawGradiant = Value
Invalidate()
End Set End Property '''Browsable(
True), _Category("Design"), _
Description("Set True if you want to draw hatch background")> _
Public Property DrawHatch() As Boolean Get Return __DrawHatch End Get Set(ByVal Value As Boolean)__DrawHatch = Value
Invalidate()
End Set End Property '''RefreshProperties(RefreshProperties.Repaint), _
Category("Values"), _
Description("Set the properties for border")> _
Public Property LineOptions() As LineProperties Get Return __LineOptions End Get Set(ByVal Value As LineProperties)__LineOptions = Value
End Set End Property '''RefreshProperties(RefreshProperties.Repaint), _
Category("Values"), _
Description("Set the properties for gradiant")> _
Public Property GradiantOptions() As GradiantProperties Get Return __GradiantOptions End Get Set(ByVal Value As GradiantProperties)__GradiantOptions = Value
End Set End Property '''RefreshProperties(RefreshProperties.Repaint), _
Category("Values"), _
Description("Set the properties for hatch desing")> _
Public Property HatchOptions() As HatchProperties Get Return __HatchOptions End Get Set(ByVal Value As HatchProperties)__HatchOptions = Value
End Set End Property '''
True), _Browsable(
Category("Design"), _
Description("Set the shape")> _
Public Property Shape() As Shapes Get Return __Shape End Get Set(ByVal Value As Shapes)__Shape = Value
Invalidate()
End Set End Property '''Category("Design"), _
Description("Set the shape fill color")> _
Public Property LineColor() As System.Drawing.Color Get Return __LineColor End Get Set(ByVal Value As System.Drawing.Color)__LineColor = Value
Invalidate()
End Set End Property '''
True), _Browsable(
Category("Design"), _
Description("Set the alpha blend for the shape")> _
Public Property AlphaBlend() As Byte Get Return __AlphaBlend End Get Set(ByVal Value As Byte)__AlphaBlend = Value
Invalidate()
End Set End Property '''#
End Region '''#
Region "Overrides" ''' Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Thencomponents.Dispose()
End If End If MyBase.Dispose(disposing) End Sub ''' Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)ReDrawControl(e.Graphics)
End Sub '''#
End Region '''#
Region "Procedures" ''' Private Sub BorderEx_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.ResizeInvalidate()
End Sub ''' Public Sub LoadDefaults() '******************************************************** ' Load default values '******************************************************** With Me.__LineColor = System.Drawing.SystemColors.ActiveCaption
.__Shape = Shapes.HorizontalLine
.__AlphaBlend = 255
.__DrawGradiant =
False.__DrawHatch =
False.Size =
New Size(150, 20) End With End Sub ''' Public Function ShouldSerializeFillColor() As Boolean Return Not (__LineColor.ToArgb = Color.Black.ToArgb) End Function ''' Private Sub ReDrawControl(ByRef g As Graphics) '******************************************************** ' Controls the drawing flow '******************************************************** 'Calculate RegionsCreateRegion()
'FillGradiant If __DrawGradiant Then Draw_Gradient(g) 'FillHatch If __DrawHatch Then Draw_Hatch(g) 'DrawBorderDraw_Line(g)
End Sub ''' Private Sub CreateRegion() '******************************************************** ' Creates regions for the selected shape '******************************************************** Dim graphics_path As GraphicsPath = New GraphicsPath '''Ln_Points = GenerateLinePoints(
New Rectangle(0, 0, Me.Width, Me.Height))graphics_path.AddPolygon(Ln_Points)
'graphics_path.AddLine(Ln_Points(0), Ln_Points(1))Fill_Region =
New Region(graphics_path)graphics_path.Dispose()
End Sub ''' Private Sub Draw_Line(ByRef g As Graphics) '******************************************************* 'Draws the border for the selected shape '******************************************************* Dim _Brush As Drawing2D.LinearGradientBrush Dim _Pen As Pen Try If __LineOptions.LineGradiant Then_Brush =
New Drawing2D.LinearGradientBrush(New Rectangle(0, 0, Me.Width, Me.Height), __LineOptions.StartColor, __LineOptions.EndColor, __LineOptions.GradiantStyle)_Pen =
New Pen(_Brush, __LineOptions.BorderWidth) Else_Pen =
New Pen(__LineOptions.BorderColor, __LineOptions.BorderWidth) End If_Pen.Alignment = PenAlignment.Inset
_Pen.DashStyle = __LineOptions.LineDashStyle
g.SmoothingMode =
Me.SmoothModeg.DrawLine(_Pen, Ln_Points(0).X, Ln_Points(0).Y, Ln_Points(1).X, Ln_Points(1).Y)
Catch ex As Exception Throw ex Finally If Not IsNothing(_Pen) Then _Pen.Dispose() If Not IsNothing(_Brush) Then _Brush.Dispose() End Try End Sub ''' Private Sub Draw_Gradient(ByRef g As Graphics) '******************************************************** ' Fills the control with gradiant brush '******************************************************** Dim __GradientBrush As LinearGradientBrush Try__GradientBrush =
New LinearGradientBrush(New Rectangle(0, 0, Me.Width, Me.Height), Me.__GradiantOptions.StartColor, Me.__GradiantOptions.EndColor, Me.__GradiantOptions.GradiantStyle) Select Case __Shape Case Shapes.HorizontalLineg.FillPolygon(__GradientBrush, Ln_Points)
End Select Catch ex As Exception Throw ex Finally__GradientBrush.Dispose()
End Try End Sub ''' Private Sub Draw_Hatch(ByRef g As Graphics) '******************************************************** ' Draws Hatch design on the control '******************************************************** Dim __HatchBrush As HatchBrush Try__HatchBrush =
New HatchBrush(Me.__HatchOptions.HatchStyle, Me.__HatchOptions.PenColor, Me.__HatchOptions.BackColor)g.SmoothingMode =
Me.SmoothMode Select Case __Shape Case Shapes.HorizontalLineg.FillPolygon(__HatchBrush, Ln_Points)
End Select Catch ex As Exception Throw ex Finally__HatchBrush.Dispose()
End Try End Sub ''' Private Function GenerateLinePoints(ByVal Rect As Rectangle) As Point() '******************************************************** ' Generates Line points for the control '******************************************************** Dim Ln_Points(2) As Point Dim _Width As Integer = Rect.Width Dim _Height As Integer = Rect.Height Dim StartPoint As Point Dim EndPoint As Point Try Select Case Me.Shape Case Shapes.HorizontalLineStartPoint =
New Point(Rect.Left, Rect.Top + (_Height / 2))EndPoint =
New Point(Rect.Left + _Width, Rect.Top + (_Height / 2)) Exit Select Case Shapes.VerticalLineStartPoint =
New Point(Rect.Left + (_Width / 2), Rect.Top)EndPoint =
New Point(Rect.Left + (_Width / 2), Rect.Top + _Height) Exit Select Case Shapes.NWSEDiagonal ' \ ' \ ' \StartPoint =
New Point(Rect.Left, Rect.Top)EndPoint =
New Point(Rect.Left + _Width, Rect.Top + _Height) Exit Select Case Shapes.NESWDiagonal ' / not working properly ' / ' /StartPoint =
New Point(Rect.Left + _Width, Rect.Top)EndPoint =
New Point(Left, Rect.Top + _Height) Exit Select Case ElseStartPoint =
New Point(Rect.Left, Rect.Top + (_Height / 2))EndPoint =
New Point(Rect.Left + _Width, Rect.Top + (_Height / 2)) Exit Select End SelectLn_Points(0) = StartPoint
Ln_Points(1) = EndPoint
Return Ln_Points Catch ex As Exception Throw ex Return Nothing Finally End Try End Function ''' Private Sub OnPropertyChange()ReDrawControl(
Me.CreateGraphics) End Sub ''' Private Sub __GradiantOptions_PropertyChanged() Handles __GradiantOptions.PropertyChanged If __DrawGradiant Then Me.Invalidate() End Sub ''' Private Sub __HatchOptions_PropertyChanged() Handles __HatchOptions.PropertyChanged If __DrawHatch Then Me.Invalidate() End Sub ''' Private Sub __LineOptions_PropertyChanged() Handles __LineOptions.PropertyChanged Me.Invalidate() End Sub '''#
End Region '''End
Class'''
#
End Region#
Region "Hacth"'''
#
Region "Hatch Properties class"''''
Public
Class HatchProperties '''#
Region "Variables" ''' Private __PenColor As System.Drawing.Color Private __BackColor As System.Drawing.Color Private __HatchStyle As Drawing2D.HatchStyle Event PropertyChanged() '''#
End Region '''#
Region "Properties" ''' Public Property PenColor() As System.Drawing.Color Get Return __PenColor End Get Set(ByVal Value As System.Drawing.Color)__PenColor = Value
RaiseEvent PropertyChanged() End Set End Property ''' Public Property BackColor() As System.Drawing.Color Get Return __BackColor End Get Set(ByVal Value As System.Drawing.Color)__BackColor = Value
RaiseEvent PropertyChanged() End Set End Property ''' Public Property HatchStyle() As System.Drawing.Drawing2D.HatchStyle Get Return __HatchStyle End Get Set(ByVal Value As System.Drawing.Drawing2D.HatchStyle)__HatchStyle = Value
RaiseEvent PropertyChanged() End Set End Property '''#
End Region '''#
Region "Procedures" ''' Public Sub New(ByVal penColor As Color, ByVal BackColor As Color, ByVal HatchStyle As Drawing2D.HatchStyle) ''Load Defaults Me.__PenColor = penColor Me.__BackColor = BackColor Me.__HatchStyle = HatchStyle End Sub '''#
End Region '''End
Class'''
#
Region "HatchPropertiesConverter class"'''
Friend
Class HatchPropertiesConverter : Inherits ExpandableObjectConverter '''#
Region "Properties" ''' Public Overloads Overrides Function CanConvertFrom(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal sourceType As System.Type) As Boolean If sourceType Is GetType(String) Then Return True Else Return MyBase.CanConvertFrom(context, sourceType) End If End Function '' Public Overloads Overrides Function CanConvertTo(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal destinationType As System.Type) As Boolean If destinationType Is GetType(InstanceDescriptor) Or destinationType Is GetType(String) Then Return True End If Return MyBase.CanConvertTo(context, destinationType) End Function '' Public Overloads Overrides Function ConvertFrom(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal culture As System.Globalization.CultureInfo, ByVal value As Object) As Object ''' Dim __Value As String Try__Value = value
If Not (__Value Is Nothing) Then__Value = __Value.Trim()
If __Value.Length <> 0 Then If culture Is Nothing Then culture = CultureInfo.CurrentCulture Dim params As String() = __Value.Split(",") Dim _PenColor As Color Dim _BackColor As Color Dim _HatchStyle As HatchStyle If IsNothing(params(0)) OrElse params(0) = "" Then _PenColor = Color.Black Else _PenColor = ColorTranslator.FromHtml(params(0)) If IsNothing(params(1)) OrElse params(1) = "" Then _BackColor = Color.Transparent Else _BackColor = ColorTranslator.FromHtml(params(1)) If IsNothing(params(2)) OrElse params(2) = "" Then _HatchStyle = 0 Else _HatchStyle = params(2) Return New HatchProperties(_PenColor, _BackColor, _HatchStyle) Else Return MyBase.ConvertFrom(context, culture, value) End If End If Catch ex As Exception Throw New ArgumentException("Invalid string for conversion - " & __Value) End Try End Function '' Public Overloads Overrides Function ConvertTo(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal culture As System.Globalization.CultureInfo, ByVal value As Object, ByVal destinationType As System.Type) As Object ''' Dim __HatchProperties As HatchProperties Try__HatchProperties = value
If destinationType Is GetType(InstanceDescriptor) Then Dim argTypes As System.Type() = New System.Type(2) {}argTypes(0) =
GetType(Color)argTypes(1) =
GetType(Color)argTypes(2) =
GetType(HatchStyle) Dim constructor As ConstructorInfo = GetType(HatchProperties).GetConstructor(argTypes) Dim arguments As Object() = New Object(2) {}arguments(0) = __HatchProperties.PenColor
arguments(1) = __HatchProperties.BackColor
arguments(2) = __HatchProperties.HatchStyle
Return New InstanceDescriptor(constructor, arguments) ElseIf (destinationType Is GetType(String)) Then If (culture Is Nothing) Then culture = CultureInfo.CurrentCulture Dim Params(3) As StringParams(0) = ColorTranslator.ToHtml(__HatchProperties.PenColor)
Params(1) = ColorTranslator.ToHtml(__HatchProperties.BackColor)
Params(2) = __HatchProperties.HatchStyle
Return Join(Params, ",") Else Return MyBase.ConvertTo(context, culture, value, destinationType) End If Catch ex As Exception Throw New ArgumentException End Try ''' End Function '''#
End Region '''End
Class'''
#
End Region'''
#
End Region'''
#
End Region'''
#
Region "Gradiant"'''
#
Region "Gradiant Properties class"''''
Public
Class GradiantProperties '''#
Region "Variables" ''' Private __StartColor As System.Drawing.Color Private __EndColor As System.Drawing.Color Private __GradiantStyle As Drawing.Drawing2D.LinearGradientMode Event PropertyChanged() '''#
End Region '''#
Region "Properties" '''Description("Select the starting color for gradiant"), _
NotifyParentProperty(
True)> _ Public Property StartColor() As System.Drawing.Color Get Return __StartColor End Get Set(ByVal Value As System.Drawing.Color)__StartColor = Value
RaiseEvent PropertyChanged() End Set End Property '''Description("Select the end color for gradiant"), _
NotifyParentProperty(
True)> _ Public Property EndColor() As System.Drawing.Color Get Return __EndColor End Get Set(ByVal Value As System.Drawing.Color)__EndColor = Value
RaiseEvent PropertyChanged() End Set End Property '''DefaultValue(0), _
Description("Select the gradiant style"), _
NotifyParentProperty(
True)> _ Public Property GradiantStyle() As Drawing.Drawing2D.LinearGradientMode Get Return __GradiantStyle End Get Set(ByVal Value As Drawing.Drawing2D.LinearGradientMode)__GradiantStyle = Value
RaiseEvent PropertyChanged() End Set End Property '''#
End Region '''#
Region "Procedures" ''' Public Sub New(ByVal Start_Color As Color, ByVal End_Color As Color, ByVal Options As Drawing2D.LinearGradientMode) ''Load Defaults Me.__StartColor = Start_Color Me.__EndColor = End_Color Me.__GradiantStyle = Options End Sub '''#
End Region '''End
Class'''
#
End Region'''
#
Region "GradiantPropertiesConverter class"'''
Friend
Class GradiantPropertiesConverter : Inherits ExpandableObjectConverter '''#
Region "Properties" ''' Public Overloads Overrides Function CanConvertFrom(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal sourceType As System.Type) As Boolean If sourceType Is GetType(String) Then Return True Else Return MyBase.CanConvertFrom(context, sourceType) End If End Function '' Public Overloads Overrides Function CanConvertTo(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal destinationType As System.Type) As Boolean If destinationType Is GetType(InstanceDescriptor) Or destinationType Is GetType(String) Then Return True End If Return MyBase.CanConvertTo(context, destinationType) End Function '' Public Overloads Overrides Function ConvertFrom(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal culture As System.Globalization.CultureInfo, ByVal value As Object) As Object '' Parse the string format which is: name,breed,age Dim sValue As String = value If Not IsDBNull(sValue) Then Dim v As String() = sValue.Split(New Char() {","}) Return New GradiantProperties(ColorTranslator.FromHtml(v(0)), ColorTranslator.FromHtml(v(1)), v(2)) Else Return MyBase.ConvertFrom(context, culture, value) End If End Function '' Public Overloads Overrides Function ConvertTo(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal culture As System.Globalization.CultureInfo, ByVal value As Object, ByVal destinationType As System.Type) As Object If destinationType Is GetType(InstanceDescriptor) Then Return New InstanceDescriptor(GetType(GradiantProperties).GetConstructor(New Type() {GetType(Color), GetType(Color), GetType(Drawing2D.LinearGradientMode)}), New Object() {value.startcolor, value.endcolor, value.gradiantstyle}) ElseIf destinationType Is GetType(String) Then Return String.Format("{0},{1},{2}", ColorTranslator.ToHtml(value.startcolor), ColorTranslator.ToHtml(value.endcolor), value.gradiantstyle) End If Return MyBase.ConvertTo(context, culture, value, destinationType) End Function '''#
End Region '''End
Class'''
#
End Region#
End Region#
Region "Line Prop"'''
#
Region "Line Properties"'''
Public
Class LineProperties '''#
Region "Variables" ''' Private __StartColor As System.Drawing.Color Private __EndColor As System.Drawing.Color Private __GradiantStyle As Drawing2D.LinearGradientMode Private __LineColor As Color Private __LineWidth As Short Private __LineStyle As Windows.Forms.Border3DStyle Private __LineDashStyle As Drawing2D.DashStyle Private __LineGradiant As Boolean ''' Event PropertyChanged() '''#
End Region '''#
Region "Properties" '''Description("Set true to draw gradiant border"), _
NotifyParentProperty(
True)> _ Public Property LineGradiant() As Boolean Get Return __LineGradiant End Get Set(ByVal Value As Boolean)__LineGradiant = Value
RaiseEvent PropertyChanged() End Set End Property '''Description("Select the Border dash style"), _
NotifyParentProperty(
True)> _ Public Property LineDashStyle() As Drawing2D.DashStyle Get Return __LineDashStyle End Get Set(ByVal Value As Drawing2D.DashStyle)__LineDashStyle = Value
RaiseEvent PropertyChanged() End Set End Property '''Description("Select the starting color for border gradiant"), _
NotifyParentProperty(
True)> _ Public Property BorderStyle() As Windows.Forms.Border3DStyle Get Return __LineStyle End Get Set(ByVal Value As Windows.Forms.Border3DStyle)__LineStyle = Value
RaiseEvent PropertyChanged() End Set End Property '''Description("Select the starting color for border gradiant"), _
NotifyParentProperty(
True)> _ Public Property BorderWidth() As Short Get Return __LineWidth End Get Set(ByVal Value As Short)__LineWidth = Value
RaiseEvent PropertyChanged() End Set End Property '''Description("Select the border color"), _
NotifyParentProperty(
True)> _ Public Property BorderColor() As System.Drawing.Color Get Return __LineColor End Get Set(ByVal Value As System.Drawing.Color)__LineColor = Value
RaiseEvent PropertyChanged() End Set End Property '''Description("Select the starting color for border gradiant"), _
NotifyParentProperty(
True)> _ Public Property StartColor() As System.Drawing.Color Get Return __StartColor End Get Set(ByVal Value As System.Drawing.Color)__StartColor = Value
RaiseEvent PropertyChanged() End Set End Property '''Description("Select the end color for border gradiant"), _
NotifyParentProperty(
True)> _ Public Property EndColor() As System.Drawing.Color Get Return __EndColor End Get Set(ByVal Value As System.Drawing.Color)__EndColor = Value
RaiseEvent PropertyChanged() End Set End Property '''DefaultValue(0), _
Description("Select the gradiant style for border"), _
NotifyParentProperty(
True)> _ Public Property GradiantStyle() As Drawing.Drawing2D.LinearGradientMode Get Return __GradiantStyle End Get Set(ByVal Value As Drawing.Drawing2D.LinearGradientMode)__GradiantStyle = Value
RaiseEvent PropertyChanged() End Set End Property '''#
End Region '''#
Region "Procedures" ''' Public Sub New(ByVal Border_Width As Short, ByVal Border_Color As Color, ByVal Border_Gradiant As Boolean, ByVal Border_DashStyle As Drawing2D.DashStyle, ByVal Border_Style As Windows.Forms.Border3DStyle, ByVal Start_Color As Color, ByVal End_Color As Color, ByVal Gradiant_Style As Drawing2D.LinearGradientMode) ''Load Defaults__StartColor = Start_Color
__EndColor = End_Color
__GradiantStyle = Gradiant_Style
__LineColor = Border_Color
__LineDashStyle = Border_DashStyle
__LineGradiant = Border_Gradiant
__LineStyle = Border_Style
__LineWidth = Border_Width
End Sub '''#
End Region '''End
Class'''
#
End Region'''
#
Region "BorderPropertiesConverter class"'''
Friend
Class BorderPropertiesConverter : Inherits ExpandableObjectConverter '''#
Region "Properties" ''' Public Overloads Overrides Function CanConvertFrom(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal sourceType As System.Type) As Boolean If sourceType Is GetType(String) Then Return True Else Return MyBase.CanConvertFrom(context, sourceType) End If End Function '' Public Overloads Overrides Function CanConvertTo(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal destinationType As System.Type) As Boolean If destinationType Is GetType(InstanceDescriptor) Or destinationType Is GetType(String) Then Return True End If Return MyBase.CanConvertTo(context, destinationType) End Function '' Public Overloads Overrides Function ConvertFrom(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal culture As System.Globalization.CultureInfo, ByVal value As Object) As Object ''' Dim __Value As String Try__Value = value
If Not (__Value Is Nothing) Then__Value = __Value.Trim()
If __Value.Length <> 0 Then If culture Is Nothing Then culture = CultureInfo.CurrentCulture Dim params As String() = __Value.Split(",") Dim Start_Color As Color Dim End_Color As Color Dim Gradiant_Style As Drawing2D.LinearGradientMode Dim Line_Color As Color Dim Line_dashStyle As Drawing2D.DashStyle Dim Line_Gradiant As Boolean Dim Line_Style As Windows.Forms.Border3DStyle Dim Line_Width As Short '''Line_Width = params(0)
Line_Color = ColorTranslator.FromHtml(params(1))
Line_Gradiant = params(2)
Line_dashStyle = params(3)
Line_Style = params(4)
Start_Color = ColorTranslator.FromHtml(params(5))
End_Color = ColorTranslator.FromHtml(params(6))
Gradiant_Style = params(7)
Return New LineProperties(Line_Width, Line_Color, Line_Gradiant, Line_dashStyle, Line_Style, Start_Color, End_Color, Gradiant_Style) Else Return MyBase.ConvertFrom(context, culture, value) End If End If Catch ex As Exception Throw New ArgumentException("Invalid string for conversion - " & __Value) End Try End Function '' Public Overloads Overrides Function ConvertTo(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal culture As System.Globalization.CultureInfo, ByVal value As Object, ByVal destinationType As System.Type) As Object ''' Dim __LineProperties As LineProperties Try__LineProperties = value
If destinationType Is GetType(InstanceDescriptor) Then Dim argTypes As System.Type() = New System.Type(7) {}argTypes(0) =
GetType(Short)argTypes(1) =
GetType(Color)argTypes(2) =
GetType(Boolean)argTypes(3) =
GetType(Drawing2D.DashStyle)argTypes(4) =
GetType(Windows.Forms.Border3DStyle)argTypes(5) =
GetType(Color)argTypes(6) =
GetType(Color)argTypes(7) =
GetType(Drawing2D.LinearGradientMode) Dim constructor As ConstructorInfo = GetType(LineProperties).GetConstructor(argTypes) Dim arguments As Object() = New Object(7) {}arguments(0) = __LineProperties.BorderWidth
arguments(1) = __LineProperties.BorderColor
arguments(2) = __LineProperties.LineGradiant
arguments(3) = __LineProperties.LineDashStyle
arguments(4) = __LineProperties.BorderStyle
arguments(5) = __LineProperties.StartColor
arguments(6) = __LineProperties.EndColor
arguments(7) = __LineProperties.GradiantStyle
Return New InstanceDescriptor(constructor, arguments) ElseIf (destinationType Is GetType(String)) Then If (culture Is Nothing) Then culture = CultureInfo.CurrentCulture Dim Params(7) As StringParams(0) = __LineProperties.BorderWidth
Params(1) = ColorTranslator.ToHtml(__LineProperties.BorderColor)
Params(2) = __LineProperties.LineGradiant
Params(3) = __LineProperties.LineDashStyle
Params(4) = __LineProperties.BorderStyle
Params(5) = ColorTranslator.ToHtml(__LineProperties.StartColor)
Params(6) = ColorTranslator.ToHtml(__LineProperties.EndColor)
Params(7) = __LineProperties.GradiantStyle
Return Join(Params, ",") Else Return MyBase.ConvertTo(context, culture, value, destinationType) End If Catch ex As ExceptionMsgBox(ex.ToString)
Throw New ArgumentException End Try End Function '''#
End Region '''End
Class'''
#
End Region'''
#
End Region'''