Visual Styles

  • Thread starter Thread starter Curtis Wellborn
  • Start date Start date
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 does not work because i coded the
application to change the flatstyles(if needed) to whatever theme the
user is using. I call this at FORM_LOAD.
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
after the XP Visual style has been loaded?(if possible by using my image
list)

Thank you to whoever can help.

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
 
If you use the FlatStyle.System, OS will ignore the background image
property and the imagelists.

To display image is to override Paint event

//get from image list
Image test = ImageList.Images[0];
e.Graphics.DrawImage(.......);
 
button.Image = youImageList.Images;
or button.Background = youImageList.Images;
 
Hey thanks for your post. I was wondering if there is a way to do this
once and it work for all the bottons or do i have to sit here and go
through 10+ applications and change the images one by one. I have the
images selected and put on each picture...Is there a way to display the
picture that is already on the button but not displaying without doing
it one by one?



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

It depends on how you designed your form. If your buttons are derived from a
base class, change is going to be in one place (base class).

If you had placed your button dragging from toolbox, then you have to go to
individual form to make the change.
 
Hey,
I have been trying to get what you said to work. It keeps saying
Graphics doesnt exist. Where do i put the code you said to use? Do i put
it in form_load? Will you please be more specific on where to put it and
how? Also is there anything else i need to add? Sorry for the incoveince
i have just started using C# so im not really used to it yet. Thank you
so much for your help.
Oh and yes i drop each button in with my toolbox.

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
 
You have to get the graphics object in the Paint event handler of the button
not the form.
 
Im sorry i dont mean to be annoying but now it is telling me that:
"No overload for method 'DrawImage' takes '0' arguments"
What should i do now?


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

In my previous post i said that you have to use DrawImage(...). I meant that
it has some arguments.

refer this link for the list of overloaded methods for DraImage

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfSystemDrawingGraphicsClassDrawImageTopic.asp

For your purpose you may have to use

Graphics.DrawImage Method (Image, Rectangle, Rectangle, GraphicsUnit)


Example -

// Create image from file
Image newImage = Image.FromFile("myImage.jpg");

// Create rectangle for displaying image.
Rectangle destRect = new Rectangle( 100,100, 300, 300);

// Create rectangle for source image.
Rectangle srcRect = new Rectangle( 50, 50, 100, 100);

// Draw image.
e.Graphics.DrawImage(newImage, destRect, srcRect, GraphicsUnit.Pixel);
 
Im using Icons and I have an image list. This is what im having trouble
with...How do i put the IndexNum in for the name. Also if i was goin to
do it like your example could i use .ico?

*** 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

Back
Top