Visual Styles and Button Images

C

Curtis Wellborn

Hey,
I have come into a bit of a problem.
When Flatsyle is on system it will not show my images that i have set
in image list or just in image.
Also somethings i have found online do not work because i coded it to
change the flatstyles(if needed) to whatever theme the user is using.
This is the code that effects it:

private void RecursivelyFormatForWinXP(Control control)
{
for(int x = 0; x < control.Controls.Count; x++)
{
// If the control derives from ButtonBase,
// set its FlatStyle property to FlatStyle.System.
if(control.Controls[x].GetType().BaseType == typeof(ButtonBase))
{
((ButtonBase)control.Controls[x]).FlatStyle = FlatStyle.System;
}

// If the control holds other controls, iterate through them also.
if(control.Controls.Count > 0)
{
RecursivelyFormatForWinXP(control.Controls[x]);
}
}
}

and...

private void frmNonPOReceiptsEntry_Load(object sender,
System.EventArgs e)
{
// Makes sure Windows XP is running and
// a .manifest file exists for the EXE.
if(Environment.OSVersion.Version.Major > 4
& Environment.OSVersion.Version.Minor > 0
& System.IO.File.Exists(Application.ExecutablePath + ".manifest"))
{
// Iterate through the controls.
for(int x = 0; x < this.Controls.Count; x++)
{
// If the control derives from ButtonBase,
// set its FlatStyle property to FlatStyle.System.
if(this.Controls[x].GetType().BaseType == typeof(ButtonBase))
{
((ButtonBase)this.Controls[x]).FlatStyle = FlatStyle.System;
}
RecursivelyFormatForWinXP(this.Controls[x]);
}
}
}

So my question is how do i get my own images to show up on the
buttons?(if possible by using my image list)

Thank you to whoever can help.
 
G

Guest

Hi,

I had a similar problem with tool tip buttons and a treeview that were loosing their images when using FlatStyle.System. I've solved my problem by calling Application.DoEvents() after calling Application.EnableVisualStyles() eg.

Application.EnableVisualStyles();
Application.DoEvents();
Application.Run(new MyForm());

I cant remember which post I got this from but its out there somewhere.

Hope this helps

Scott
 
C

Curtis Wellborn

Yea see i have thought of that before but there is one problem. I call
my flatstyles in the form load because Im not always going to have it on
XP style. I have it finding what theme they use and having that play a
part. So my code on when to change my flatstyle and what to change it to
is in form load. So in form load once it finds the style then my immages
are taken away. If you knwo anything else or anyone who can help let me
know.

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
 

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

Similar Threads

Visual Styles 9
XP visual style 3
XP visual style 4
IHTMLDocument2, HTMLImgClass and images 1
A Little Help?? 2

Top