471,330 Members | 1,499 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Problem with EnabelVisualStyles and displaying ToolBarButtons

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 ;)
Jun 27 '08 #1
5 951
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:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.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/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Jun 27 '08 #2
Linda Liu[MSFT] schrieb:
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!


Jun 27 '08 #3
On Wed, 07 May 2008 07:28:47 -0700, Richard Faust
<so*********@community.nospamwrote:
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.
Without a concise-but-complete code example that reliably reproduces the
problem, it's nearly impossible to answer your question. Especially when
you yourself have confirmed that you yourself cannot reproduce the problem
with a brand new project.

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.

I think that's the sort of thing you'll want to look for. Other than
that, unless you can provide a concise-but-complete code example, I'm not
hopeful that anyone would be able to answer the question.

Pete

p.s. I'm not sure why you apologized for your English...you write better
than many native speakers do. :)
Jun 27 '08 #4
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
Jun 27 '08 #5
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:
ms****@microsoft.com.

This posting is provided "AS IS" with no warranties, and confers no rights.
Jun 27 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Ramesh | last post: by
2 posts views Thread by Balamurali C | last post: by
6 posts views Thread by Ammar | last post: by
2 posts views Thread by Fedor G via DotNetMonster.com | last post: by
2 posts views Thread by lottoman | last post: by
1 post views Thread by Maanav Jackson | last post: by
reply views Thread by rosydwin | last post: by

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.