By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,667 Members | 1,656 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,667 IT Pros & Developers. It's quick & easy.

Toolbar's, ImageLists, and Manifest Resources

P: n/a
I have encountered a problem (most certainly a .NET bug), that, for the
life of me, I cannot figure out how to work around.

Using Visual Studio 2003, with enabled XP Visual Styles.

There are two possible scenarios here, the first one works properly,
while the 2nd one doesn't.

Scenario 1
----------
* Application opens with a notifyicon instead of a form window.

* User double clicks the notifyicon to show the main form window

* The main form window properly displays the toolbar buttons with
their respective images from the assigned ImageList. The ImageList is
populated from calls to
Assembly.GetExecutingAssembly().GetManifestResourc eStream("ns.file.ext")
-----------

Scenario 2
----------
Everything is the same as in Scenario 1, except for the following:

* Application opens with a notifyicon, same as above.

* A Timer event triggers the opening of another form window, and the
user has *not* double clicked the notifyicon to open the "main" window.
* When double clicking the notifyicon and opening the main form window,
the buttons on the toolbar do not display their images. They are
blank. This is the problem.
-----------

Also, If there is a timer tick that triggers the secondary window AFTER
the user has already opened and closed the main window, and the user
procedes to open the main window again, everything still displays as it
should.

Other than forcing the main window to open (which I do not want to do),
I absolutely cannot find a workaround for this problem. I have been
trying absolutely everything that I can think of for hours to no avail.
Any insight would be appreciated.

Nov 16 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
How are you starting the App with a NotifyIcon?
When are you loading the ImageList?
Are visual styles actually Enabled?

I just built a quick test project starting my app with an
ApplicationContext.
I fill the ImageList in the Forms load method.
I showed the form by DoubleClicking on the NotifyIcon and all was well.

I restarted the App and allowed a Timer to show the Form.
Visual Styles were not Enabled, but the Images showed up on the Toolbar
Buttons.

I then removed the EnableVisualStyles and DoEvents calls and added a
Manifest Resource to the project.
Visual Styles are now enabled and the Icons display just fine in the toolbar
whether the form is loaded by doubleClick or timer.

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
<an***********@gmail.com> wrote in message
news:11**********************@l41g2000cwc.googlegr oups.com...
I have encountered a problem (most certainly a .NET bug), that, for the
life of me, I cannot figure out how to work around.

Using Visual Studio 2003, with enabled XP Visual Styles.

There are two possible scenarios here, the first one works properly,
while the 2nd one doesn't.

Scenario 1
----------
* Application opens with a notifyicon instead of a form window.

* User double clicks the notifyicon to show the main form window

* The main form window properly displays the toolbar buttons with
their respective images from the assigned ImageList. The ImageList is
populated from calls to
Assembly.GetExecutingAssembly().GetManifestResourc eStream("ns.file.ext")
-----------

Scenario 2
----------
Everything is the same as in Scenario 1, except for the following:

* Application opens with a notifyicon, same as above.

* A Timer event triggers the opening of another form window, and the
user has *not* double clicked the notifyicon to open the "main" window.
* When double clicking the notifyicon and opening the main form window,
the buttons on the toolbar do not display their images. They are
blank. This is the problem.
-----------

Also, If there is a timer tick that triggers the secondary window AFTER
the user has already opened and closed the main window, and the user
procedes to open the main window again, everything still displays as it
should.

Other than forcing the main window to open (which I do not want to do),
I absolutely cannot find a workaround for this problem. I have been
trying absolutely everything that I can think of for hours to no avail.
Any insight would be appreciated.

Nov 16 '05 #2

P: n/a
This is my main() method:

static void Main()
{
System.Windows.Forms.Application.EnableVisualStyle s();
System.Windows.Forms.Application.DoEvents();
Loader load = new Loader();
System.Windows.Forms.Application.Run();
}

Loader() then loads the notifyicon in its constructor and sets up its
click events and menu. The main form is also instantiated in the
Loader() constructor.

The ticker is a variable in the Loader() class, and is initialized on
declaration in the class header.

The main form loads the toolbar buttons from the manifest resource
stream in its OnLoad event. I have also tried arranging this to load
up the toolbar button images in the forms instantiation, but that does
not work, either.

Note that I have created a PictureBox and used the manifest resource
stream to grab one of the icons and display it in the picture box
successfully - in the same OnLoad() method, while it didn't display in
the toolbar button.

If I'm being unclear in anything, the full source code and application
can be obtained on source forge - http://sf.net/projects/ontime

Nov 16 '05 #3

P: n/a
Looks like Application.EnableVisualStyles is doing nothing when your app
loads a form via the timer, as can be seen by looking at the radio buttons
and checkboxes on your config form.

Remove the calls to EnableVisualStyles and DoEvents from your main() method.
Rebuild your app.
Open OnTime.Exe with Visual Studio.
Import a *.manifest file into the resource table (Resource Type =
RT_MANIFEST)
Change the Id from 101 to 1.

The downside to this method is that you must add the manifest resource every
time you rebuild the app, but visual styles will work and your Icons will
show in the toolbar.

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
<an***********@gmail.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
This is my main() method:

static void Main()
{
System.Windows.Forms.Application.EnableVisualStyle s();
System.Windows.Forms.Application.DoEvents();
Loader load = new Loader();
System.Windows.Forms.Application.Run();
}

Loader() then loads the notifyicon in its constructor and sets up its
click events and menu. The main form is also instantiated in the
Loader() constructor.

The ticker is a variable in the Loader() class, and is initialized on
declaration in the class header.

The main form loads the toolbar buttons from the manifest resource
stream in its OnLoad event. I have also tried arranging this to load
up the toolbar button images in the forms instantiation, but that does
not work, either.

Note that I have created a PictureBox and used the manifest resource
stream to grab one of the icons and display it in the picture box
successfully - in the same OnLoad() method, while it didn't display in
the toolbar button.

If I'm being unclear in anything, the full source code and application
can be obtained on source forge - http://sf.net/projects/ontime

Nov 16 '05 #4

P: n/a
Mick,
That only happens when the timer event is the first thing to show a
form window. In my personal code, I overcame that by initializing
frmMain() in Loader's constructor, instead of when it was first being
shown. The EnableVisualStyles() also seems to be affected by this
whole weird form issue in this regard. I was able to work around that,
but I still haven't been able to work around the button images....

Nov 16 '05 #5

P: n/a
Adding a Manifest Resource only takes seconds and will fix it.

If you don't want to do that, then you'll have to make your ImageList a
global variable, instead of local to the form, and then assign the imagelist
to the toolbar in the load event.
In your Main() method you need to Initialize a new FrmMain, Initialize and
fill the imagelist, then show and hide/dispose the FrmMain.

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
<an***********@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Mick,
That only happens when the timer event is the first thing to show a
form window. In my personal code, I overcame that by initializing
frmMain() in Loader's constructor, instead of when it was first being
shown. The EnableVisualStyles() also seems to be affected by this
whole weird form issue in this regard. I was able to work around that,
but I still haven't been able to work around the button images....

Nov 16 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.