ARTICLE

Themes in windows forms

Posted by mihir soni Articles | Visual Basic 2010 October 26, 2009
Here I am going to describe, how to change all GUI formatting with class file.
 
Reader Level:

Hello friends now I am going to write my first articles.

Here I m trying to explain, how to change the whole project theme by just changing the main theme file in VB.NET project.

What this code actually does is that it visit all the windows form control on the form and set the properties of the control so if you have 100 forms and want to change the GUI or color of the button or anything else you can by changing in only one file.
 
Here is the code.

Public
Class colour

    Public Shared Sub colordesign(ByRef formc As Form)

        formc.BackColor = Color.WhiteSmoke

        Dim ct As Control = formc.GetNextControl(formc, True) 'This will take the first control from the form

        Do Until ct Is Nothing 

            If TypeOf ctl Is GroupBox Then 'This will set the settings for all groupbox in form                

                ct.BackColor = Color.Silver 'This will change the color of all the group box.              

                Dim myfont As System.Drawing.Font

                myfont = New System.Drawing.Font("Microsoft Sans Serif", 9, FontStyle.Bold, GraphicsUnit.Point)

                ctl.Font = myfont 'You can set the font             

                ctl.ForeColor = Color.Black

            End If

            'If TypeOf ctl Is Label Then 'This will set the all settings for the Label.          

            '    Dim myfont As System.Drawing.Font           

            '    myfont = New System.Drawing.Font("Microsoft Sans Serif", FontStyle.Bold, GraphicsUnit.Point) 

            '    ctl.ForeColor = Color.Black           

            'End If          

            If TypeOf ctl Is Button Then

                ctl.BackColor = Color.Gray

                ctl.ForeColor = Color.Snow

                Dim myfont As System.Drawing.Font

                myfont = New System.Drawing.Font("Arial", 12, FontStyle.Bold)

                ctl.Font = myfont

                ctl.Height = 29

            End If

            ctl = formx.GetNextControl(ctl, True) 'after checking the first control take the next control in the form.       

        Loop

    End Sub

End Class

Now you can customize with any number of windows form which are basically used in all the forms and set all the properties from the class file.

Hope you all like this article.

Login to add your contents and source code to this article
share this article :
post comment
 

im newby ,
please help me , how to begin to vb.net

Posted by ohdo lom Aug 15, 2010
Nevron Diagram
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Become a Sponsor