Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 132,685 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 1,264 people online right now. Registration is fast and FREE... Join Now!




CSS type style standardization for WinForms

 
Reply to this topicStart new topic

CSS type style standardization for WinForms

redivider
post 30 May, 2008 - 03:09 PM
Post #1


New D.I.C Head

*
Joined: 28 May, 2008
Posts: 10

I'm developing a Windows application that will end up fairly large. Is there a way to implement a standardization (like Headers are 12pt font and blue, groupbox labels are 13pt font....).
I've tried creating a new class
CODE
class LabelGroupBox : Label

but font cannot be inherited from Label, so it does me no good.

Am I really stuck with setting the display on the fly (where I won't see the actual look during design, or through DesignView, where I'll spend 3 hours updating fonts if I want to change the look?
User is offlineProfile CardPM

Go to the top of the page

Martyr2
post 31 May, 2008 - 09:19 PM
Post #2


Programming Theoretician

Group Icon
Joined: 18 Apr, 2007
Posts: 5,062



Thanked 177 times

Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions


Font can't be, but you can certainly create your own control based on inheriting another control. Here is a small example. We inherit from a basic label to create a new control called "newlabel". It will act exactly like a label but it will have its own font and colors etc. In our example we make a label that is 14 em sized Arial font that is Aqua in color.

csharp

// Our new label control inherits from Label.
public class newlabel : Label {
// Our constructor to set this control upon creation
public newlabel()
{
this.Font = new Font("Arial", 14);
this.ForeColor = Color.Aqua;
}
}


Then all we need to do is create the control when we startup a form or hit a button or whatever.

csharp

private void Form1_Load(object sender, EventArgs e)
{
// Create a new label control, set it to be in the top left corner of the form
// at position 10, 10 with our new label text and lastly add it to the form.

// We will then have a control that is there and ready to go.
newlabel test = new newlabel();
test.Left = 10;
test.Top = 10;
test.Text = "My new label";

this.Controls.Add(test);

}


Now of course this isn't a control in your toolbox but you can certainly make one of those inherited from label or another control and add your own functionality. It is up to you. This is just a taste that it is possible to enforce your own styling on a control.

Hope this shows you the possibilities. Enjoy!

"At DIC we be control inheriting code ninjas... and no we don't inherit male pattern baldness" decap.gif

User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/23/08 07:09AM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month