Problem with EnabelVisualStyles and displaying ToolBarButtons

R

Richard Faust

Hi,

After adding the Application.EnableVisualStyles() in the Main-Method of
my application, i got some strange problems
with ToolBarButtons. When the Image of the button is set during
designtime everything's ok. But all the buttons
which load their image during runtime from an ImageList and/or are
dynamicaly created have the following problems:
In default-state the button is invisible, in down-state too, but the
border higlight of the mouseover-state works.
Image is not displayed in either state.

Thanks for any help!
Martin

PS: Sorry for my bad english, but the german community is far too small
at the moment ;)
 
L

Linda Liu[MSFT]

Hi Martin,

I performed some tests based on your description but didn't reproduce the
problem on my side.

The steps of my test are as follows:

1. Create a new Windows Application project
2. In the static Main method, add this line of code:
Application.EnableVisualStyles();
3. Drag two ToolBar controls from Toolbox onto the Form1
4. Drag two ImageLists to Form1
5. Insert some images into the two ImageLists
6. Assign imageList1 to ToolBar1
7. Insert some ToolBarButtons to the toolBar1. Set ImageIndex property for
each button, the image is immediately shown up
8. Add a Button to the Form1and in the Click event handler of this button,
add the following lines of code:

private void button1_Click(object sender, System.EventArgs e)
{
ToolBarButton b1 = new ToolBarButton();
b1.ImageIndex = 1;
this.toolBar2.ImageList = this.imageList2;
this.toolBar2.Buttons.Add(b1);
}

10. Build the project and run it. When I click the button on the
Form1, a ToolBarButton appears in the ToolBar2 with the specified image.

I performed tests in both VS.NET 2003 and VS2005 and got the same result.
The OS of my test machine is Windows Server 2003.

What version of Visual Studio are you using?
What's the OS version on your machine?
Is there any difference between your project and mine?

If the problem still not solved, could you please show us the relevant code
snippet or reproduce the problem in a simple project and send it to me? To
get my actual email address, remove 'online' from my displayed email
address.

I look forward to your reply.

Sincerely,
Linda Liu
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
R

Richard Faust

Linda said:
1. Create a new Windows Application project
2. In the static Main method, add this line of code:
Application.EnableVisualStyles();
3. Drag two ToolBar controls from Toolbox onto the Form1
4. Drag two ImageLists to Form1
5. Insert some images into the two ImageLists
6. Assign imageList1 to ToolBar1
7. Insert some ToolBarButtons to the toolBar1. Set ImageIndex property for
each button, the image is immediately shown up
8. Add a Button to the Form1and in the Click event handler of this button,
add the following lines of code:

private void button1_Click(object sender, System.EventArgs e)
{
ToolBarButton b1 = new ToolBarButton();
b1.ImageIndex = 1;
this.toolBar2.ImageList = this.imageList2;
this.toolBar2.Buttons.Add(b1);
}

10. Build the project and run it. When I click the button on the
Form1, a ToolBarButton appears in the ToolBar2 with the specified image.

Hi Linda,

The problem occured only when adding the EnableVisualStyles() to an
older project which was originaly not designed for that case i think.
Since the project is very complex in architecture and i'm not one of the
initial developers i have no clue where the problem did came from.

I just remade the ToolBar from scratch once again following your steps
and now everything works as it is supposed to be, even if i can't see
any difference in the code.

Just FYI:
Windows XP Home (wrong coice for a developer, i'll change that ;)
Visual Studio 2005, .Net Framework 2

Anyway, thank you very much for your help!
 
R

Richard Faust

p.s. I'm not sure why you apologized for your English...you write
better than many native speakers do. :)

Hi Pete,

Thanks for the compliment, guess I always underestimate myself a bit ;)
That said, I'll make a wild guess: there's something about the older
project that initializes something important before the line you added
that calls Application.EnableVisualStyles(). Possibly in a DLL
initialization entry point or something like that, which would be less
obvious than something called by your application entry point.

Well, so far I'm happy with my remade (working) ToolBar, but i'll have a
look at that. When I'm able to pinpoint something out i'll make another
post.

Thanks for the directions :)
Martin
 
L

Linda Liu[MSFT]

Hi Martin,

Thank you for your reply!

For now, I will close this issue in the newsgroup. If you have new findings
to this problem later, you may reopen this post or post another thread and
we will work with you at that time.

Thank you for using our MSDN Managed Newsgroup Support Service!

Sincerely,
Linda Liu
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top