程序化标签的圆边

时间:2014-01-09 20:24:14

标签: vb.net

我正在尝试创建四边四角的标签,标签以编程方式创建,如下所示:

    Dim lbl1 As Label = New Label()
    lbl1.AutoSize = False 'allow resizing
    lbl1.BackColor = Color.Yellow
    lbl1.Text = newid
    lbl1.Height = 46
    lbl1.Width = 42
    lbl1.Padding = New Padding(1, 1, 1, 1)

如何从方角切换到更加XP风格的舍入。

1 个答案:

答案 0 :(得分:2)

Imports System.Runtime.InteropServices

<DllImport("Gdi32.dll", EntryPoint:="CreateRoundRectRgn")> _
        Private Shared Function CreateRoundRectRgn(ByVal iLeft As Integer, ByVal iTop As Integer, ByVal iRight As Integer, ByVal iBottom As Integer, ByVal iWidth As Integer, ByVal iHeight As Integer) As IntPtr
        End Function

ex。)

    Imports System.Runtime.InteropServices
Public Class Form1

    <DllImport("Gdi32.dll", EntryPoint:="CreateRoundRectRgn")> _
    Private Shared Function CreateRoundRectRgn(ByVal iLeft As Integer, ByVal iTop As Integer, ByVal iRight As Integer, ByVal iBottom As Integer, ByVal iWidth As Integer, ByVal iHeight As Integer) As IntPtr
    End Function

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim newid$ = "mylabel"
        Dim lbl1 As Label = New Label()
        With lbl1
            lbl1.AutoSize = False 'allow resizing
            lbl1.BackColor = Color.Yellow
            lbl1.Text = newid
            lbl1.Height = 46
            lbl1.Width = 42
            lbl1.Padding = New Padding(1, 1, 1, 1)
            lbl1.Region = System.Drawing.Region.FromHrgn(CreateRoundRectRgn(2, 2, lbl1.Width - 2, lbl1.Height - 2, 5, 1))
        End With
        Me.Controls.Add(lbl1)
    End Sub

End Class