gpt4 book ai didi

c# - 在 C# 中显示图像

转载 作者:可可西里 更新时间:2023-11-01 03:06:29 26 4
gpt4 key购买 nike

我想用 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com