PictureBox
を使用して、C#でイメージを表示したいとします。私は、コントリビュータがpictureBox
のタイマーとタイマーを作成しました。そこからオブジェクトを作成するときは、何も表示されません。イメージをC言語で表示する#
どうすればよいですか?
私はtimer1を正しく使用していますか? Timer
が有効になっていることを
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.
...
}
私はそれをどこに置くべきですか? move_create()メソッドでForm1.Controls.Add(p)を書きましたが、エラーが発生しました... –
フォームへの参照が必要です。あなたのクラスのコンストラクタにプロパティを渡して渡してください。 – Shimrod