我怎么画圆 [英] how can i draw circle

查看:90
本文介绍了我怎么画圆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我该如何在C#Windows窗体中绘制一个圆(一半是彩色,一半不是)
我知道如何绘制圆圈,但我不能为它上色
我希望你能理解我
这就是我画圆的方式

how can i draw a circle in c# windows form( half colored and half not)
i know how draw circle but i cant color it
i hope you understand me
and this how i draw circle

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.DrawEllipse(Pens.Red, 50, 50, 100, 100);
        }
    }
}


是对的还是不对的?


is that right or not

推荐答案

如果您希望它一半被着色"(您的意思是填入正确的符号?)而另一半不被着色,那不是圆圈.这是两个弧度.使用 Graphics.DrawArc [
If you want it half ''coloured'' (you mean filled in right?) and half not, it''s not a circle. It''s two arcs. Use Graphics.DrawArc[^] and FillPie.

( Whose idea was it to call the Fill and Draw items different things ...)


Bob的回答是正确的.请参阅下面的一些更重要的详细信息:

您所需要的只是DrawEllipseSystem.Drawing.Graphics.FillPie(Brush, Rectangle) 之前,请参见
http://msdn.microsoft.com/en-us/library/dw5wshbd.aspx [
Bob''s answer is correct. See some more important details below:

All you need is System.Drawing.Graphics.FillPie(Brush, Rectangle) before of DrawEllipse, see http://msdn.microsoft.com/en-us/library/dw5wshbd.aspx[^].

If you want to allocate a brush, don''t dispose it manually as UJimbo advised. That code is wrong because it will leak memory/resources in the case of exceptions. The right approach is using using statement:

Rectangle ellipseBounds = new Rectangle(50, 50, 100, 100); //like in your code sample
using (Brush brush = new SolidBrush(/* some parameters */)) {
    e.Graphics.FillPie(brush, ellipseBounds, 0, 180); //for example, do it before drawing lines.
    e.Graphics.DrawEllipse(Color.Red, ellipseBounds);
} //brush.Dispose will be automatically called here, even if exception is thrown



关于分配笔等的事情也一样.

—SA



Same thing about allocation of pens, etc.

—SA


您可以感谢BobJanova,DrawArc是一个很好的提示.

You can thank BobJanova for that, DrawArc was a good hint.

System.Drawing.SolidBrush brush0 = new System.Drawing.SolidBrush(System.Drawing.Color.Black);
System.Drawing.SolidBrush brush1 = new System.Drawing.SolidBrush(System.Drawing.Color.Red);
System.Drawing.SolidBrush brush2 = new System.Drawing.SolidBrush(System.Drawing.Color.Blue);

System.Drawing.Pen thePen = new System.Drawing.Pen(brush0);
System.Drawing.Graphics formGraphics = this.CreateGraphics();

formGraphics.DrawArc(thePen, new System.Drawing.Rectangle(150, 50, 100, 100), 0, 180);
formGraphics.DrawArc(thePen, new System.Drawing.Rectangle(150, 50, 100, 100), 180, 360);
formGraphics.FillPie(brush1, new System.Drawing.Rectangle(150, 50, 100, 100), 0, 180);
formGraphics.FillPie(brush2, new System.Drawing.Rectangle(150, 50, 100, 100), 180, 180);

brush0.Dispose();
brush1.Dispose();
brush2.Dispose();
thePen.Dispose();
formGraphics.Dispose();


这篇关于我怎么画圆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆