我想用 c# 和 PictureBox
显示图像。我创建了一个包含 pictureBox
和计时器的类。但是当从中创建对象时什么都不显示。
我该怎么办?
我是否正确使用了 timer1?
这是我的代码:
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
c1 c = new c1();
c.create_move(1);
}
}
class c1 {
PictureBox p = new PictureBox();
Timer timer1 = new Timer();
public void create_move(int i){
p.ImageLocation = "1.png";
p.Location = new Point(50, 50 + (i - 1) * 50);
timer1.Start();
timer1.Interval = 15;
timer1.Tick += new EventHandler(timer_Tick);
}
private int k = 0;
void timer_Tick(object sender, EventArgs e)
{
// some code. this part work outside the class c1 properly.
...
}
最佳答案
您需要将图片框添加到Form
。查看 Form.Controls.Add()
方法。
关于c# - 在 C# 中显示图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4874800/