vb.net圆形 vb圆形控件

VB.net该如何将图片圆形显示?新建一个Winform,拖两个图片框 。图片框1在设计器中选择一个图片(尺寸在图片框容纳为佳) 。如下代码测试通过:
private void button1_Click(object sender, EventArgs e)
{
Image img1 = this.pictureBox1.Image;
Image img2 = CropToCircle(img1);
this.pictureBox2.Image = img2;
}
public Image CropToCircle(Image img1)
{
Image img2 = new Bitmap(img1.Width, img1.Height,
img1.PixelFormat);
Graphics g = Graphics.FromImage(img2);
using (Brush br =
new SolidBrush(SystemColors.Control))//背景色
{
g.FillRectangle(br, 0, 0,
【vb.net圆形 vb圆形控件】img2.Width, img2.Height);
}
GraphicsPath path = new GraphicsPath();
path.AddEllipse(0, 0, img2.Width, img2.Height);
g.SetClip(path);
g.DrawImage(img1, 0, 0);
return img2;
}
在VB.Net中如何画实心的圆在PictureBox1上画红色的实心圆:
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中绘制圆的代码是什么?Dim myGraphics As Graphics = Me.CreateGraphics '声明并创建一个Graphics对象
Dim myPen As Pen = New Pen(Drawing.Color.Black, 3) '声明一个画笔vb.net圆形,并设定颜色和粗细
myPen.DashStyle = Drawing.Drawing2D.DashStyle.Solid '线型vb.net圆形,Solid是实线
myGraphics.DrawEllipse(myPen, 200, 200, 100, 100) '画圆vb.net圆形 , 数值依次是vb.net圆形:横坐标、纵坐标、宽度和高度(宽高相同为正圆,否则为椭圆)
myGraphics.Dispose() '释放Graphics占用vb.net圆形的资源
如何用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怎么做圆形窗体设置Region属性:
Dim path As New System.Drawing.Drawing2D.GraphicsPath
path.AddEllipse(0, 0, 400, 300)
Region = New Region(path)
vb.net怎么画圆的图形Public a(8) As OvalShape
Dim canvas= New Microsoft.VisualBasic.PowerPacks.ShapeContainer
ConstCircleSize As Integer= 20
Const Dist As Integer = 10
Const Gap As Integer = 50
Dim i As Integer
canvas.Parent = Me.Panel1
For i =0 To 8
a(i) = NewOvalShape
a(i).Size = New Size(CircleSize,CircleSize)
a(i).Location = New Point(DistGap * (i Mod 3), DistGap * (i \ 3))
a(i).BorderWidth = 3
a(i).Enabled = True
a(i).Visible = True
a(i).Parent = canvas
Next
关于vb.net圆形和vb圆形控件的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站 。

    推荐阅读