如何可以实现在一个窗体中一个小球图形从上往下掉下?不使用pictureBox控件? 如何可以实现在一个窗体中一个小球图形从上往下掉下?不使用pictureBox控件? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 不知道.我记得有直接draw图像的方法 比较简单。使用一个Timer控件,在Timer的每次事件中改变小球的位置,然后刷新控件一次, 于是就触发了Paint事件,你在Paint事件中添加绘制代码。用Graphics绘制。 控件启用双缓冲。你可以通过使用自动落体工式来使小球下落更逼真。 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; } }你可以用一幅图来代替绘制的球,会有更好的效果。代码未经优化,仅供参考。但以完全展示出该效果。 Excel使用OLEDB读取数据出现精度问题 WinForm多个子窗体如何共用主窗体中的工具栏 存储过程-表-累加(有没有更好的方法) 提取其他页面中的内容?! 请教c#中大写字母的问题 多线程流水线模式的问题???????????????????? 高分求助,如何在windows form 的 datagrid 上实现双击事件? 笨熊问题:在C#中如何将表中的记录排序??? value 相关的问题 关于将类中属性值显示在窗体控件中。 ===这个获取gridview的行号问题把我弄晕了,求解=== 如何把一个XML文档用DataSet把XML文档里元素和元素的属性保存到数据库里
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;
}
}
你可以用一幅图来代替绘制的球,会有更好的效果。代码未经优化,仅供参考。但以完全展示出该效果。