如何在vb.net中动态创建多行标签

时间:2014-01-02 13:32:06

标签: vb.net

方案是我想根据string.say的大小动态填充标签数据,如果字符串长度为100,则必须在第一个标签中填充前30个字符,在下一个标签上填充剩余的30个字符,依此类推。

到目前为止我做了什么

Dim remcontent, remcontentlength, remcontentlabelcount, labelcounter As New Integer
                Dim rc As Integer = 30
                Dim remcontentstring As String
                remcontentlength = row.Item(4).ToString.Length
                Dim endindex As Integer = 30
                Dim startindex As Integer = 0


                If remcontentlength > 30 Then
                    Dim actualremcontent As String
                    actualremcontent = "Note :" + row.Item(4).ToString

                    Dim modcheck As Integer
                    modcheck = remcontentlength Mod 30
                    If modcheck = 0 Then
                        remcontentlabelcount = (remcontentlength / 30)
                    Else
                        remcontentlabelcount = (Math.Floor(remcontentlength \ 30)) + 1
                    End If
                   ReDim remindercontantmulti(remcontentlabelcount)
                    For labelcounter = 1 To remcontentlabelcount
                        remindercontantmulti(labelcounter) = New Label
                        With remindercontantmulti(labelcounter)
                            .Name = "remindercontant " + x.ToString + labelcounter.ToString
                            .Text = actualremcontent.ToString.Substring(startindex, endindex)
                            .Visible = True
                            .Top = (22 * (x + (aa + 1))) + 10
                            .AutoSize = True
                            '.Left = reminderTime(x).Left + reminderTime(x).Width + 20
                            .BackColor = Color.Transparent
                            '.BorderStyle = BorderStyle.FixedSingle
                            .TextAlign = ContentAlignment.MiddleRight
                            .Font = New Drawing.Font("Trebuchet MS", 8, FontStyle.Regular)
                            Me.Panel4.Controls.Add(remindercontantmulti(labelcounter))
                            aa = aa + 1
                        End With
                        If Not startindex = 0 Then
                            startindex = startindex + rc
                            If (rc * labelcounter) < remcontentlength Then
                                endindex = remcontentlength - startindex
                            End If
                        End If
                    Next labelcounter
                    Else
                    remindercontant(x) = New Label
                    With remindercontant(x)
                        .Name = "remindercontant " + x.ToString
                        .Text = "Note :" + row.Item(4).ToString
                        .Visible = True
                        .Top = (22 * (x + (aa + 1))) + 10
                        .AutoSize = True
                        '.Left = reminderTime(x).Left + reminderTime(x).Width + 20
                        .BackColor = Color.Transparent
                        '.BorderStyle = BorderStyle.FixedSingle
                        .TextAlign = ContentAlignment.MiddleRight
                        .Font = New Drawing.Font("Trebuchet MS", 8, FontStyle.Regular)
                        Me.Panel4.Controls.Add(remindercontant(x))
                        aa = aa + 1
                    End With
                End If

0 个答案:

没有答案