首页 > 解决方案 > 如何创建标签文本框,如 html 标签(在 ms 访问表单中)

问题描述

如何在 ms 访问表单中创建标签文本框?

像下面这样:

喜欢这张照片!!

标签: vbams-accesstags

解决方案


你可以使用一个类,像这样。它需要做一些工作,但这是我要开始的地方。不处于设计模式时无法添加控件,因此您期望的动态解决方案可能是不可能的。

一个类叫clsTagTextbox

Option Explicit

Private WithEvents tb As TextBox
Private lbl As Label
Private dicTags As Scripting.Dictionary

Public Function Initialise(tbTagTextBoxElement As TextBox, _
                            lblLabelForTags As Label)

    Set tb = tbTagTextBoxElement
    Set lbl = lblLabelForTags
    Set dicTags = New Scripting.Dictionary

End Function

Private Sub tb_Exit(Cancel As Integer)
    If Not dicTags.Exists(tb.Text) Then
        dicTags.Add tb.Text, dicTags.Count
        lbl.Caption = Join(dicTags.Keys(), ",")
    End If
    tb.Text = ""
End Sub

然后在你的表单中,你有一个标签和一个文本框,我的是txtTagBoxlblTags我有代码

Private c As clsTagTextbox

Private Sub Form_Load()
    Set c = New clsTagTextbox
    c.Initialise Me.txtTagBox, Me.lblTags
End Sub

推荐阅读