|
-
Feb 22nd, 2003, 01:38 PM
#1
Thread Starter
Junior Member
Changing the FlatStyle property at runtime
I wrote a couple of functions that will change the FlatStyle property of all form controls to System automatically at runtime (to give my applications a Windows XP look).
I had written it in VB actually and converted it into C#. The C# code does not work. My application compiles without any errors but the FlatStyle property does not change. I would appreciate it if anyone could help me debug this code.
Code:
// Put these two static methods in any of your classes to use them.
using System;
using System.IO;
using System.Windows.Forms;
public static void XPStyle(Form FRM)
{
if (Environment.OSVersion.Version.Major > 4 &&
Environment.OSVersion.Version.Minor > 0 &&
File.Exists(Application.ExecutablePath + ".manifest"))
{
for (int x = 0; x < FRM.Controls.Count; x++)
{
if (FRM.Controls[x].GetType() == typeof(ButtonBase))
{
((ButtonBase) FRM.Controls[x]).FlatStyle = FlatStyle.System;
}
if (FRM.Controls[x].GetType() == typeof(GroupBox))
{
((GroupBox) FRM.Controls[x]).FlatStyle = FlatStyle.System;
}
if (FRM.Controls[x].GetType() == typeof(Label))
{
((Label) FRM.Controls[x]).FlatStyle = FlatStyle.System;
}
RecursiveXPStyle(FRM.Controls[x]);
}
}
}
private static void RecursiveXPStyle(Control CTR)
{
for (int x = 0; x < CTR.Controls.Count; x++)
{
if (CTR.Controls[x].GetType() == typeof(ButtonBase))
{
((ButtonBase) CTR.Controls[x]).FlatStyle = FlatStyle.System;
}
if (CTR.Controls[x].GetType() == typeof(GroupBox))
{
((GroupBox) CTR.Controls[x]).FlatStyle = System;
}
if (CTR.Controls[x].GetType() == typeof(Label))
{
((Label) CTR.Controls[x]).FlatStyle = System;
}
if (CTR.Controls.Count > 0)
{
RecursiveXPStyle(CTR.Controls[x]);
}
}
}
-
Feb 22nd, 2003, 01:52 PM
#2
Frenzied Member
There is no need for that, just include the manifest into the exe, and set the control properties to system.
Dont gain the world and lose your soul
-
Feb 22nd, 2003, 02:24 PM
#3
Thread Starter
Junior Member
Originally posted by DevGrp
There is no need for that, just include the manifest into the exe, and set the control properties to system.
That is a nice reply
I could do that, but I want to do it programatically.
-
Feb 22nd, 2003, 04:42 PM
#4
Frenzied Member
Dude first rule of programming. KISS, keep it small simple.
Dont gain the world and lose your soul
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|