XP style GUI for winform

G

Guest

Hi,
Is your operating system windows XP ?If it is windows 2000 or lesser than
that then you want be able to apply windows XP look and feel(easily) to your
..NET Application as windows 2000 came before windows XP and it does not have
UXTheme.dll.
 
M

Morten Wennevik [C# MVP]

hi i m using .net 2003 and winform application, i m using below article to
make my application winform outlook like xp style, but it does not shows
controls on my winform as xp style , but it shows messagebox(using
MessageBx.Show("dd")) like xp style, what i m missing , how to make my
winform button also behave lik xp style.
http://msdn2.microsoft.com/en-us/li...visualstyleswithcontrolsonwindowsformsanchor7

thanks in advance.

Hi Tasleem,

That was an overly complicated article written five years ago. I haven't tested it, but I noticed it didn't mention what I learnt on how to xp-enable VS 2003 projects, which is

1) Add "Application.EnableVisualStyles();" before Application.Run in the Main method
2) Set FlatStyle to FlatStyle.System on each control.

I seem to remember this not working on all controls, and ProgressBar does not have a FlatStyle, but it got XP-enabled anyway.

As mentioned in another reply, on Windows 2000, you need to enable xp-styles on the system as well.
 
G

Guest

hi thanks for reply i m using windows XP and it shows xp style to button on
Messageboxes but not button on winform.
 
K

Kevin S Gallagher

Try the following code placed into a code module. As coded you need your
main form to be named "frmMainForm". Note the line
MakeSystemStyle(mMainForm) will go through each control and set FlatStyle =
True which needs to be done for the XP look to work as expected. Hope this
helps.

BTW SetProperty is not mine, it came from a programmer who I can not
remember his name but he is one of the gurus here.


Imports System
Imports System.Drawing
Imports System.Windows.Forms

Module StartUp
Friend mMainForm As frmMainForm
Public Class DOR
Inherits System.Windows.Forms.Form
<System.STAThread()> Public Shared Sub Main()
'
' Permit Visual XP Styling
'
System.Windows.Forms.Application.EnableVisualStyles()
'
' Required for implementing XP Styling...as per above has a bug in
..NET 1.1
'
Application.DoEvents()
'
' Set up access via the Class Program below which allows us to
access
' items on the frmMainForm from a child form.
'
mMainForm = New frmMainForm
mMainForm.StartPosition =
System.Windows.Forms.FormStartPosition.CenterScreen
'
' MakeSystemStyle in short goes through "every" control on the
passed form
' and if a control has the 'FlatStyle' property it is set to
[System style]
' which in turns permits XP styling coupled with The first lin in
the procedure.
'
MakeSystemStyle(mMainForm)
'
' Fire up the main form
'
System.Windows.Forms.Application.Run(mMainForm)
Application.DoEvents()
End Sub
End Class

Public Class Program
Public Shared ReadOnly Property MainForm() As frmMainForm
Get
Return mMainForm
End Get
End Property
Public Shared ReadOnly Property ApplicationPath() As String
Get
Return Application.StartupPath()
End Get
End Property
End Class
Private Function SetProperty(ByVal objUnknown As Object, ByVal
propertyName As String, ByVal ObjectValue As Object) As Boolean
Try
Dim PropInfo As System.Reflection.PropertyInfo =
objUnknown.GetType().GetProperty(propertyName)
If PropInfo Is Nothing Then Return False
ObjectValue = Convert.ChangeType(ObjectValue,
PropInfo.PropertyType)
PropInfo.SetValue(objUnknown, ObjectValue, Nothing)
Return True
Catch
Return False
End Try
End Function
Public Sub MakeSystemStyle(ByVal ParamArray TheForm() As Control)
Dim ControlItem As Control
For Each ControlItem In TheForm
SetProperty(ControlItem, "FlatStyle",
System.Windows.Forms.FlatStyle.System)
Dim c As Control
For Each c In ControlItem.Controls
MakeSystemStyle(c)
Next
Next
End Sub
End Module
 

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

Top