以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  这段代码麻烦改一下  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=103449)

--  作者:天蝉一下
--  发布时间:2017/7/8 16:44:00
--  这段代码麻烦改一下
这段代码我的目的是美化了一下文本框的显示,
   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
但是,我又不想把控件绑定到列上,这段代码如果我在文本框输入数据,离开控件的时候,录入的数据被隐藏了,怎么样改一下,让录入的数据显示出来,并且居中。

--  作者:有点蓝
--  发布时间:2017/7/8 16:55:00
--  
Private Sub Control_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.Label.Visible = True
        \'Me.Control.Visible = False \'去掉这句
    End Sub

--  作者:天蝉一下
--  发布时间:2017/7/8 17:01:00
--  
不行呀,第一次录入文本框数据,离开控件,录入的数据就被Me.Label遮住了,看不到数据,点击控件,数据才显示出来


--  作者:天蝉一下
--  发布时间:2017/7/8 17:03:00
--  
这是实例
 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:文本框控件处理.foxdb

而且录入的数据没有居中,怎么让它居中
[此贴子已经被作者于2017/7/8 17:03:25编辑过]

--  作者:有点蓝
--  发布时间:2017/7/8 17:17:00
--  

lbl.TextAlign = ContentAlignment.MiddleLeft

改为

lbl.TextAlign = ContentAlignment.MiddleCenter


Me.Label.Text = Me.Control.Form.Controls(Control.Name).Value

改为

Me.Label.Text = Me.Control.Form.Controls(Control.Name).Text

--  作者:天蝉一下
--  发布时间:2017/7/8 17:24:00
--  
非常感谢!周末愉快