Setting Control Properties in C# WinForms

Colors, Fonts, and Layout in Windows Forms

Windows Forms gives you full control over how your app looks. Beyond just adding buttons and textboxes, you can customize their colour, font, alignment, and layout β€” all in code or using the Visual Studio designer.


🧰 Why Customize UI Properties?

Customizing control properties helps:

  • Improve readability and usability
  • Match your app’s style or brand
  • Make interfaces kid-friendly, professional, or fun

πŸš€ Getting Started

πŸ›  Requirements:

  • Visual Studio 2022+
  • Windows Forms App (.NET) project

βœ… Controls like Label, Button, and TextBox come with dozens of tweakable properties.


✏️ Key Properties to Customize

PropertyWhat it does
.BackColourBackground colour of the control
.ForeColourText colour
.FontFont family, size, and style
.TextAlignText alignment (for Label, Button)
.SizeWidth and height in pixels
.LocationX/Y position of the control
.AnchorAnchors to edges for resizing
.DockAutomatically dock to edges of the form
.PaddingSpace inside the control
.MarginSpace outside the control

βš™οΈ Example: Custom Styled Label

Label title = new Label();
title.Text = "Welcome to My App!";
title.Font = new Font("Segoe UI", 16, FontStyle.Bold);
title.ForeColor = Color.White;
title.BackColor = Color.Navy;
title.AutoSize = true;
title.Location = new Point(20, 20);
this.Controls.Add(title);

βœ… This makes a bold, white-on-blue heading label.


πŸ–Œ Customize a Button

Button playButton = new Button();
playButton.Text = "Play";
playButton.Size = new Size(100, 40);
playButton.Font = new Font("Comic Sans MS", 12, FontStyle.Italic);
playButton.BackColor = Color.LightGreen;
playButton.ForeColor = Color.DarkGreen;
playButton.Location = new Point(50, 80);
this.Controls.Add(playButton);

This adds a fun, styled button with custom fonts and colors.


🎯 Layout Tips

  • Use .Anchor to keep controls pinned when resizing: myControl.Anchor = AnchorStyles.Top | AnchorStyles.Right;
  • Use .Dock to make a control fill or stick to a side: myControl.Dock = DockStyle.Top;
  • .Padding and .Margin fine-tune spacing, especially inside Panel or GroupBox.

πŸ§ͺ Quick Challenge

🧩 Create a color-themed app with:

  • A Label with large, bold red text
  • A Button with a green background and white text
  • A TextBox with a light yellow background and blue text

πŸ’‘ Hint: Set .ForeColor, .BackColor, and .Font on each


πŸ–Ό Visual Sample (Design Concept)

-----------------------------------------
| Welcome to My Game!                   |  ← Big red label
|                                       |
| [__________]                          |  ← Textbox (yellow with blue text)
|                                       |
|       [    Play Game    ]             |  ← Green button with white text
-----------------------------------------

πŸ“š Summary

ConceptDescription
.BackColorControl background colour
.ForeColorText colour
.FontCustom font settings
.LocationX/Y position on form
.SizeWidth & height in pixels
.AnchorSticks control to form edge on resize
.DockLocks control to a side or fills the form

πŸŽ“ Want to Style More?

Next steps:

  • Add icons to buttons (button.Image)
  • Create custom controls with user-drawn styles
  • Style multiple forms with consistent themes
  • Use TableLayoutPanel or FlowLayoutPanel for dynamic layouts

πŸ’¬ Want help making your app colorful and fun? Contact us
Let’s build beautiful, interactive UIs β€” one button at a time!