vb点虐 鼠标画圆 vbcircle画圆
在VB.Net中如何画实心的圆
在游罩拦PictureBox1上神胡画红色的实闷首心圆:
成都创新互联专注于企业营销型网站建设、网站重做改版、克州网站定制设计、自适应品牌网站建设、H5技术、商城网站制作、集团公司官网建设、成都外贸网站制作、高端网站制作、响应式网页设计等建站业务,价格优惠性价比高,为克州等各大城市提供网站开发制作服务。
Private Sub DrawCircle(ByVal cp As Point, ByVal radius As Integer, ByVal color As Brush)
Dim gr As Graphics
gr = PictureBox1.CreateGraphics
Dim rect As Rectangle = New Rectangle(cp.X - radius, cp.Y - radius, 2 * radius, 2 * radius)
gr.DrawEllipse(Pens.Black, rect)
gr.FillEllipse(color, rect)
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
DrawCircle(New Point(120, 100), 80, Brushes.Red)
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点虐 中绘制圆的代码是什么?
Dim myGraphics As Graphics = Me.CreateGraphics '声明并创建一个Graphics对象
Dim myPen As Pen = New Pen(Drawing.Color.Black, 3) '声明一个画笔,并设定颜色和粗细
myPen.DashStyle = Drawing.Drawing2D.DashStyle.Solid '线型,Solid是实线
myGraphics.DrawEllipse(myPen, 200, 200, 100, 100) '画圆,数值依次是:横坐标孝源、纵坐标巧配态、宽度和高度(宽高卖缺相同为正圆,否则为椭圆)
myGraphics.Dispose() '释放Graphics占用的资源
怎样用VB实现:用鼠标拖动绘制实圆与多种虚线圆
Dim
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点虐 鼠标画圆 vbcircle画圆
转载来于:http://cdiso.cn/article/ddpsisd.html