Visual Basic 6.0 中的 Shape 控件在 Visual Basic 2005 中沒有等效項(xiàng)。但是可以使用
在 Visual Basic 6.0 中,Shape 控件提供了一種簡(jiǎn)單的方法,用于在設(shè)計(jì)時(shí)繪制矩形、圓和其他形狀。Shape 控件是一個(gè)“輕量級(jí)”控件,這意味著它沒有 Windows 句柄(也稱為 HWnd)。
在 Visual Basic 2005 中,沒有 Shape 控件的等效項(xiàng),也不再支持輕量級(jí)控件。但是也提供了在設(shè)計(jì)時(shí)和運(yùn)行時(shí)在窗體上繪制形狀的方法。
設(shè)計(jì)時(shí),可以通過添加
運(yùn)行時(shí),可以通過從 Graphics 類創(chuàng)建新對(duì)象并調(diào)用其方法,在窗體的
在 Visual Basic 6.0 中,可以通過向容器添加 Shape 控件,使用 Shape 控件在容器控件(例如 PictureBox 或 Frame 控件)上繪制形狀。
在 Visual Basic 2005 中,可以通過調(diào)用容器控件的 Paint
事件的 Graphics 方法實(shí)現(xiàn)相同效果。
下面的代碼示例演示 Visual Basic 6.0 和 Visual Basic 2005 在編碼方法上的不同之處。
下面的代碼演示如何在運(yùn)行時(shí)在窗體上繪制實(shí)心矩形。在 Visual Basic 6.0 示例中使用 Shape 控件;其中假定 Line 控件是在設(shè)計(jì)時(shí)添加的。Visual Basic 2005 示例演示兩種不同的方法,一種方法使用 Label 控件,另一種則使用 Graphics 方法。
![]() |
---|
在 Visual Basic 6.0 中,默認(rèn)度量單位是緹;在 Visual Basic 2005 中,默認(rèn)度量單位是像素。 |
![]() | |
---|---|
' Visual Basic 6.0 Private Sub Form_Load() ' Show a solid red rectangle 200 twips from the top left. Shape1.Top = 200 Shape1.Left = 200 Shape1.FillColor = vbRed Shape1.FillColor= vbFSSolid Shape1.BorderColor = vbRed End Sub |
Visual Basic | ![]() |
---|---|
' Visual Basic 2005 ' Using a Label control Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As _ System.EventArgs) Handles MyBase.Load Dim Shape1 As New System.Windows.Forms.Label ' Show a solid red rectangle 14 pixels from the top left. Shape1.Location = New System.Drawing.Point(14, 14) Shape1.Size = New System.Drawing.Size(200, 100) Shape1.BorderStyle = BorderStyle.None Shape1.BackColor = System.Drawing.Color.Red Shape1.Text = "" Controls.Add(Shape1) End Sub |
Visual Basic | ![]() |
---|---|
' Visual Basic 2005 ' Using Graphics methods Private Sub Form2_Paint(ByVal sender As Object, ByVal e As _ System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint ' Draw a solid blue rectangle below the red rectangle. e.Graphics.FillRectangle(Brushes.Blue, 14, 120, 200, 100) End Sub |
下面的代碼演示如何在運(yùn)行時(shí)在窗體上繪制圓。在 Visual Basic 6.0 示例中使用 Shape 控件;其中假定 Shape 控件是在設(shè)計(jì)時(shí)添加的。Visual Basic 2005 示例使用 Graphics 方法。
![]() |
---|
在 Visual Basic 6.0 中,默認(rèn)度量單位是緹;在 Visual Basic 2005 中,默認(rèn)度量單位是像素。 |
![]() | |
---|---|
' Visual Basic 6.0 Private Sub Form_Load() Draw a 1000 twip diameter red circle Shape1.Top = 0 Shape1.Left = 0 Shape1.Height = 1000 Shape1.Width = 1000 Shape1.Shape = vbShapeCircle Shape1.BorderColor = vbRed End Sub |
Visual Basic | ![]() |
---|---|
' Visual Basic 2005 Private Sub Form3_Paint(ByVal sender As Object, ByVal e As _ System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint ' Draw a 70 pixel diameter red circle. e.Graphics.DrawEllipse(Pens.Red, 0, 0, 70, 70) End Sub |
Visual Basic 6.0 應(yīng)用程序升級(jí)到 Visual Basic 2005 后,任何 Shape 控件將被替換為 Windows 窗體 Label 控件,并且將 BorderStyle 屬性設(shè)置為 FixedSingle,
![]() |
---|
可以采用與原始 Shape 控件不同的順序?qū)?Label 控件添加到窗體。對(duì)于重疊形狀,可能需要調(diào)用 |
Shape 屬性設(shè)置為“2-Oval”或“3-Circle”的 Shape 控件不能升級(jí),并由作為占位符的 Label 控件進(jìn)行替換??梢杂?.NET Framework 內(nèi)置的圖形函數(shù)替換 Shape 控件。有關(guān)更多信息,請(qǐng)參見圖形(針對(duì) Visual Basic 6.0 用戶)。
聯(lián)系客服