Public Sub BeautifyControls(ByVal e As WinForm.Form,ByVal _Values As String)
Dim Values() As String = _Values.Split(",")
For Index As Integer = 0 To Values.Length - 1
Dim BeautifyControl As New BeautifyControl(e.Controls(Values(Index)))
Next
End Sub
Public Class BeautifyControl
Private Control As WinForm.Control
Private Label As WinForm.Label
Public Sub New(ByVal _Control As WinForm.Control)
Dim lbl As WinForm.Label
lbl = _Control.Form.CreateControl("lable1", ControlTypeEnum.Label)
lbl.Name = "lable-" & _Control.Name
lbl.BackColor = Color.Transparent
lbl.TextAlign = ContentAlignment.MiddleLeft
_Control.Parent.AddControl(lbl)
lbl.AutoSize = False
lbl.SetBounds(_Control.Left, _Control.Top, _Control.Width, _Control.Height)
lbl.Anchor = _Control.Anchor
lbl.Dock = _Control.Dock
Me.Control = _Control
Me.Label = lbl
Me.Control.Visible = False
Dim ln As WinForm.Line = _Control.Form.CreateControl("lable1", ControlTypeEnum.Line)
ln.Anchor = _Control.Anchor
_Control.Parent.AddControl(ln)
ln.Left = _Control.Left
ln.Top = _Control.Top + _Control.Height - 16
ln.Width = _Control.Width
AddHandler lbl.BaseControl.Click, AddressOf Label_Click
AddHandler lbl.BaseControl.VisibleChanged, AddressOf Label_VisibleChanged
AddHandler Me.Control.BaseControl.Leave, AddressOf Control_Leave
End Sub
Private Sub Label_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Me.Control.Visible = True
Me.Control.Select()
Me.Control.Form.Controls(Control.Name).BaseControl.SelectionLength = 0
Me.Label.Visible = False
End Sub
Private Sub Label_VisibleChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
If Me.Label.Visible = True Then
If Me.Control.Form.ExistControl(Control.Name) Then
If Me.Control.BindingField = Nothing Then
Me.Label.Text = Me.Control.Form.Controls(Control.Name).Value
Else
Me.Label.BindingField = Me.Control.BindingField
End If
Me.Label.ForeColor = Me.Control.ForeColor
End If
End If
End Sub
'当文本控件不是活动控件的时候发生
Private Sub Control_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs)
Me.Label.Visible = True
Me.Control.Visible = False
End Sub
End Class