473,396 Members | 1,689 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Strange behavior when setting the icon of a window.

The following program simply sets the icon of a form called form1. When I
get the name of the embedded icon using GetManifestResourceNames(), I store
the name in a string variable called s. The value of s is "test2.icon1.ico".
This program will compile and run just fine from visual studio .net 2003
using .net 1.1 and also will compile and run just fine using csc form1.cs
/resource:icon1.ico.

Now, I created a new string called s2 and just simply stored the value
"test2.icon1.ico" in it. When I use s2 instead of s as a parameter to
GetManifestResourceSteam, the program will compile and run just fine in
Visual Studio 2003 but when compiled from the command line using cs form1.cs
/resource:icon1.ico, the GetManifestResourceString() method does not return a
valid string. This is really strange because the s and s2 strings are
identical.

Is this a bug or am I missing something?

Here is the code:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Reflection;
using System.IO;
using System.Diagnostics;

namespace test2
{
public class Form1 : System.Windows.Forms.Form
{
private System.ComponentModel.Container components = null;

public Form1()
{
InitializeComponent();
}

protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Form1_Load);
}

static void Main()
{
Application.Run(new Form1());
}

private void Form1_Load(object sender, System.EventArgs e)
{
Stream imgStream = null;
Assembly a = Assembly.GetExecutingAssembly();
string [] resNames = a.GetManifestResourceNames();
foreach(string s in resNames)
{
if(s.EndsWith(".ico"))
{
string s2 = "test2.icon1.ico";
imgStream = a.GetManifestResourceStream(s2);

if( !(null==imgStream) )
{
System.Drawing.Icon ico = new Icon(imgStream);
this.Icon = ico ;
}
}
}
}
}
}

This code is stored in Form1.cs and added to a project called test2. It
also needs an embedded icon file called icon1.ico.

If this program is executed with:

imgStream = a.GetManifestResourceStream(s2);

The program will work from Visual Studio 2003 but not at a command line
using csc to compile.

If this program is executed with:

imgStream = a.GetManifestResourceStream(s);

The program will execute properly from Visual Studio 2003 and at a command
line using csc.

Thanks for the help.

Feb 28 '06 #1
1 2265
If anyone is interested, the behavior noted is because the
/resource:icon1.ico command line parameter to csc embeds the icon in the
executable program as icon1.ico but Visual Studio embeds the icon as
test2.icon1.ico. This is why the EndsWith() worked for csc and Visual Studio
but the use of test2.icon1.ico failed when compile by csc.

"hansolox1" wrote:
The following program simply sets the icon of a form called form1. When I
get the name of the embedded icon using GetManifestResourceNames(), I store
the name in a string variable called s. The value of s is "test2.icon1.ico".
This program will compile and run just fine from visual studio .net 2003
using .net 1.1 and also will compile and run just fine using csc form1.cs
/resource:icon1.ico.

Now, I created a new string called s2 and just simply stored the value
"test2.icon1.ico" in it. When I use s2 instead of s as a parameter to
GetManifestResourceSteam, the program will compile and run just fine in
Visual Studio 2003 but when compiled from the command line using cs form1.cs
/resource:icon1.ico, the GetManifestResourceString() method does not return a
valid string. This is really strange because the s and s2 strings are
identical.

Is this a bug or am I missing something?

Here is the code:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Reflection;
using System.IO;
using System.Diagnostics;

namespace test2
{
public class Form1 : System.Windows.Forms.Form
{
private System.ComponentModel.Container components = null;

public Form1()
{
InitializeComponent();
}

protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Form1_Load);
}

static void Main()
{
Application.Run(new Form1());
}

private void Form1_Load(object sender, System.EventArgs e)
{
Stream imgStream = null;
Assembly a = Assembly.GetExecutingAssembly();
string [] resNames = a.GetManifestResourceNames();
foreach(string s in resNames)
{
if(s.EndsWith(".ico"))
{
string s2 = "test2.icon1.ico";
imgStream = a.GetManifestResourceStream(s2);

if( !(null==imgStream) )
{
System.Drawing.Icon ico = new Icon(imgStream);
this.Icon = ico ;
}
}
}
}
}
}

This code is stored in Form1.cs and added to a project called test2. It
also needs an embedded icon file called icon1.ico.

If this program is executed with:

imgStream = a.GetManifestResourceStream(s2);

The program will work from Visual Studio 2003 but not at a command line
using csc to compile.

If this program is executed with:

imgStream = a.GetManifestResourceStream(s);

The program will execute properly from Visual Studio 2003 and at a command
line using csc.

Thanks for the help.

Feb 28 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Grant Edwards | last post by:
I'm trying in vain to set the icon for the executable generated by py2exe. According to various sources there are two answers: 1) Do it on the command line: python setup.py py2exe --icon...
4
by: Tim Jarman | last post by:
Apologies in advance for the long post - I wanted to be sure I included all the relevant details. The answer is probably very, very simple. I am doing something stupid here, but I don't know what...
2
by: swp | last post by:
I have a site created using ASP, HTML, and JavaScript. I use frames to manage a few things, and requires SSL to connect. The site is on a secured network, not meant to be cross-browser...
4
by: solex | last post by:
Hello, I am in the process of converting a project from VB6 to DotNet and have noticed that some strange behavior with the TreeView Control (1) when setting the NodeFont property to Bold I...
4
by: ljlevend | last post by:
I have the following issues: 1. I want to make it so that ToolTips never go away once they are shown until the user moves the mouse outside of the control for which the ToolTip is assigned. It...
5
by: michael sorens | last post by:
(1) By setting an icon in my Windows Form properties, I successfully display my custom icon when my application is executed. However, as soon as I open the Options form in my application--now...
3
by: senfo | last post by:
I developed a Windows control in VS 2005 that inherits from the PictureBox Control that adds the ability to select images in a Windows application. It is, however, experiencing a strange issue...
1
Plater
by: Plater | last post by:
C# (and possibly VB.NET) in VS2005 can be a bit tricky. Here's my little rundown: Add an icon file to your project (new or exisiting, whichever) Open the icon file is VS and edit as desired....
0
by: Lie | last post by:
Yesterday I installed compiz-icon in my Ubuntu. Today, when I go to the python interpreter, I happen to do this: ### START OF PYTHON SESSION ### Python 2.5.2 (r252:60911, Apr 21 2008, 11:17:30)...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.