📄 curvedlinetypes.vb
字号:
Imports System.Runtime.InteropServices
Imports System.ComponentModel
Imports System
Imports System.ComponentModel.Design
Imports Microsoft.Win32
Imports System.Diagnostics
Imports System.Drawing
Imports System.Drawing.Design
Imports System.Windows.Forms
Imports System.Windows.Forms.ComponentModel
Imports System.Windows.Forms.Design
Namespace Microsoft.Samples
<Editor("Microsoft.Samples.CurvedLineTypeEditor", GetType(UITypeEditor))> _
Public Enum CurvedLineTypes
LowerLeftQuarterCirle
LowerRightQuarterCircle
UpperLeftQuarterCirle
UpperRightQuarterCirle
End Enum
Public Class CurvedLineTypeEditor
Inherits UITypeEditor
Private lineTypeUI As CurvedLineTypeUI
Public Overloads Overrides Function EditValue(ByVal context As ITypeDescriptorContext, ByVal provider As IServiceProvider, ByVal value As Object) As Object
Dim returnValue As Object = value
If provider IsNot Nothing Then
Dim edSvc As IWindowsFormsEditorService = DirectCast(provider.GetService(GetType(IWindowsFormsEditorService)), IWindowsFormsEditorService)
If edSvc IsNot Nothing Then
If lineTypeUI Is Nothing Then
lineTypeUI = New CurvedLineTypeUI(Me)
End If
lineTypeUI.Start(edSvc, value)
edSvc.DropDownControl(lineTypeUI)
value = lineTypeUI.Value
lineTypeUI.[End]()
End If
End If
Return value
End Function
Public Overloads Overrides Function GetEditStyle(ByVal context As ITypeDescriptorContext) As UITypeEditorEditStyle
Return UITypeEditorEditStyle.DropDown
End Function
Private Class CurvedLineTypeUI
Inherits Control
Private edSvc As IWindowsFormsEditorService
Private editor As CurvedLineTypeEditor = Nothing
Private oldLineType As CurvedLineTypes
Private m_value As Object
Public Sub New(ByVal editor As CurvedLineTypeEditor)
Me.editor = editor
InitializeComponent()
End Sub
Public ReadOnly Property Value() As Object
Get
Return m_value
End Get
End Property
Public Sub [End]()
m_value = Nothing
edSvc = Nothing
End Sub
Public Sub Start(ByVal edSvc As IWindowsFormsEditorService, ByVal value As Object)
Me.edSvc = edSvc
Me.m_value = value
Me.oldLineType = DirectCast(value, CurvedLineTypes)
Dim panel As Panel
For Each c As Control In Controls
panel = TryCast(c, Panel)
If c IsNot Nothing Then
c.BackColor = SystemColors.Control
c.ForeColor = SystemColors.ControlText
End If
panel = Nothing
Next
Select Case DirectCast(value, CurvedLineTypes)
Case CurvedLineTypes.UpperLeftQuarterCirle
Me.upperLeftPanel.BackColor = SystemColors.ControlText
Me.upperLeftPanel.ForeColor = SystemColors.Control
Exit Select
Case CurvedLineTypes.UpperRightQuarterCirle
Me.upperRightPanel.BackColor = SystemColors.ControlText
Me.upperRightPanel.ForeColor = SystemColors.Control
Exit Select
Case CurvedLineTypes.LowerLeftQuarterCirle
Me.lowerLeftPanel.BackColor = SystemColors.ControlText
Me.lowerLeftPanel.ForeColor = SystemColors.Control
Exit Select
Case CurvedLineTypes.LowerRightQuarterCircle
Me.lowerRightPanel.BackColor = SystemColors.ControlText
Me.lowerRightPanel.ForeColor = SystemColors.Control
Exit Select
Case Else
Exit Select
End Select
End Sub
Private Sub Teardown(ByVal save As Boolean)
If Not save Then
m_value = oldLineType
End If
edSvc.CloseDropDown()
End Sub
#Region "Component Designer generated code"
Private upperLeftPanel As System.Windows.Forms.Panel
Private upperRightPanel As System.Windows.Forms.Panel
Private lowerLeftPanel As System.Windows.Forms.Panel
Private lowerRightPanel As System.Windows.Forms.Panel
Private upperLeftLine As Microsoft.Samples.CurvedLine
Private upperRightLine As Microsoft.Samples.CurvedLine
Private lowerLeftLine As Microsoft.Samples.CurvedLine
Private lowerRighttLine As Microsoft.Samples.CurvedLine
Friend Overridable Sub InitializeComponent()
Me.upperLeftPanel = New System.Windows.Forms.Panel()
Me.upperRightPanel = New System.Windows.Forms.Panel()
Me.lowerLeftPanel = New System.Windows.Forms.Panel()
Me.lowerRightPanel = New System.Windows.Forms.Panel()
Me.upperLeftLine = New Microsoft.Samples.CurvedLine()
Me.upperRightLine = New Microsoft.Samples.CurvedLine()
Me.lowerLeftLine = New Microsoft.Samples.CurvedLine()
Me.lowerRighttLine = New Microsoft.Samples.CurvedLine()
Me.upperLeftPanel.SuspendLayout()
Me.upperRightPanel.SuspendLayout()
Me.lowerLeftPanel.SuspendLayout()
Me.lowerRightPanel.SuspendLayout()
Me.SuspendLayout()
'
' upperLeftPanel
'
Me.upperLeftPanel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.upperLeftPanel.Controls.AddRange(New System.Windows.Forms.Control() {Me.upperLeftLine})
Me.upperLeftPanel.Location = New System.Drawing.Point(2, 2)
Me.upperLeftPanel.Name = "upperLeftPanel"
Me.upperLeftPanel.Size = New System.Drawing.Size(40, 40)
Me.upperLeftPanel.TabIndex = 0
'
' upperRightPanel
'
Me.upperRightPanel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.upperRightPanel.Controls.AddRange(New System.Windows.Forms.Control() {Me.upperRightLine})
Me.upperRightPanel.Location = New System.Drawing.Point(44, 2)
Me.upperRightPanel.Name = "upperRightPanel"
Me.upperRightPanel.Size = New System.Drawing.Size(40, 40)
Me.upperRightPanel.TabIndex = 1
'
' lowerLeftPanel
'
Me.lowerLeftPanel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.lowerLeftPanel.Controls.AddRange(New System.Windows.Forms.Control() {Me.lowerLeftLine})
Me.lowerLeftPanel.Location = New System.Drawing.Point(86, 2)
Me.lowerLeftPanel.Name = "lowerLeftPanel"
Me.lowerLeftPanel.Size = New System.Drawing.Size(40, 40)
Me.lowerLeftPanel.TabIndex = 2
'
' lowerRightPanel
'
Me.lowerRightPanel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.lowerRightPanel.Controls.AddRange(New System.Windows.Forms.Control() {Me.lowerRighttLine})
Me.lowerRightPanel.Location = New System.Drawing.Point(128, 2)
Me.lowerRightPanel.Name = "lowerRightPanel"
Me.lowerRightPanel.Size = New System.Drawing.Size(40, 40)
Me.lowerRightPanel.TabIndex = 3
'
' upperLeftLine
'
Me.upperLeftLine.Dock = System.Windows.Forms.DockStyle.Fill
Me.upperLeftLine.CurveType = Microsoft.Samples.CurvedLineTypes.UpperLeftQuarterCirle
Me.upperLeftLine.Name = "upperLeftLine"
Me.upperLeftLine.Size = New System.Drawing.Size(38, 38)
Me.upperLeftLine.TabIndex = 0
Me.upperLeftLine.Text = "CurvedLine1"
AddHandler Me.upperLeftLine.Click, AddressOf button_Click
'
' upperRightLine
'
Me.upperRightLine.Dock = System.Windows.Forms.DockStyle.Fill
Me.upperRightLine.CurveType = Microsoft.Samples.CurvedLineTypes.UpperRightQuarterCirle
Me.upperRightLine.Name = "upperRightLine"
Me.upperRightLine.Size = New System.Drawing.Size(38, 38)
Me.upperRightLine.TabIndex = 0
Me.upperRightLine.Text = "CurvedLine2"
AddHandler Me.upperRightLine.Click, AddressOf button_Click
'
' lowerLeftLine
'
Me.lowerLeftLine.Dock = System.Windows.Forms.DockStyle.Fill
Me.lowerLeftLine.CurveType = Microsoft.Samples.CurvedLineTypes.LowerLeftQuarterCirle
Me.lowerLeftLine.Name = "lowerLeftLine"
Me.lowerLeftLine.Size = New System.Drawing.Size(38, 38)
Me.lowerLeftLine.TabIndex = 0
Me.lowerLeftLine.Text = "CurvedLine3"
AddHandler Me.lowerLeftLine.Click, AddressOf button_Click
'
' lowerRighttLine
'
Me.lowerRighttLine.Dock = System.Windows.Forms.DockStyle.Fill
Me.lowerRighttLine.CurveType = Microsoft.Samples.CurvedLineTypes.LowerRightQuarterCircle
Me.lowerRighttLine.Name = "lowerRighttLine"
Me.lowerRighttLine.Size = New System.Drawing.Size(38, 38)
Me.lowerRighttLine.TabIndex = 0
Me.lowerRighttLine.Text = "CurvedLine4"
AddHandler Me.lowerRighttLine.Click, AddressOf button_Click
'
' UserControl1
'
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.lowerRightPanel, Me.lowerLeftPanel, Me.upperRightPanel, Me.upperLeftPanel})
Me.Name = "UserControl1"
Me.Size = New System.Drawing.Size(164, 44)
Me.BackColor = System.Drawing.SystemColors.InactiveBorder
Me.upperLeftPanel.ResumeLayout(False)
Me.upperRightPanel.ResumeLayout(False)
Me.lowerLeftPanel.ResumeLayout(False)
Me.lowerRightPanel.ResumeLayout(False)
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub button_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim line As CurvedLine = TryCast(sender, CurvedLine)
If line IsNot Nothing Then
Me.m_value = line.CurveType
Teardown(True)
End If
End Sub
End Class
End Class
End Namespace
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -