这是一个完整的程序,运行:
图片框如图所选中,
但我不知道图片的来源。图片框中的属性找了,都没有找到运行时候显示出的图片。
我是有一个这程序的文件包的,但我不知道图片的来源。
图片框中的属性找了,都没有找到运行时候显示出的图片。
复制.FORM1.cs内容到新建的代码段里是行不通的,图像文件插入picturebox1中的image和initialimage都是没办法显示的。using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace 实验4._1
{
    public partial class Form1 : Form
    {
        private int picno;
        private Bitmap[] bitmap;
        public Form1()
        {
            InitializeComponent();
        }        private void Form1_Load(object sender, EventArgs e)
        {
            timer1.Interval = 500;
            hScrollBar1.Value = 1000 - 500;
            bitmap = new Bitmap[9];
            picno = 0;
            for (int i =1; i < 9; i++)
            {
                string file = Application.StartupPath + "\\wolf\\" + i.ToString() + ".jpg";
               bitmap[i-1] = new Bitmap(file);
                
            }
        }        private void hScrollBar1_Scroll(object sender, ScrollEventArgs e)
        {
            timer1.Interval = 1000-hScrollBar1.Value;        }        private void button1_Click(object sender, EventArgs e)
        {
            if (button1.Text =="开始")
            {
                button1.Text = "停止";
                timer1.Enabled = true;
            }
            else
            {
                button1.Text ="开始" ;
                timer1 .Enabled =false ;
            }
        }        private void timer1_Tick(object sender, EventArgs e)
        {
            pictureBox1.Image = bitmap[picno];
            picno = (picno + 1) % 9;
            pictureBox1.Left = pictureBox1.Left +10;
            if (pictureBox1.Left > this.Width) pictureBox1.Left = 0;
        }
    }
}
我试着用其他图片显示效果都失败了,比如我在initialmage中插入一组“DG01.bmp”-"DG5.bmp"图像
错误提示这两句: string file = Application.StartupPath + "\\DG0" + i.ToString() + ".bmp";
                 bitmap[i - 1] = new Bitmap(file);不知是图片插错控件地方了,还是怎么地,无法用自己的图片组来运行。

解决方案 »

  1.   

    Application.StartupPath + "\\wolf\\"中图片是否存在
      

  2.   

    !!,对,就是这个图片,我不知道这个图片是哪里插入picturebox1的,我没找到。这个图片,或者您用这个程序插入自己的9个图片试试,告诉我哪里插入,查看浙西图图。
      

  3.   

    这个图片存放在 Form1.resx 文件里呢
    下面的代码是在程序运行时如何访问 From1.resx 中的这个图片try
    {
        // 获取程序集中的所有资源文件
        System.Reflection.Assembly assembly =
            System.Reflection.Assembly.GetExecutingAssembly();    string[] resourceNames =
            assembly.GetManifestResourceNames();    // 这个可以查看到很多资源的名字
        // string[] resourceNames =
        //    this.pictureBox1.GetType().Assembly.GetManifestResourceNames();    Console.WriteLine(string.Join("\r\n", resourceNames));    // 在我的程序中输出的是:
        // CSDNSamples.Form1.resources
        // CSDNSamples.Properties.Resources.resources
        // CSDNSamples.Form2.resources    // 一般情况下各窗体和自定义控件的资源命名规则是
        // AssemblyName.FormName(UserControlName).resources    // 我就直接利用名称 CSDNSamples.Form1.resources 获取资源流
        System.IO.Stream resourceStream =
            assembly.GetManifestResourceStream("CSDNSamples.Form1.resources");    // 通过 resourceStream 创建一个 ResourceReader 对象
        System.Resources.ResourceReader reader =
            new System.Resources.ResourceReader(resourceStream);    System.Collections.IDictionaryEnumerator dic =
            reader.GetEnumerator();    while (dic.MoveNext())
        {
            Console.WriteLine(dic.Key.ToString());
            this.BackgroundImage = dic.Value as Image;
        }    reader.Close();
        resourceStream.Close();
    }
    catch (Exception ex)
    {
        Console.WriteLine(ex.Message);
    }
      

  4.   

    picturebox的属性里面不是有一个image属性吗?在那里插入本地的图片,不就可以显示了?
      

  5.   

    不行,只能放一张,也许是我试错了。
    现在图片我找到了,是在DBUG文件夹中,是怎么放进DBUG中的,是手动添加控件中还是编程写出来的?试验成功后回我,谢谢。
      

  6.   

    根据我的代码,求大虾传授让图片添加到到BIN文件夹下Debug文件夹中的操作步骤(代码形式或属性添加,不要手动添加图片到DEBUG中谢谢)。
      

  7.   

    选择项目->添加->现有项->选择图片文件->目录树中选择图片->属性->复制到输出目录:是 + 生成操作:无
      

  8.   

    moon前辈,在程序中实现行吗?您这方法这么搞啊