C#画圆问题
答案:3 悬赏:50 手机版
解决时间 2021-12-03 00:13
- 提问者网友:不爱我么
- 2021-12-02 18:20
C#画圆问题
最佳答案
- 五星知识达人网友:洎扰庸人
- 2021-12-02 19:13
Point center = new Point(20, 20);
Graphics paper = pictureBoxDisplay.CreateGraphics();
paper.Clear(this.BackColor);
SolidBrush aBrush = new SolidBrush(Color.Green);
Pen blackPen = new Pen(Color.Black, 1);
int r = int.Parse(textBox1.Text);
Rectangle bar = new Rectangle(center.X-r,center.Y-r,center.X+r,center.Y+r);
paper.FillEllipse(aBrush, bar);
paper.DrawEllipse(blackPen, bar);
bar.Y += 80;
aBrush.Color = Color.Yellow;
paper.FillEllipse(aBrush, bar);
paper.DrawEllipse(blackPen, bar);
bar.Y += 80;
aBrush.Color = Color.Red;
paper.FillEllipse(aBrush, bar);
paper.DrawEllipse(blackPen, bar);
Graphics paper = pictureBoxDisplay.CreateGraphics();
paper.Clear(this.BackColor);
SolidBrush aBrush = new SolidBrush(Color.Green);
Pen blackPen = new Pen(Color.Black, 1);
int r = int.Parse(textBox1.Text);
Rectangle bar = new Rectangle(center.X-r,center.Y-r,center.X+r,center.Y+r);
paper.FillEllipse(aBrush, bar);
paper.DrawEllipse(blackPen, bar);
bar.Y += 80;
aBrush.Color = Color.Yellow;
paper.FillEllipse(aBrush, bar);
paper.DrawEllipse(blackPen, bar);
bar.Y += 80;
aBrush.Color = Color.Red;
paper.FillEllipse(aBrush, bar);
paper.DrawEllipse(blackPen, bar);
全部回答
- 1楼网友:像个废品
- 2021-12-02 21:35
FillEllipse函数,用来填充一个矩形的内部椭圆的。当矩形尺寸变小的时候,椭圆也就变小了。
你这里的矩形bar创建的时候,使用Rectangle(10, 10, 50, 50);,自己修改一下尺寸就可以了。
描黑边,实际上就是用黑色画笔画一个圆。使用Graphics类的DrawEllipse函数(填充用FillEllipse)
你这里的矩形bar创建的时候,使用Rectangle(10, 10, 50, 50);,自己修改一下尺寸就可以了。
描黑边,实际上就是用黑色画笔画一个圆。使用Graphics类的DrawEllipse函数(填充用FillEllipse)
- 2楼网友:夜风逐马
- 2021-12-02 20:14
private void button1_Click(object sender, EventArgs e)
{
int diameter;
try
{
diameter = int.Parse(textBox1.Text);
}
catch
{
MessageBox.Show("直径值错误!");
return;
}
Rectangle rect = new Rectangle(10, 10, diameter, diameter);
Graphics g = pictureBox1.CreateGraphics();
//清除原来画的圆
g.Clear(pictureBox1.BackColor);
//画圆——绿色
Brush brush = new SolidBrush(Color.Green);
g.FillEllipse(brush, rect);
//描边
Pen pen = Pens.Black;
g.DrawEllipse(pen, rect);
//画圆——黄色
rect.Y += 80;
brush = new SolidBrush(Color.Yellow);
g.FillEllipse(brush, rect);
//描边
g.DrawEllipse(pen, rect);
//画圆——红色
rect.Y += 80;
brush = new SolidBrush(Color.Red);
g.FillEllipse(brush, rect);
//描边
g.DrawEllipse(pen, rect);
g.Dispose();
}
{
int diameter;
try
{
diameter = int.Parse(textBox1.Text);
}
catch
{
MessageBox.Show("直径值错误!");
return;
}
Rectangle rect = new Rectangle(10, 10, diameter, diameter);
Graphics g = pictureBox1.CreateGraphics();
//清除原来画的圆
g.Clear(pictureBox1.BackColor);
//画圆——绿色
Brush brush = new SolidBrush(Color.Green);
g.FillEllipse(brush, rect);
//描边
Pen pen = Pens.Black;
g.DrawEllipse(pen, rect);
//画圆——黄色
rect.Y += 80;
brush = new SolidBrush(Color.Yellow);
g.FillEllipse(brush, rect);
//描边
g.DrawEllipse(pen, rect);
//画圆——红色
rect.Y += 80;
brush = new SolidBrush(Color.Red);
g.FillEllipse(brush, rect);
//描边
g.DrawEllipse(pen, rect);
g.Dispose();
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯