使用Line 方法
創(chuàng)新互聯(lián)公司是一家專注于成都網(wǎng)站設(shè)計、成都做網(wǎng)站與策劃設(shè)計,扎魯特旗網(wǎng)站建設(shè)哪家好?創(chuàng)新互聯(lián)公司做網(wǎng)站,專注于網(wǎng)站建設(shè)10多年,網(wǎng)設(shè)計領(lǐng)域的專業(yè)建站公司;建站業(yè)務涵蓋:扎魯特旗等地區(qū)。扎魯特旗做網(wǎng)站價格咨詢:18980820575
在對象上畫直線和矩形。
語法
object.Line [Step] (x1, 1) [Step] (x2, y2), [color], [B][F]
Line 方法的語法有以下對象限定符和部分:
部分 描述
object 可選的。 對象表達式,其值為“應用于”列表中的對象。如果object 省略,具有焦點的窗體作為object。
Step 可選的。關(guān)鍵字,指定起點坐標,它們相對于由 CurrentX 和 CurrentY 屬性提供的當前圖形位置。
(x1, y1) 可選的。Single (單精度浮點數(shù)),直線或矩形的起點坐標。ScaleMode 屬性決定了使用的度量單位。如果省略,線起始于由 CurrentX 和 CurrentY 指示的位置。
Step 可選的。關(guān)鍵字,指定相對于線的起點的終點坐標。
(x2, y2) 必需的。Single (單精度浮點數(shù)),直線或矩形的終點坐標。
color 可選的。Long (長整型數(shù)),畫線時用的 RGB 顏色。如果它被省略,則使用 ForeColor 屬性值。可用 RGB 函數(shù)或 QBColor 函數(shù)指定顏色。
B 可選的。如果包括,則利用對角坐標畫出矩形。
F 可選的。如果使用了 B 選項,則 F 選項規(guī)定矩形以矩形邊框的顏色填充。不能不用 B 而用 F。如果不用 F 光用 B,則矩形用當前的 FillColor 和 FillStyle 填充。FillStyle 的缺省值為 transparent。
例:
Private Sub Form_Load()
Me.AutoRedraw = True
Line (100, 100)-(2100, 2100), vbBlue, BF
End Sub
Picture1.Line?(oldx,?oldy)-(oldx,?Y)
Picture1.Line?(oldx,?oldy)-(X,?oldy)
Picture1.Line?(oldx,?Y)-(X,?Y)
Picture1.Line?(X,?oldy)-(X,?Y)
這個是vb6.0畫長方形的代碼,可以供你參考下
Dim canvas As New ShapeContainer
' To draw anoval, substitute
' OvalShapefor RectangleShape.
DimtheShape As NewRectangleShape
' Set theform as the parent of the ShapeContainer.
canvas.Parent = Me
' Set theShapeContainer as the parent of the Shape.
theShape.Parent = canvas
' Set thesize of the shape.
theShape.Size = New System.Drawing.Size(200,300)
' Set thelocation of the shape.
theShape.Location = New System.Drawing.Point(100,100)
' To draw arounded rectangle, add the following code:
theShape.CornerRadius = 12
theShape.FillStyle = FillStyle.Solid
theShape.FillColor = Color.Red
這個類繼承自Panel,把它加到你的項目里面,先運行一下,然后從工具箱里把它拖到窗體上,然后再向里面添加其它控件就可以了,支持Shift加選,Alt減選
Imports?System.Linq
Imports?System.Collections
Public?Class?MyPanel
Inherits?Panel
'?選擇模式,相交還是包含
Enum?SelectMode
Intersects
Contains
End?Enum
Dim?down?As?New?Point(-1,?-1)
Dim?rect?As?Rectangle
Dim?selected?As?New?List(Of?Control)
Dim?editting?As?IEnumerable(Of?Control)
Dim?mode?As?SelectMode?=?SelectMode.Contains
Dim?shift,?alt?As?Boolean
Public?Sub?New()
Me.DoubleBuffered?=?True
End?Sub
Protected?Overrides?Sub?OnMouseDown(e?As?MouseEventArgs)
MyBase.OnMouseDown(e)
down?=?e.Location
editting?=?selected.ToArray().ToList()
OnMouseMove(e)
End?Sub
Protected?Overrides?Sub?OnMouseMove(e?As?MouseEventArgs)
MyBase.OnMouseMove(e)
If?e.Button?=?Windows.Forms.MouseButtons.Left?Then
Dim?loc?As?New?Point(Math.Min(down.X,?e.X),?Math.Min(down.Y,?e.Y))
Dim?size?As?New?Size(Math.Abs(down.X?-?e.X),?Math.Abs(down.Y?-?e.Y))
rect?=?New?Rectangle(loc,?size)
Dim?cs?As?New?List(Of?Control)
For?Each?c?In?Controls
cs.Add(c)
Next
Dim?a?=?cs.Where(Function(n?As?Control)?(mode?=?SelectMode.Contains?And?rect.Contains(n.Bounds))?Or?(mode?=?SelectMode.Intersects?And?rect.IntersectsWith(n.Bounds)))
If?shift?Then?editting?=?a.Union(selected)?Else?If?alt?Then?editting?=?selected.Except(a)?Else?editting?=?a
Invalidate()
End?If
End?Sub
Protected?Overrides?Sub?OnMouseUp(e?As?MouseEventArgs)
MyBase.OnMouseUp(e)
down?=?New?Point(-1,?-1)
selected?=?editting.ToList()
editting?=?Nothing
Invalidate()
End?Sub
Protected?Overrides?Function?ProcessKeyPreview(ByRef?m?As?Message)?As?Boolean
Dim?KeyCode?As?Keys?=?CInt(m.WParam)?And?CInt(Keys.KeyCode)
Dim?d?As?Boolean
If?m.Msg?=?H100?Or?m.Msg?=?H104?Then?d?=?True?Else?If?m.Msg?=?H101?Or?m.Msg?=?H105?Then?d?=?False?Else?Return?MyBase.ProcessKeyPreview(m)
If?KeyCode?=?Keys.ShiftKey?Then
shift?=?d
ElseIf?KeyCode?=?Keys.Menu?Then
alt?=?d
End?If
Return?MyBase.ProcessKeyPreview(m)
End?Function
Protected?Overrides?Sub?OnPaint(e?As?PaintEventArgs)
MyBase.OnPaint(e)
For?Each?c?As?Control?In?IIf(editting?Is?Nothing,?selected,?editting)
e.Graphics.DrawRectangle(New?Pen(Color.Gray)?With?{.DashStyle?=?Drawing2D.DashStyle.DashDot},?c.Left?-?1,?c.Top?-?1,?c.Width?+?1,?c.Height?+?1)
Next
If?(down.X??0)?Then?e.Graphics.DrawRectangle(New?Pen(Color.Gray)?With?{.DashStyle?=?Drawing2D.DashStyle.DashDot},?rect)
End?Sub
End?Class
g?=?Me.picDisplay.CreateGraphics
Dim?mybrush?As?Brush?=?New?SolidBrush(Map_Empty_Color)
Dim?rect2?As?System.Drawing.Rectangle?=?New?System.Drawing.Rectangle(0,?0,?Map_Width,?Map_Height)
g.FillRectangle(mybrush,?rect2)