绘图问题 怎么在一个Panel组件上实现绘图比如说,画一个钟面上去 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 注册paint事件Panel p = new Panel();p.Paint += new PaintEventHandler(p_Paint);void p_Paint(object sender, PaintEventArgs e){ //画相应的东东,比如画一个圆 e.Graphics.DrawEllipse(Pens.Black, new Rectangle(10, 10, 50, 50));} 如果我想在Button的Click时间里实现这个功能呢? 那你可以把钟面做成一副图,然后在button click的时候,设置Panel的BackGroundImage为这幅画当然前提是这个图不能是动画 private void button1_Click(object sender, EventArgs e) { Graphics g = this.panel1.CreateGraphics(); Graphics.DrawEllipse(Pens.Black, new Rectangle(10, 10, 50, 50)); } private void button1_Click(object sender, EventArgs e) { Graphics g = this.panel1.CreateGraphics(); Pen bluePen = new Pen(Color.Blue, 3); g.DrawEllipse(bluePen, 0, 0, 100, 100); }这样就可以了 各位高手,还有个问题,我把钟面画好了,然后用了三个textbox来输入当前的时间请问输入之后表针应该怎么摆? 就是应该怎么重绘panel中的这个钟面图形? public class MyClock : UserControl{ Timer clock = new Timer(); public MyClock() { clock.Interval = 1000; clock.Tick += delegate { Invalidate(); }; clock.Start(); } protected override void OnPaint(PaintEventArgs e) { DateTime now = DateTime.Now; using (Graphics g = e.Graphics) { g.TranslateTransform(ClientRectangle.Width / 2.0f, ClientRectangle.Height / 2.0f); System.Drawing.Drawing2D.GraphicsState state = g.Save(); g.RotateTransform( now.Second * 6 - 90); g.DrawLine(Pens.YellowGreen, 0, 0, ClientRectangle.Width / 3, 0); g.Restore(state); g.RotateTransform(now.Minute * 6 - 90); g.DrawLine(new Pen(Brushes.BlueViolet, 2), 0, 0, ClientRectangle.Width / 4, 0); } }}这是我在另外一个帖子发的一个控件,和画在panel上没有本质的区别。C# WinForm中能让显示时间的钟表的指针随系统时间一起动起来吗? public class MyClock : UserControl{ Timer clock = new Timer(); public MyClock() { clock.Interval = 1000; clock.Tick += delegate { Invalidate(); }; clock.Start(); } protected override void OnPaint(PaintEventArgs e) { DateTime now = DateTime.Now; using (Graphics g = e.Graphics) { g.TranslateTransform(ClientRectangle.Width / 2.0f, ClientRectangle.Height / 2.0f); System.Drawing.Drawing2D.GraphicsState state = g.Save(); g.RotateTransform( now.Second * 6 - 90); g.DrawLine(Pens.YellowGreen, 0, 0, ClientRectangle.Width / 3, 0); g.Restore(state); g.RotateTransform(now.Minute * 6 - 90); g.DrawLine(new Pen(Brushes.BlueViolet, 2), 0, 0, ClientRectangle.Width / 4, 0); } }或者计算角度。也可以。 http://www.skinfeature.com/bbs 很多教程 关于DATASET更新数据库德问题 请教“如何用c# + sql2005 做信息滚动软件”!!!!!! VS2005水晶报表问题 你遍历文件夹没有? 天行点歌问题 程序中引用了Excel对象,如何在打包安装后,让客户端也能正常使用?? vs2003与office2003的问题:访问帮助\搜索时,总是要启动office2003的安装程序??怎么回事 我如何把网上的流媒体录制到本地? C#中如何用xpath找到对应的节点,详细说明见内容 中秋节 大送分 tabcontrol控件里怎么添加滚动条?而且滚动条是所有tabpage共用的?谢谢!!急~~ 【100分,不够再加】图像处理
p.Paint += new PaintEventHandler(p_Paint);
void p_Paint(object sender, PaintEventArgs e)
{
//画相应的东东,比如画一个圆
e.Graphics.DrawEllipse(Pens.Black, new Rectangle(10, 10, 50, 50));
}
那你可以把钟面做成一副图,然后在button click的时候,设置Panel的BackGroundImage为这幅画当然前提是这个图不能是动画
{
Graphics g = this.panel1.CreateGraphics();
Graphics.DrawEllipse(Pens.Black, new Rectangle(10, 10, 50, 50));
}
private void button1_Click(object sender, EventArgs e)
{
Graphics g = this.panel1.CreateGraphics();
Pen bluePen = new Pen(Color.Blue, 3);
g.DrawEllipse(bluePen, 0, 0, 100, 100);
}
这样就可以了
请问输入之后表针应该怎么摆?
public class MyClock : UserControl
{
Timer clock = new Timer();
public MyClock()
{
clock.Interval = 1000;
clock.Tick += delegate { Invalidate(); };
clock.Start();
} protected override void OnPaint(PaintEventArgs e)
{
DateTime now = DateTime.Now;
using (Graphics g = e.Graphics)
{
g.TranslateTransform(ClientRectangle.Width / 2.0f, ClientRectangle.Height / 2.0f);
System.Drawing.Drawing2D.GraphicsState state = g.Save(); g.RotateTransform( now.Second * 6 - 90);
g.DrawLine(Pens.YellowGreen, 0, 0, ClientRectangle.Width / 3, 0); g.Restore(state);
g.RotateTransform(now.Minute * 6 - 90);
g.DrawLine(new Pen(Brushes.BlueViolet, 2), 0, 0, ClientRectangle.Width / 4, 0);
}
}
}这是我在另外一个帖子发的一个控件,和画在panel上没有本质的区别。
C# WinForm中能让显示时间的钟表的指针随系统时间一起动起来吗?
{
Timer clock = new Timer();
public MyClock()
{
clock.Interval = 1000;
clock.Tick += delegate { Invalidate(); };
clock.Start();
} protected override void OnPaint(PaintEventArgs e)
{
DateTime now = DateTime.Now;
using (Graphics g = e.Graphics)
{
g.TranslateTransform(ClientRectangle.Width / 2.0f, ClientRectangle.Height / 2.0f);
System.Drawing.Drawing2D.GraphicsState state = g.Save(); g.RotateTransform( now.Second * 6 - 90);
g.DrawLine(Pens.YellowGreen, 0, 0, ClientRectangle.Width / 3, 0); g.Restore(state);
g.RotateTransform(now.Minute * 6 - 90);
g.DrawLine(new Pen(Brushes.BlueViolet, 2), 0, 0, ClientRectangle.Width / 4, 0);
}
}
或者计算角度。也可以。