CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
可用分押宝游戏火热进行中... 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  .NET技术 >  C#

高手教我:为什么给控件加上图片后就不能正常使用了啊?

楼主km168()2003-06-02 10:50:07 在 .NET技术 / C# 提问

我打算在窗体中实现飞机飞翔的效果。我添加了一个PictureBox控件,并加上图片,可是会出现如下的异常:  
   
  未处理的“System.Resources.MissingManifestResourceException”类型的异常出现在   mscorlib.dll   中  
   
  其他信息:未能在给定的程序集中找到任何适合于指定的区域性(或非特定区域性)的资源。请确保已将“Form1.resources”正确嵌入或链接到程序集“WindowsApplication4”。  
  baseName:   Form1     locationInfo:   WindowsApplication4.Form1     resource   file   name:   Form1.resources     assembly:   WindowsApplication4,   Version=1.0.1248.18561,   Culture=neutral,   PublicKeyToken=null  
   
  发生异常的语句是:  
  this.plane.Image   =   ((System.Drawing.Bitmap)(resources.GetObject("plane.Image")));  
   
  这里的plane是控件名。  
   
  可我将控件换成Label控件,不加图片,仅仅是将Label.text改成“飞机”,却能很好的运行,这是怎么回事?换成Label后代码如下:  
   
  using   System;  
  using   System.Drawing;  
  using   System.Collections;  
  using   System.ComponentModel;  
  using   System.Windows.Forms;  
  using   System.Data;  
  using   System.Threading;  
   
  namespace   WindowsApplication4  
  {  
  class   planeflying  
  {  
  public   static   Label   b;  
  public   planeflying(Label   label1)  
  {  
  b=label1;  
  }  
  public   void   fly()  
  {  
  int   i=310;  
  while(true)  
  {  
  while(i>5)  
  {  
  b.Location=new   System.Drawing.Point(i,88);  
  i--;  
  Thread.Sleep(20);  
  }  
  b.Location=new   System.Drawing.Point(310,88);  
  i=310;  
  }  
   
   
  }  
   
  }  
   
   
  ///   <summary>  
  ///   Form1   的摘要说明。  
  ///   </summary>  
   
  public   class   Form1   :   System.Windows.Forms.Form  
  {  
  private   System.Windows.Forms.Button   begin;  
  private   System.Windows.Forms.Button   pause;  
  private   System.Windows.Forms.Button   restart;  
  private   System.Windows.Forms.Button   stop;  
  Thread   t;  
  private   System.Windows.Forms.Label   plane;  
  ///   <summary>  
  ///   必需的设计器变量。  
  ///   </summary>  
  private   System.ComponentModel.Container   components   =   null;  
   
  public   Form1()  
  {  
  //  
  //   Windows   窗体设计器支持所必需的  
  //  
  InitializeComponent();  
   
  //  
  //   TODO:   在   InitializeComponent   调用后添加任何构造函数代码  
  //  
  }  
   
  ///   <summary>  
  ///   清理所有正在使用的资源。  
  ///   </summary>  
  protected   override   void   Dispose(   bool   disposing   )  
  {  
  if(   disposing   )  
  {  
  if   (components   !=   null)    
  {  
  components.Dispose();  
  }  
  }  
  base.Dispose(   disposing   );  
  }  
   
  #region   Windows   Form   Designer   generated   code  
  ///   <summary>  
  ///   设计器支持所需的方法   -   不要使用代码编辑器修改  
  ///   此方法的内容。  
  ///   </summary>  
  private   void   InitializeComponent()  
  {  
  this.begin   =   new   System.Windows.Forms.Button();  
  this.pause   =   new   System.Windows.Forms.Button();  
  this.restart   =   new   System.Windows.Forms.Button();  
  this.stop   =   new   System.Windows.Forms.Button();  
  this.plane   =   new   System.Windows.Forms.Label();  
  this.SuspendLayout();  
  //    
  //   begin  
  //    
  this.begin.Location   =   new   System.Drawing.Point(16,   200);  
  this.begin.Name   =   "begin";  
  this.begin.Size   =   new   System.Drawing.Size(56,   23);  
  this.begin.TabIndex   =   3;  
  this.begin.Text   =   "开始";  
  this.begin.Click   +=   new   System.EventHandler(this.begin_Click);  
  //    
  //   pause  
  //    
  this.pause.Location   =   new   System.Drawing.Point(88,   200);  
  this.pause.Name   =   "pause";  
  this.pause.Size   =   new   System.Drawing.Size(56,   23);  
  this.pause.TabIndex   =   4;  
  this.pause.Text   =   "暂停";  
  this.pause.Click   +=   new   System.EventHandler(this.pause_Click);  
  //    
  //   restart  
  //    
  this.restart.Location   =   new   System.Drawing.Point(160,   200);  
  this.restart.Name   =   "restart";  
  this.restart.Size   =   new   System.Drawing.Size(56,   23);  
  this.restart.TabIndex   =   5;  
  this.restart.Text   =   "重启";  
  this.restart.Click   +=   new   System.EventHandler(this.restart_Click);  
  //    
  //   stop  
  //    
  this.stop.Location   =   new   System.Drawing.Point(232,   200);  
  this.stop.Name   =   "stop";  
  this.stop.Size   =   new   System.Drawing.Size(56,   23);  
  this.stop.TabIndex   =   6;  
  this.stop.Text   =   "停止";  
  this.stop.Click   +=   new   System.EventHandler(this.stop_Click);  
  //    
  //   plane  
  //    
  this.plane.Location   =   new   System.Drawing.Point(310,   88);  
  this.plane.Name   =   "plane";  
  this.plane.Size   =   new   System.Drawing.Size(48,   16);  
  this.plane.TabIndex   =   7;  
  this.plane.Text   =   "飞机";  
  //    
  //   Form1  
  //    
  this.AutoScaleBaseSize   =   new   System.Drawing.Size(6,   14);  
  this.ClientSize   =   new   System.Drawing.Size(312,   273);  
  this.Controls.AddRange(new   System.Windows.Forms.Control[]   {  
      this.plane,  
      this.stop,  
      this.restart,  
      this.pause,  
      this.begin});  
  this.Name   =   "Form1";  
  this.Text   =   "Form1";  
  this.Load   +=   new   System.EventHandler(this.Form1_Load);  
  this.ResumeLayout(false);  
   
  }  
  #endregion  
   
  ///   <summary>  
  ///   应用程序的主入口点。  
  ///   </summary>  
  [STAThread]  
  static   void   Main()    
  {  
  Application.Run(new   Form1());  
  }  
   
   
  private   void   Form1_Load(object   sender,   System.EventArgs   e)  
  {  
  planeflying   f=new   planeflying(plane);//这里的plane是那个Label控件名  
  t=new   Thread(new   ThreadStart(f.fly));  
   
  begin.Enabled=true;  
  pause.Enabled=false;  
  restart.Enabled=false;  
  stop.Enabled=false;  
  }  
   
  private   void   begin_Click(object   sender,   System.EventArgs   e)  
  {  
  begin.Enabled=false;  
  restart.Enabled=false;  
  pause.Enabled=true;  
  stop.Enabled=true;  
  t.Start();  
  }  
   
  private   void   pause_Click(object   sender,   System.EventArgs   e)  
  {  
  pause.Enabled=false;  
  restart.Enabled=true;  
  stop.Enabled=false;  
  t.Suspend();  
  }  
   
  private   void   restart_Click(object   sender,   System.EventArgs   e)  
  {  
  pause.Enabled=true;  
  restart.Enabled=false;  
  stop.Enabled=true;  
  stop.Enabled=true;  
  t.Resume();  
  }  
   
  private   void   stop_Click(object   sender,   System.EventArgs   e)  
  {  
  begin.Enabled=true;  
  pause.Enabled=false;  
  restart.Enabled=false;  
  stop.Enabled=false;  
  if(t.IsAlive)  
  {  
  t.Abort();  
  Form1_Load(sender,e);  
  plane.Location=new   System.Drawing.Point(310,88);  
  }  
  }  
  }  
  }  
  问题点数:100、回复次数:6Top

1 楼Knight94(愚翁)回复于 2003-06-02 11:29:53 得分 30

最好不要在设计的时候给控件添加图片,可以在InitializeComponent()之后或Form_Load事件中添加,例如:  
  pictureBox1.Image=Image.FromFile(yourImageFile);Top

2 楼fastxyf(迅影)回复于 2003-06-02 11:35:09 得分 20

你的资源文件没删除吧,看看关连了没有Top

3 楼km168()回复于 2003-06-02 12:21:43 得分 0

我的图片的文件名是pic015_jpg,文件类型是JPEG   图像,添加语句pictureBox1.Image=Image.FromFile(pic015_jpg);后还是不能用啊,说“找不到类型或命名空间名称“pic015_jpg”(是否缺少   using   指令或程序集引用?)”。  
   
  还有,怎么看关连了没有?  
   
  Top

4 楼km168()回复于 2003-06-02 12:32:53 得分 0

顶Top

5 楼CMIC(大象)回复于 2003-06-02 12:51:43 得分 30

Image.FromFile方法是文件名及所在路径的字符串,比如:你的pic015_jpg文件在C;\Temp下,  
  Image.FromFile(@"C;\Temp\pic015_jpg.jpg");Top

6 楼dragontt(今年本命年)回复于 2003-06-02 18:55:10 得分 20

Image.FromFile(pic015_jpg);  
  这里应该把文件名当作string对象传进取  
   
  按照楼上的方法修改Top

相关问题

  • 如和在控件(如:CoolBar,ToolBar)上加上背景图片,
  • 如何在TreeView控件加上背景图片?(不是改变被景色)
  • 图片显示控件?
  • 当要显示的图片很大时,如何给image控件加上滚动条?
  • 请问怎么给TListView控件加上背景图片,就是实现Windows桌面的效果
  • 请问怎么给TListView控件加上背景图片,而背景图片不会覆盖ListView的Item的图片和字体
  • 用TQuery控件从数据库返回的图片无法正常显示??!!高手赐教
  • 怎样用TQUERY控件存取IMAGE控件的图片?
  • 怎样为控件加上滚动条?
  • image 控件装载图片怎么写?

关键词

  • 控件
  • 代码
  • restart
  • pause
  • plane
  • stop
  • planeflying
  • enabled
  • windowsapplication4
  • drawing

得分解答快速导航

  • 帖主:km168
  • Knight94
  • fastxyf
  • CMIC
  • dragontt

相关链接

  • CSDN .NET频道
  • .NET类图书
  • C#类图书
  • .NET类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo