例如在panel1上画一个圆心为(x,y)半径为z的圆~~请问怎么才能做到?谢谢啦~~~
解决方案 »
- 定义了很多dst,我想在循环中引用它,怎么写?请大侠赐教
- c#自定义控件
- 在DataGridVIew的CellEndEdit事件里怎么判断事件是不是由用户按Esc键触发的?(需要其它事件协助判断也行)(续)(急)
- 非常难的问题
- IrisSkin2.dll控件引用之后,所有控件格式统一,如果局部想取消显示自定义格式,怎么办呢?
- 类似outlook界面,如何切换其右边的显示内容?
- C#操作XML
- 关于C#开发微信批量添加好友的功能实现
- 为什么得不到正确的IP包内容
- 网络高手请进,如何用C#实现windows Xp那种修复IP的功能?
- 使用 backgroundWorker 出现的异常问题
- 关于用户自定义数据类型
using System.Drawing;
using System.Windows.Forms;class Form1 : Form
{
Form1()
{
Panel panel1 = new Panel();
panel1.Parent = this;
panel1.Dock = DockStyle.Fill;
panel1.Paint += delegate(object o, PaintEventArgs e)
{
// 画一个圆心为(x,y)半径为z的圆
float x = 80;
float y = 90;
float z = 50;
e.Graphics.DrawEllipse(Pens.Red, x - z, y - z, z * 2, z * 2);
};
}
static void Main()
{
Application.Run(new Form1());
}
}
int y = 100;
int z = 40;
Graphics g = CreateGraphics();
Pen pen = new Pen(Color.Red, 2);
g.DrawEllipse(pen, x - z, y - z, 2 * z , 2* z);
g.Flush();
g.Dispose();
private void panel1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
g.DrawEllipse( new Pen (Color.Yellow ,1 ) ,5,5,150,150);
}
你看看吧!!
using System.Drawing;
using System.Windows.Forms;class Form1 : Form
{
Form1()
{
Panel panel1 = new Panel();
panel1.Parent = this;
panel1.Dock = DockStyle.Fill;
panel1.Paint += delegate(object o, PaintEventArgs e)
{
// 画一个圆心为(x,y)半径为z的实心圆
float x = 80;
float y = 90;
float z = 20;
e.Graphics.FillEllipse(new SolidBrush(Color.Blue), x - z, y - z, z * 2, z * 2);
};
}
static void Main()
{
Application.Run(new Form1());
}
}
private int x = 100;
private int y = 100;
private int z = 50;
private void panel1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawEllipse(new Pen(Color.Green, 2), x - z, y - z, 2 * z, 2 * z);
//下面部分可以省略,只是方便验证
e.Graphics.DrawLine(new Pen(Color.Blue, 1), 0, 0, x, y);
e.Graphics.DrawLine(new Pen(Color.Blue, 1), 0, y, x, y);
e.Graphics.DrawLine(new Pen(Color.Blue, 1), x, 0, x, y);
}
OnPaint 是时时画的,别说你刷新,你就是切换界面它就会重新画一次.
内存中画图方式:
按钮单击事件中写一下代码
Bitmap bmp = new Bitmap(400,500);
Graphic g = Graphic.FromImage(bmp);
g.DrawEllipse(...); //参数省略
然后呢在
panel中放个图片控件
pic.Image = bmp;
差不多就这个意思
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
Panel panel1 = new Panel();
panel1.Parent = this;
panel1.Dock = DockStyle.Fill;
//匿名方法
panel1.Paint += delegate(object sender, PaintEventArgs e)
{
// 画一个圆心为(x,y)半径为z的圆
float x = 80;
float y = 90;
float z = 50;
e.Graphics.DrawEllipse(Pens.Red, x - z, y - z, z * 2, z * 2);
};
}
}
}