473,626 Members | 3,325 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 GetManifestReso urceNames(), I store
the name in a string variable called s. The value of s is "test2.icon1.ic o".
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.ic o" in it. When I use s2 instead of s as a parameter to
GetManifestReso urceSteam, 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 GetManifestReso urceString() 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.Collecti ons;
using System.Componen tModel;
using System.Windows. Forms;
using System.Data;
using System.Reflecti on;
using System.IO;
using System.Diagnost ics;

namespace test2
{
public class Form1 : System.Windows. Forms.Form
{
private System.Componen tModel.Containe r components = null;

public Form1()
{
InitializeCompo nent();
}

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

private void InitializeCompo nent()
{
this.Load += new System.EventHan dler(this.Form1 _Load);
}

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

private void Form1_Load(obje ct sender, System.EventArg s e)
{
Stream imgStream = null;
Assembly a = Assembly.GetExe cutingAssembly( );
string [] resNames = a.GetManifestRe sourceNames();
foreach(string s in resNames)
{
if(s.EndsWith(" .ico"))
{
string s2 = "test2.icon1.ic o";
imgStream = a.GetManifestRe sourceStream(s2 );

if( !(null==imgStre am) )
{
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.GetManifestRe sourceStream(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.GetManifestRe sourceStream(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 2290
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 GetManifestReso urceNames(), I store
the name in a string variable called s. The value of s is "test2.icon1.ic o".
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.ic o" in it. When I use s2 instead of s as a parameter to
GetManifestReso urceSteam, 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 GetManifestReso urceString() 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.Collecti ons;
using System.Componen tModel;
using System.Windows. Forms;
using System.Data;
using System.Reflecti on;
using System.IO;
using System.Diagnost ics;

namespace test2
{
public class Form1 : System.Windows. Forms.Form
{
private System.Componen tModel.Containe r components = null;

public Form1()
{
InitializeCompo nent();
}

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

private void InitializeCompo nent()
{
this.Load += new System.EventHan dler(this.Form1 _Load);
}

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

private void Form1_Load(obje ct sender, System.EventArg s e)
{
Stream imgStream = null;
Assembly a = Assembly.GetExe cutingAssembly( );
string [] resNames = a.GetManifestRe sourceNames();
foreach(string s in resNames)
{
if(s.EndsWith(" .ico"))
{
string s2 = "test2.icon1.ic o";
imgStream = a.GetManifestRe sourceStream(s2 );

if( !(null==imgStre am) )
{
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.GetManifestRe sourceStream(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.GetManifestRe sourceStream(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
15770
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 foo.ico That generates a usage error: error: --icon not recognized
4
6353
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 it is. I'm writing an application with a Tkinter GUI (Python 2.4, Tcl/Tk 8.4.) and I want to put a custom icon on the main window. I've followed (so far as I understand it) the recipe in the eff-bot's splendid Introduction to Tkinter - see:...
2
1603
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 compatible, and only works with IE 5.5 or higher. IIS v5 is used, with all patches applied. "Keep Alives" are enabled. I have a login page that uses session variables to know things about who logged in, such as preferences and what rights they have. I...
4
1867
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 cannot see the complete text. (2) when selecting a child node that has a different icon from its parent, it takes on the parents' icon.
4
3808
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 seems to me that setting the ToolTip.AutoPopDelay to a large value (e.g., Int32.MaxValue) should acomplish this goal, but it does not. 2. I want to make it so that the ErrorProvider message is always displayed when the mouse is over the...
5
9464
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 having two windows open--they are grouped on the taskbar, but with a generic icon. Both my main form and my Option form are using the same icon. How can I use my custom icon instead of the generic icon in a .Net 2.0 C# application? (2) A standard...
3
2425
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 that I can't explain. One of the desired affects was to provide the ability to change the background color on images that were selected, as well as setting the background color back to its original color after the image had been deselected. To...
1
48055
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. (Note: On the left hand side is a small preview of the icon, extra sizes can be added to the SAME icon file there as well as cycling through existing sizes by using the Image menu.) Set your icons as desired. A 16x16 size will be used withen...
0
1230
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) on linux2 Type "help", "copyright", "credits" or "license" for more information. Welcome to Python 2.5! This is the online help utility.
0
8266
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8199
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8505
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7196
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6125
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5574
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4198
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2626
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1811
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.