如何可以实现在一个窗体中一个小球图形从上往下掉下?不使用pictureBox控件?

解决方案 »

  1.   

    不知道.我记得有直接draw图像的方法
      

  2.   

    比较简单。使用一个Timer控件,在Timer的每次事件中改变小球的位置,然后刷新控件一次, 于是就触发了Paint事件,你在Paint事件中添加绘制代码。用Graphics绘制。 控件启用双缓冲。你可以通过使用自动落体工式来使小球下落更逼真。
      

  3.   


    public partial class Form1 : Form
        {
            private float y;
            private int time;
            private Brush b;
            public Form1()
            {
                InitializeComponent();
                b = new SolidBrush(Color.Blue);
            }        private void timer1_Tick(object sender, EventArgs e)
            {
                time++;
                y = 0.5F * 9.8F * time * time;
                if (y >= Top + Height)
                {
                    y = 0;
                    time = 0;
                }
                Invalidate();        }
            protected override void OnPaint(PaintEventArgs e)
            {
                base.OnPaint(e);
                Graphics gra = e.Graphics;
                gra.FillEllipse(b,new Rectangle(20,(int)y,40,40));
            }        private void button1_Click(object sender, EventArgs e)
            {
                timer1.Enabled = true;
            }
        }
    你可以用一幅图来代替绘制的球,会有更好的效果。代码未经优化,仅供参考。但以完全展示出该效果。