English 中文(简体)
1. 财产收集的飞行
原标题:Serialization with collection property
  • 时间:2011-11-16 18:00:33
  •  标签:
  • vb.net

奥基文如此撰写的控制权是多个触摸屏纽顿的东道主。 这种控制是通过操纵带有属性特征的收集财产来实现的。 现在,在设计者制造的初始责任(子)项中,这些纽芬兰语集了出来。 然而,每当我删除主要控制时(由纽芬兰人担任主控制),设计师便会取消初始责任国的纽芬兰语的序列化法,但甚至更糟。 如果我用一种表格复制主要控制,将其复制成另一种形式,则纽埃州就被复制。

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
最佳回答

我找到了解决这一问题的办法。 我必须做的是处置控制,以删除这些控制,并利用控制人员部分将儿童控制与主要控制联系起来。

问题回答

暂无回答




相关问题
Is Shared ReadOnly lazyloaded?

I was wondering when I write Shared ReadOnly Variable As DataType = New DataType() Or alternatively Shared ReadOnly Variable As New DataType() Is it lazy loaded or as the instance initializes? ...

Entertaining a baby with VB.NET

I would like to write a little application in VB.NET that will detect a baby s cry. How would I get started with such an application?

Choose Enter Rather than Pressing Ok button

I have many fields in the page and the last field is a dropdown with list of values. When I select an item in a dropdown and press Enter, it doesn t do the "Ok". Instead I have to manually click on Ok ...

ALT Key Shortcuts Hidden

I am using VS2008 and creating forms. By default, the underscore of the character in a textbox when using an ampersand is not shown when I run the application. ex. "&Goto Here" is not ...

Set Select command in code

On button Click I want to Set the Select command of a Gridview. I do this and then databind the grid but it doesn t work. What am i doing wrong? protected void bttnView_Click(object sender, ...

Hover tooltip on specific words in rich text box?

I m trying to create something like a tooltip suddenly hoovering over the mouse pointer when specific words in the richt text box is hovered over. How can this be done?

热门标签