提供一个绘制任意曲线的简单代码。其他功能类似,希望能举一反三。
在窗体中添加一个Picture box,然后输入命令如下:
Dim oldx As SingleDim oldy As Single
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then '当鼠标左建按下时发生
Picture1.Line (oldx, oldy)-(X, Y)
oldx = X
oldy = Y
End If
End Sub
Private Sub Picture1_Mousedown(Button As Integer, Shift As Integer, X As Single, Y As Single)
oldx = X
oldy = Y
End Sub
Line 方法请参阅 范例 适用于
在一个对象上画线条和长方形;无法使用指名自变量。
语法
object.Line Step (x1, y1) - Step (x2, y2), color, BF
Line 方法的语法有下列这些部分:
单元 说明
object 可选择的。对象表达式,指定位于「适用于」清单中的对象。若是 object 被省略,则含有驻点 的 Form 会被假设成为 object 。
Step 可选择的。关键词 ,用来指定起点的坐标,而坐标相关于由 CurrentX 和 CurrentY 属性所给定的目前图形位置。
(x1, y1) 可选择的。是单精密度的值,用来指出线条或长方形起点的坐标。 ScaleMode 属性决定了测量时所使用的单位。若它被省略,则线条由 CurrentX 和 CurrentY 所指定的位置开始。
Step 可选择的。它是一个关键词,指定相关于线条起点位置的终点坐标。
(x2, y2) 必需要的。是单精密度的值,它们表示目前要画线条的终点坐标。
color 可选择的。它是长整数值,表示用来画线条的 RGB
颜色。如果它被省略,则使用 ForeColor 属性的值。您也可以使用 RGB 函数或是 QBColor 函数来指定此颜色。
B 可选择的。若它被包含进来,则绘出坐标所指定对角的方块。
F 可选择的。若 B 选项被使用,则 F 选项会指定此方块的内部与外框将使用相同颜色填满。您不能只使用 F 而不使用 B。如果使用 B 而不使用 F ,则此方块以目前的 FillColor 和 FillStyle 来填满。 FillStyle 的默认值是透明的。
请注意
为了画出连续的线条,随后的线条要开始于上一线条的终点。
画出线条的宽度是依照 DrawWidth 属性的设定。在背景画线条或方块的方法是根据 DrawMode 和 DrawStyle 属性的设定。
当 Line 执行时, CurrentX 和 CurrentY 属性会被设定成由自变量所设定的终点。
VB.net与VB不同。VB.net已经有专门绘图的类。
可以定义笔刷然后用Drawing类中的方法绘制。
Private Sub DrawEllipse()
Dim myPen As New System.Drawing.Pen(System.Drawing.Color.Red)
Dim formGraphics as System.Drawing.Graphics
formGraphics = Me.CreateGraphics()
formGraphics.DrawEllipse(myPen, New Rectangle(0,0,200,300))
myPen.Dispose()
formGraphics.Dispose()
End Sub
Private Sub DrawRectangle()
Dim myPen As New System.Drawing.Pen(System.Drawing.Color.Red)
Dim formGraphics as System.Drawing.Graphics
formGraphics = Me.CreateGraphics()
formGraphics.DrawRectangle(myPen, New Rectangle(0,0,200,300))
myPen.Dispose()
formGraphics.Dispose()
End Sub
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)