c# - 在 C# 中显示图像

标签 c# winforms

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

相关文章:

c# - 如何使 DateTimePicker 在鼠标滚轮上递增/递减

c# - 从未加载的程序集中获取类型

c# - 如何在 C# 中执行快速 Web 请求

c# - VLC Media Player 如何实现 HTTP Streaming?

winforms - MenuStrip 快捷键间距

c# - 调用父窗体函数?

c# - 在本地机器上设置数据库备份文件

c# - 使用 DrawString() 正确绘制文本

c# - 如何创建带圆角的用户控件?

C# Winform 应用程序无法在其他计算机上运行(启动时神秘挂起)