vb.net让鼠标画圆,用vb画圆
怎样用VB实现:用鼠标拖动绘制实圆与多种虚线圆
Dim
创新互联专注于企业成都全网营销推广、网站重做改版、福安网站定制设计、自适应品牌网站建设、H5网站设计、商城网站制作、集团公司官网建设、成都外贸网站建设、高端网站制作、响应式网页设计等建站业务,价格优惠性价比高,为福安等各大城市提供网站开发制作服务。
s
As
Boolean,
ci
As
Integer,
xianxing
As
Integer,
xiankuan
As
Integer
Dim
x0
As
Single,
y0
As
Single
Private
Sub
Command1_Click()
s
=
True
Command1.Enabled
=
False
End
Sub
Private
Sub
Form_Load()
Dim
b
b
=
Array("透明",
"实线",
"虚线",
"点线",
"点划线",
"双点划线")
Frame1.Move
100,
100,
1300,
3500
Frame1.Caption
=
"线型"
Frame2.Move
Width
-
1500,
100,
1300,
3500
Frame2.Caption
=
"线宽"
For
i
=
To
5
Option1(i).Move
100,
300
+
i
*
500,
1100,
300
Option1(i).Caption
=
b(i)
Option2(i).Move
100,
500
+
i
*
500,
800,
300
Option2(i).Caption
=
i
+
1
"点宽"
Next
i
Shape1(0).Visible
=
False
Shape1(1).Visible
=
False
s
=
ci
=
-1
Command1.Caption
=
"开始画圆"
Command1.ToolTipText
=
"点击按钮后在窗体内按下鼠标左键处为圆心,拖到半径处松开鼠标左键即可"
End
Sub
Private
Sub
Form_MouseDown(Button
As
Integer,
Shift
As
Integer,
X
As
Single,
Y
As
Single)
If
s
And
Button
=
1
Then
x0
=
X
y0
=
Y
ci
=
ci
+
1
If
ci
1
Then
Load
Shape1(ci)
Shape1(ci).Visible
=
True
Shape1(ci).BorderStyle
=
xianxing
Shape1(ci).Move
x0,
y0,
0,
Shape1(ci).Shape
=
3
Shape1(ci).BorderWidth
=
xiankuan
End
If
End
Sub
Private
Sub
Form_MouseMove(Button
As
Integer,
Shift
As
Integer,
X
As
Single,
Y
As
Single)
If
s
And
Button
=
1
Then
banjing
=
Sqr((x0
-
X)
*
(x0
-
X)
+
(y0
-
Y)
*
(y0
-
Y))
Shape1(ci).Move
x0
-
banjing,
y0
-
banjing,
2
*
banjing,
2
*
banjing
End
If
End
Sub
Private
Sub
Form_MouseUp(Button
As
Integer,
Shift
As
Integer,
X
As
Single,
Y
As
Single)
Command1.Enabled
=
True
s
=
False
End
Sub
Private
Sub
Option1_Click(Index
As
Integer)
For
i
=
To
5
If
Option1(i)
Then
xianxing
=
i
Next
i
If
i
=
1
Then
Frame2.Enabled
=
True
Else
Frame2.Enabled
=
False
xiankuan
=
1
End
If
End
Sub
Private
Sub
Option2_Click(Index
As
Integer)
For
i
=
To
5
If
Option2(i)
Then
xiankuan
=
1
+
i
Next
i
End
Sub
界面稍微复杂了点:
一个按钮,两个框架,第一框架上option1共六个,第二个框架上option2也是六个。
VB编程 鼠标画圆
创建一个工程,界面上放一个PictureBox控件,控件名字叫Picture1,然后把下面的代码复制到工程中,运行查看效果。
Option Explicit
Private Type POINTAPI
x As Long
y As Long
End Type
Private Declare Function Ellipse Lib "gdi32" (ByVal hdc As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private DrawEllipse As Boolean
Private dwPoint(1) As POINTAPI
Private Sub Form_Load()
Picture1.ScaleMode = vbPixels
Picture1.AutoRedraw = True
End Sub
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
If Button = vbLeftButton Then
DrawEllipse = True
dwPoint(0).x = CLng(x)
dwPoint(0).y = CLng(y)
End If
End Sub
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
If DrawEllipse = True Then
dwPoint(1).x = CLng(x)
dwPoint(1).y = CLng(y)
Picture1.Cls
Ellipse Picture1.hdc, dwPoint(0).x, dwPoint(0).y, dwPoint(1).x, dwPoint(1).y
Picture1.Refresh
End If
End Sub
Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
If Button = vbLeftButton Then
DrawEllipse = False
End If
End Sub
如何用VB.NET画同心圆
窗体上添加一个按钮,在该按钮的单击事件里编写代码如下:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'声明窗体的Me.CreateGraphics对象
Dim MyGraphics As Graphics = Me.CreateGraphics
Dim Cx As Integer = 150 '圆心的X坐标
Dim Cy As Integer = 150 '圆心的Y坐标
Dim R As Integer '圆的半径
'绘制半径为R的圆
For R = 5 To 100 Step 5
MyGraphics.DrawEllipse(Pens.Black, New Rectangle(Cx - R, Cy - R, 2 * R, 2 * R))
Next
End Sub
‘用黑色画笔绘制一组同心圆,半径从5开始,增量为5。
说明:
DrawEllipse是VB.Net的Graphics类的绘制椭圆的方法;他有几种格式,上面使用的是一种;
DrawEllipse(画笔的颜色,绘制椭圆所需要的矩形区域)
其中:绘制椭圆所需要的矩形区域,如果被定义为正方形,就演变成绘制圆,定义该区域由死个数值确定,第1个数值,确定该区域左上角的X坐标,第2个数值,确定该区域左上角的Y坐标,第3个数值,确定该区域的宽度,第4个数值,确定该区域的高度。
例如1:
DrawEllipse(Pens.Black, New Rectangle(150, 150, 50, 50))
就是以圆心坐标为(100,100),绘制半径为50 的圆。其实在VB.NET中,是告诉系统在以左上角坐标(150,150),边长为50的正方形里绘制内切圆。理解了是在正方形里绘制内切圆,就可以通过数学计算,知道如何绘制了。
同理例如2:
DrawEllipse(Pens.Black, New Rectangle(150, 150, 100, 50))
就是以圆心坐标为(100,100),绘制半径为50 的圆。其实在VB.NET中,是告诉系统在以左上角坐标(150,150),长轴为100,短轴为50的内切椭圆。
VB.NET中怎样画圆弧
用Circle 画圆 圆弧 椭圆 都 具体参照面详细说明 Circle(一000,一000),500,吧,-陆,-三 一000,一000,圆坐标 500,半径 面别代表起始角,终止角,短轴比率 吧,详细点,Circle都说遍 象画圆、椭圆或弧 语 object.Circle [Step] (x, y), radius, [color, start, end, aspect] Circle 语象限定符部: 部 描述 object 选 象表达式其值应用于列表象object 省略具焦点窗体作object Step 选关键字 指定圆、椭圆或弧相于前 object CurrentX CurrentY 属性提供坐标 (x, y) 必需 Single (单精度浮点数)圆、椭圆或弧坐标object ScaleMode 属性决定使用度量单位 radius 必需Single (单精度浮点数)圆、椭圆或弧半径 object ScaleMode 属性决定使用度量单位 color 选Long (整型数)圆轮廓 RGB 颜色省略则使用 ForeColor 属性值用 RGB 函数或 QBColor 函数指定颜色 start, end 选 Single (单精度浮点数)弧、或部圆或椭圆画完start end 指定(弧度单位)弧起点终点位置其范围 -二 pi 二 pi 起点缺省值0; 终点缺省值二 * pi aspect 选 Single (单精度浮点数)圆纵横尺寸比缺省值 一.0何屏幕都产标准圆(非椭圆) 说明 想要填充圆使用圆或椭圆所属象 FillColor FillStyle 属性封闭图形才能填充封闭图形包括圆、椭圆、或扇形 画部圆或椭圆 start 负Circle 画半径 start并角度处理; end 负Circle 画半径 end并角度处理Circle 总逆针()向绘图 画圆、椭圆或弧线段粗细取决于 DrawWidth 属性值背景画圆取决于 DrawMode DrawStyle 属性值 画角度 0 扇形要画条半径(向右画水平线段)给 start 规定负值要给 0 .省略语间某参数能省略隔参数逗号您指定参数面逗号省略 Circle 执行CurrentX CurrentY 属性参数设置点 能用 With匛nd With 语句块 -------------------------------------------------------------------------------- Circle 示例 示例用Circle 窗体央画许同圆要运行示例代码放入窗体 General 部按 F5 并单击窗体 Sub Form_Click () Dim CX, CY, Radius, Limit ' Declare variable. ScaleMode = 三 ' 像素单位 CX = ScaleWidth / 二 ' X 位置 CY = ScaleHeight / 二 ' Y 位置 If CX CY Then Limit = CY Else Limit = CX For Radius = 0 To Limit ' 半径 Circle (CX, CY), Radius,RGB(Rnd * 二55, Rnd * 二55, Rnd * 二55) Next Radius End Sub -------------------------------------------------------------------------------
文章标题:vb.net让鼠标画圆,用vb画圆
分享网址:http://pwwzsj.com/article/dssspei.html