Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / July 2007

Tip: Looking for answers? Try searching our database.

XP style GUI for winform

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
tasleem - 23 Jul 2007 15:10 GMT
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/library/aa289524(VS.71).aspx#vbtchusingwindowsx
pvisualstyleswithcontrolsonwindowsformsanchor7


thanks in advance.
Manish Bafna - 23 Jul 2007 15:58 GMT
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.
Signature

Hope this helps.
Thanks and Regards.
Manish Bafna.
MCP and MCTS.

> 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
[quoted text clipped - 4 lines]
>
> thanks in advance.
tasleem - 23 Jul 2007 17:10 GMT
hi thanks for reply i m using windows XP and it shows xp style to button on
Messageboxes but not button on winform.

> Hi,
> Is your operating system windows XP ?If it is windows 2000 or lesser than
[quoted text clipped - 10 lines]
> >
> > thanks in advance.
Morten Wennevik [C# MVP] - 23 Jul 2007 17:09 GMT
> 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
[quoted text clipped - 4 lines]
>
> 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.

Signature

Happy coding!
Morten Wennevik [C# MVP]

Ravi Bhavnani - 25 Jul 2007 03:59 GMT
See this article:

http://csharpstruggles.blogspot.com/2005/04/using-xp-style-themes-in-visual-stud
io_01.html


/ravi

--------------
> 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
[quoted text clipped - 4 lines]
>
> thanks in advance.
Kevin S Gallagher - 25 Jul 2007 20:58 GMT
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

> 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
[quoted text clipped - 4 lines]
>
> thanks in advance.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.