首页 > 解决方案 > 我需要以编程方式创建用户可以移动的标签。然后我需要能够捕获该新位置的 X 和 Y

问题描述

我有一个 VB.net windows 窗体应用程序,它将用于用户(我们的内部人员)为特定客户的需求定制某些可变数据字段的位置。每种产品类型都有某些可供使用的字段,并且它们的所有默认信息都存在于表中。

When a certain product is selected I can make sample data appear as labels with a tooltip letting them know the name of the field. 所有这些都有效。

我遇到的问题是在加载默认值后使标签可移动。

我找到了允许移动开发时制作的标签的代码示例,但没有任何代码允许动态制作的标签可移动。

第二部分是能够从移动的字段中检索新的 X 和 y 坐标,以便为该客户制作记录。

这是创建标签的子程序。它是从一个循环内部调用的,该循环遍历可用的字段数据。注意:这些字段出现在面板中,其背景将是一张图像,用于了解可以放置数据的位置。

   Private Sub lblCreateLabel_Click(ByVal RecCount As Integer, ByVal FieldType As String, ByVal FieldName As String, ByVal FieldData As String, ByVal FieldWidth As Integer, ByVal FieldJustification As String, ByVal xpos As Integer, ByVal ypos As Integer, ByVal Color As String, ByVal Side As String, ByVal Font As String, ByVal FontSize As String, ByVal FontStyle As String, ByVal SetType As String)

        Dim label1 As New Label
        Dim intHorizontalAlignment As Integer = 0
        Dim intFontStyle As FontStyle = Drawing.FontStyle.Regular

        Select Case FieldJustification
            Case "Center"
                intHorizontalAlignment = 32
            Case "Left"
                intHorizontalAlignment = 16
            Case "Right"
                intHorizontalAlignment = 64
            Case Else
                intHorizontalAlignment = 16
        End Select

        Select Case FontStyle
            Case "Reg"
                intFontStyle = Drawing.FontStyle.Regular
            Case "Bold"
                intFontStyle = Drawing.FontStyle.Bold
            Case "Italic"
                intFontStyle = Drawing.FontStyle.Italic
            Case Else
                intFontStyle = Drawing.FontStyle.Regular
        End Select

        label1.Name = "txt" & RecCount
        label1.Text = FieldData.Replace("&", "&&")
        label1.Width = FieldWidth
        label1.ForeColor = System.Drawing.Color.FromName(Color.Replace("Color[", "").Replace("]", ""))
        label1.Location = New Point(xpos, ypos)
        Dim tt As New ToolTip()
        tt.SetToolTip(label1, FieldName)

        If FieldType = "Address" Or FieldType = "Slug" Or FieldType = "ChurchName" Then
            label1.AutoSize = True
        Else
            label1.AutoSize = False
        End If

        If FieldName.Contains("811PlaceStamp") Then
            label1.AutoSize = True
        End If

        If FieldType = "Barcode" Then
            label1.Height = 30
            label1.BackColor = Drawing.Color.Transparent
        Else
            label1.BackColor = Drawing.Color.Transparent
        End If

        label1.TextAlign = intHorizontalAlignment

        Try
            label1.Font = New Font(Font, CInt(FontSize), intFontStyle)
        Catch
        End Try

        If Side = "Face" Then
            pnlEnvelopeFace.Controls.Add(label1)
            label1.Refresh()
        Else
            pnlEnvelopeFlap.Controls.Add(label1)
            label1.Refresh()
        End If

    End Sub```

Any guidance would be very much appreciated.

标签: vb.netlabelmovable

解决方案


推荐阅读