奥基文如此撰写的控制权是多个触摸屏纽顿的东道主。 这种控制是通过操纵带有属性特征的收集财产来实现的。 现在,在设计者制造的初始责任(子)项中,这些纽芬兰语集了出来。 然而,每当我删除主要控制时(由纽芬兰人担任主控制),设计师便会取消初始责任国的纽芬兰语的序列化法,但甚至更糟。 如果我用一种表格复制主要控制,将其复制成另一种形式,则纽埃州就被复制。
The Code for the ButtonRow Object:
Public Class ButtonRow
Inherits Control
Private WithEvents g_colTouchKeys As New TouchScreenButtonCollection
Private g_iMargin As Integer = 0
Public Sub New()
MyBase.DoubleBuffered = True
End Sub
<DefaultValue(0I)> _
Public Property ButtonMargin() As Integer
Get
Return g_iMargin
End Get
Set(ByVal value As Integer)
g_iMargin = value
End Set
End Property
<DesignerSerializationVisibility(DesignerSerializationVisibility.Content), _ Editor(GetType(ButtonCollectionEditor), GetType(UITypeEditor))> _
Public ReadOnly Property Keys() As TouchScreenButtonCollection
Get
Return g_colTouchKeys
End Get
End Property
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
MyBase.OnPaint(e)
If MyBase.DesignMode Then
ArrangeButtons()
RenderButtons(e.Graphics)
Else
SetupButtons()
End If
End Sub
Private Sub ArrangeButtons()
Dim icl As Integer = 0
For Each B As TouchScreenKey In g_colTouchKeys
B.Top = 0
B.Left = icl
icl += g_iMargin + B.Width
Next
End Sub
Private Sub AddButtonToControlSurface()
For Each B As TouchScreenKey In g_colTouchKeys
If HasControl(B) = False Then MyBase.Controls.Add(B)
Next
End Sub
Private Sub RemoveControlsNotInCollection()
For Each C As Control In MyBase.Controls
If TypeOf C Is TouchScreenKey Then
If ButtonInCollection(DirectCast(C, TouchScreenKey)) = False Then
MyBase.Controls.Remove(C)
End If
End If
Next
End Sub
Private Function ButtonInCollection(ByVal B As TouchScreenKey) As Boolean
For Each BT As TouchScreenKey In g_colTouchKeys
If BT Is B Then Return True
Next
Return False
End Function
Private Function HasControl(ByVal C As Control) As Boolean
For Each Ct As Control In MyBase.Controls
If C Is Ct Then Return True
Next
Return False
End Function
Private Function CreateDefaultControl() As TouchScreenKey
Dim t As New TouchScreenKey(0, "Default")
t.Left = 0
t.Top = 0
t.Size = New Size(70, 70)
Return t
End Function
Private Sub RenderButtons(ByVal g As Graphics)
For Each B As TouchScreenKey In g_colTouchKeys
Dim rect As Rectangle = New Rectangle(B.Left, B.Top, B.Width, B.Height)
B.PaintButton(g, rect)
Next
End Sub
Private Sub SetupButtons()
ArrangeButtons()
RemoveControlsNotInCollection()
AddButtonToControlSurface()
End Sub
End Class
在布特顿罗乌特(ButtonRow)反对并增加3个纽州之后,这是InitilizeComponent()程序的样本:
Private Sub InitializeComponent()
Me.ButtonRow1 = New TouchPadControls.ButtonRow
Me.TouchScreenKey1 = New TouchPadControls.TouchScreenKey
Me.TouchScreenKey2 = New TouchPadControls.TouchScreenKey
Me.TouchScreenKey3 = New TouchPadControls.TouchScreenKey
Me.SuspendLayout()
ButtonRow1
Me.ButtonRow1.Keys.AddRange(New TouchPadControls.TouchScreenKey() {Me.TouchScreenKey1, Me.TouchScreenKey2, Me.TouchScreenKey3})
Me.ButtonRow1.Location = New System.Drawing.Point(12, 12)
Me.ButtonRow1.Name = "ButtonRow1"
Me.ButtonRow1.Size = New System.Drawing.Size(321, 111)
Me.ButtonRow1.TabIndex = 0
Me.ButtonRow1.Text = "ButtonRow1"
TouchScreenKey1
Me.TouchScreenKey1.ButtonPressGenerates = ""
Me.TouchScreenKey1.Location = New System.Drawing.Point(0, 0)
Me.TouchScreenKey1.Name = "TouchScreenKey1"
Me.TouchScreenKey1.Size = New System.Drawing.Size(80, 80)
Me.TouchScreenKey1.TabIndex = 0
Me.TouchScreenKey1.Text = "TouchScreenKey1"
TouchScreenKey2
Me.TouchScreenKey2.ButtonPressGenerates = ""
Me.TouchScreenKey2.Location = New System.Drawing.Point(80, 0)
Me.TouchScreenKey2.Name = "TouchScreenKey2"
Me.TouchScreenKey2.Size = New System.Drawing.Size(80, 80)
Me.TouchScreenKey2.TabIndex = 0
Me.TouchScreenKey2.Text = "TouchScreenKey2"
TouchScreenKey3
Me.TouchScreenKey3.ButtonPressGenerates = ""
Me.TouchScreenKey3.Location = New System.Drawing.Point(160, 0)
Me.TouchScreenKey3.Name = "TouchScreenKey3"
Me.TouchScreenKey3.Size = New System.Drawing.Size(80, 80)
Me.TouchScreenKey3.TabIndex = 0
Me.TouchScreenKey3.Text = "TouchScreenKey3"
Form1
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(449, 305)
Me.Controls.Add(Me.ButtonRow1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub