wa22guy Posted October 22, 2004 Share Posted October 22, 2004 How can I make my c# app recognize XP themes and display the controls correctly according to the theme? Ethan Link to comment Share on other sites More sharing options...
0 Winston Posted October 22, 2004 Share Posted October 22, 2004 For text boxes and buttons and some other controls you need to change the FlatStyle property, lol waiti forgot what the property name is... but yeah and inside the constructor after the initialize component call, you add Application.EnableVisualStyles(); however, there has been random issues in the past with this method call, causing conflicts with third party controls etc, so it might be better to just include a .manifest file. Link to comment Share on other sites More sharing options...
0 lostspyder Posted October 22, 2004 Share Posted October 22, 2004 You need to add an XP manifest and use soemthing like the WinXpStyle Class http://www.codeproject.com/csharp/HugoWinXpStyle.asp Link to comment Share on other sites More sharing options...
0 wa22guy Posted October 22, 2004 Author Share Posted October 22, 2004 You need to add an XP manifest and use soemthing like the WinXpStyle Classhttp://www.codeproject.com/csharp/HugoWinXpStyle.asp 584783255[/snapback] Hmm, not working for me and I don't know why. I can set the styles to Flat, Popup, etc but it just won't switch over to my Media Center theme. Any ideas on why? Link to comment Share on other sites More sharing options...
0 STV Posted October 22, 2004 Share Posted October 22, 2004 if you are using .net 1.1 then set the flat style property to system. then add Application.EnableVisualStyles(); before you call Application.Run(); this is basically what Winston said, but i thought that I should clarify a bit. STV Link to comment Share on other sites More sharing options...
0 MrRogers Posted October 23, 2004 Share Posted October 23, 2004 Check this out. It helped me with some quirks with EnableVisualStyles. http://www.thecodeproject.com/buglist/Enab...alStylesBug.asp In my opinion it's still tons easier than making a manefest file. Link to comment Share on other sites More sharing options...
0 azcodemonkey Posted October 23, 2004 Share Posted October 23, 2004 Check this out. It helped me with some quirks with EnableVisualStyles.http://www.thecodeproject.com/buglist/Enab...alStylesBug.asp In my opinion it's still tons easier than making a manefest file. 584792139[/snapback] That's really cool. Link to comment Share on other sites More sharing options...
0 wa22guy Posted October 23, 2004 Author Share Posted October 23, 2004 I just found out that all you need is two lines: Application.EnableVisualStyles(); Application.DoEvents(); EASY. Link to comment Share on other sites More sharing options...
0 Winston Posted October 23, 2004 Share Posted October 23, 2004 Hmmmm funny fix, btw out of curiosity where exactly is the call for Application.Run(); inside a normal VB form? :s Link to comment Share on other sites More sharing options...
0 anog Posted October 23, 2004 Share Posted October 23, 2004 Right at the very top ;) #Region " Windows Form Designer generated code " Public Sub New() ?MyBase.New() ?Application.EnableVisualStyles() ?Application.DoEvents() ?'This call is required by the Windows Form Designer. ?InitializeComponent() ?'Add any initialization after the InitializeComponent() call End Sub edit: This isn't "application.run", but I guess this was what u're looking for... or am I wrong?? Link to comment Share on other sites More sharing options...
0 wa22guy Posted October 24, 2004 Author Share Posted October 24, 2004 Hmmmm funny fix, btw out of curiosity where exactly is the call for Application.Run(); inside a normal VB form? :s 584794234[/snapback] This is all you have to have. Make sure you set the FlatStyle property of your controls (like buttons, checkboxes, etc.) to System instead of Standard on your form. [STAThread] static void Main() { Application.EnableVisualStyles(); Application.DoEvents(); Application.Run(new frmMain()); } Link to comment Share on other sites More sharing options...
0 Winston Posted October 24, 2004 Share Posted October 24, 2004 Right at the very top ;) #Region " Windows Form Designer generated code " Public Sub New() ?MyBase.New() ?Application.EnableVisualStyles() ?Application.DoEvents() ?'This call is required by the Windows Form Designer. ?InitializeComponent() ?'Add any initialization after the InitializeComponent() call End Sub edit: This isn't "application.run", but I guess this was what u're looking for... or am I wrong?? 584794259[/snapback] not what i was looking for, i wanted to see where the Application.run call was made inside the form. Link to comment Share on other sites More sharing options...
0 wa22guy Posted October 24, 2004 Author Share Posted October 24, 2004 not what i was looking for, i wanted to see where the Application.run call was made inside the form. 584795032[/snapback] Look at my post 2 posts above this one. Link to comment Share on other sites More sharing options...
0 Winston Posted October 24, 2004 Share Posted October 24, 2004 Look at my post 2 posts above this one. 584795065[/snapback] lol look at my original question, thanks anyways, your one is in c#, i'm just asking a question about vb Link to comment Share on other sites More sharing options...
0 wa22guy Posted October 24, 2004 Author Share Posted October 24, 2004 Ohhh... i think it's in the Windows Generated Code. Not sure though. Link to comment Share on other sites More sharing options...
0 John Veteran Posted October 24, 2004 Veteran Share Posted October 24, 2004 Hmmmm funny fix, btw out of curiosity where exactly is the call for Application.Run(); inside a normal VB form? :s 584794234[/snapback] Set your startup object to Sub Main, and create your own Main. Inside there, add the call to Application.Run (Y) Link to comment Share on other sites More sharing options...
0 Winston Posted October 24, 2004 Share Posted October 24, 2004 Set your startup object to Sub Main, and create your own Main. Inside there, add the call to Application.Run (Y) 584795220[/snapback] lol arggh that still doesn't answer my question, i know how to do that, but where is the Application.Run call when the startup object is set to a form. Link to comment Share on other sites More sharing options...
0 John Veteran Posted October 24, 2004 Veteran Share Posted October 24, 2004 It doesn't exist, it's created by the VB compiler and ends up somewhere in the IL. Or in other words, I don't know and I don't think you can access it with VB code :p Link to comment Share on other sites More sharing options...
0 azcodemonkey Posted October 24, 2004 Share Posted October 24, 2004 lol arggh that still doesn't answer my question, i know how to do that, but where is the Application.Run call when the startup object is set to a form. 584795565[/snapback] It isn't defined by default, but you can add it manually. Just add this to your startup form. <STAThread()> _ Public Shared Sub Main() Dim myForm As New Form1 Application.EnableVisualStyles() Application.DoEvents() Application.Run(myForm) End Sub Link to comment Share on other sites More sharing options...
0 Winston Posted October 24, 2004 Share Posted October 24, 2004 It isn't defined by default, but you can add it manually. Just add this to your startup form. ? ?<STAThread()> _ ? ?Public Shared Sub Main() ? ? ? ?Dim myForm As New Form1 ? ? ? ?Application.EnableVisualStyles() ? ? ? ?Application.DoEvents() ? ? ? ?Application.Run(myForm) ? ?End Sub 584795892[/snapback] mmmm but since Application.Run is mysteriously invoked apparently, then wouldnt this second call, cause you to make another form? One more thing, what's <:sTAThread()> for? :s does it do anything, i never understand what items inclosed in relational signs i.e. <,> mean, aren't they the way to comment code so that you can generate XML Documentation? Link to comment Share on other sites More sharing options...
0 azcodemonkey Posted October 24, 2004 Share Posted October 24, 2004 mmmm but since Application.Run is mysteriously invoked apparently, then wouldnt this second call, cause you to make another form? One more thing, what's <STAThread()> for? :s does it do anything, i never understand what items inclosed in relational signs i.e. <,> mean, aren't they the way to comment code so that you can generate XML Documentation? 584796067[/snapback] No, I just tested adding my own sub main to a VB.NET Windows application. It worked fine and did the visual styles correctly. STAThread is an attribute that tells whomever asks that the app is compatible with single threaded apartments. It's a COM thing. You could probably safely remove the attribute. You use attributes to allow more robust queries through reflection. I could query this assembly for it's attributes and find that it is STAThread safe. Attributes are metadata for both the compiler and for anyone that needs to know things about a given assembly. It's quite handy. My company uses attributes for an object repository framework. Link to comment Share on other sites More sharing options...
Question
wa22guy
How can I make my c# app recognize XP themes and display the controls correctly according to the theme?
Ethan
Link to comment
Share on other sites
20 answers to this question
Recommended Posts