怎么在一个Panel组件上实现绘图
比如说,画一个钟面上去

解决方案 »

  1.   

    注册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));
    }
      

  2.   

    如果我想在Button的Click时间里实现这个功能呢?
      

  3.   


    那你可以把钟面做成一副图,然后在button click的时候,设置Panel的BackGroundImage为这幅画当然前提是这个图不能是动画
      

  4.   

     private void button1_Click(object sender, EventArgs e)
            {
                Graphics g = this.panel1.CreateGraphics();
                Graphics.DrawEllipse(Pens.Black, new Rectangle(10, 10, 50, 50)); 
            } 
      

  5.   


            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);
            }
    这样就可以了
      

  6.   

    各位高手,还有个问题,我把钟面画好了,然后用了三个textbox来输入当前的时间
    请问输入之后表针应该怎么摆?
      

  7.   

    就是应该怎么重绘panel中的这个钟面图形?
      

  8.   


    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中能让显示时间的钟表的指针随系统时间一起动起来吗?
      

  9.   

    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);
            }
        }
    或者计算角度。也可以。
      

  10.   

    http://www.skinfeature.com/bbs 很多教程