在线等候,调用API后出错的问题 正常的C#的WinForm程序里面加上调用API好用,但是给FORM一指定图标就出现这个问题了!!!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 resource 有没有加到项目中? using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;using System.Data;using System.Runtime.InteropServices;class callAPICls { [DllImport("kernel32.dll", SetLastError=true)] static extern int AllocConsole(); [DllImport("kernel32.dll", SetLastError=true)] static extern int FreeConsole(); public static int Show() { return AllocConsole(); } public static int ShowClose() { return FreeConsole(); } public static void write(string str) { System.Console.Write(str); }} namespace WindowsApplication1{ /// <summary> /// Form1 的摘要说明。 /// </summary> public class Form1 : System.Windows.Forms.Form { /// <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 窗体设计器生成的代码 /// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() { // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(6, 14); this.ClientSize = new System.Drawing.Size(292, 273); this.Name = "Form1"; this.Text = "Form1"; this.Load += new System.EventHandler(this.Form1_Load); } #endregion /// <summary> /// 应用程序的主入口点。 /// </summary> [STAThread] static void Main() { Application.Run(new Form1()); } private void Form1_Load(object sender, System.EventArgs e) { } }}以上是我用来测试的程序,如果不给Form指定图标是好用的,指定图标就出错 我没看明白,你在设计时把图标直接加到FORM上,但在程序里却是从资源文件里去拿这个图标.资源文件里并没有这个图标,错误是出在这里的.这和你调用API没有关系."但是项目一加上图标就不行了."加的是这个notifyIcon1.Icon吗? TO (铁拳 2004) 我不知道怎么回事,如果不加这个API调用运行是正常的,加上API调用就出错了.你可以看看我后贴出来的代码,比较简单,就是在WinForm程序里面加了调用API,如果不给Form指定图标是好用的,指定图标就出错 未能在给定的程序集中找到任何适合于指定的区域性(或非特定区域性)的资源。请确保已将“Form1.resources”正确嵌入或链接到程序集“MYGUI”。这不是已经提示出来了么? 我没有资源文件呀,新建项目时根本就不给任何资源文件System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));就这么一句,是C#自已生成的 http://blog.csdn.net/lizanhong/archive/2004/09/10/100812.aspx 我的思路是自己建一个资源文件,将所用的图标放入所见的资源文件中,然后再在你的这个程序中引用这个资源文件的图标。下列代码没有经过测试,只是设想。创建资源文件(用控制台程序创建就行,所得的资源文件拷贝到你的程序文件中):ResourceWriter rw=new ResourceWriter("demo.resources");Icon icon=new Icon("填写完整的文件路径名和文件名");rw.AddResource("取个名字",icon);rw.Close();在程序中用资源文件:private ResourceManager rm;public Form1(){ Assembly asse=Assembly.GetExecutingAssembly(); rm=new ResourceManager("所创建资源文件路径,不要扩展名",asse); this.notifyIcon1.Icon = (Icon)rm.GetObject("取的名字");} excel打印 WPF简单动画问题 datatable赋值时索引超出范围 急 关于ultragrid控件事件问题 AssemblyInfo.cs文件里的accembly都是什么意思? 关于ComboBox问题 TabControl的选项卡里面如何设置默认按钮? (急切求助)无线PDA接入局域网及读条码问题讨论。。。 急!!乱码问题!~!请高手帮忙~ 为什么TextBox内容Change不能触发TextBox1_TextChanged()事件? 高分求"OPC .NET API 2.00 Redistributables" xml的小问题~~~~~~~~~~帮忙帮忙
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;
class callAPICls
{
[DllImport("kernel32.dll", SetLastError=true)] static extern int AllocConsole();
[DllImport("kernel32.dll", SetLastError=true)] static extern int FreeConsole();
public static int Show()
{
return AllocConsole();
}
public static int ShowClose()
{
return FreeConsole();
}
public static void write(string str)
{
System.Console.Write(str);
}
}
namespace WindowsApplication1
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
/// <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 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load); }
#endregion /// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
} private void Form1_Load(object sender, System.EventArgs e)
{
}
}
}
以上是我用来测试的程序,如果不给Form指定图标是好用的,指定图标就出错
资源文件里并没有这个图标,错误是出在这里的.这和你调用API没有关系."但是项目一加上图标就不行了."
加的是这个notifyIcon1.Icon吗?
我不知道怎么回事,如果不加这个API调用运行是正常的,加上API调用就出错了.你可以看看我后贴出来的代码,比较简单,就是在WinForm程序里面加了调用API,如果不给Form指定图标是好用的,指定图标就出错
这不是已经提示出来了么?
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
就这么一句,是C#自已生成的
ResourceWriter rw=new ResourceWriter("demo.resources");
Icon icon=new Icon("填写完整的文件路径名和文件名");
rw.AddResource("取个名字",icon);
rw.Close();在程序中用资源文件:
private ResourceManager rm;
public Form1()
{
Assembly asse=Assembly.GetExecutingAssembly();
rm=new ResourceManager("所创建资源文件路径,不要扩展名",asse); this.notifyIcon1.Icon = (Icon)rm.GetObject("取的名字");
}