🖥️ Introduction
In this guide, you'll learn how to change the background color of a Windows Forms (WinForms) application using both Visual Basic .NET and C# in Visual Studio. Additionally, we will explore how to enhance the form with a textured background using a custom class library. This tutorial is based on the .NET Framework 4.8.1.
🔹 1. Change Background via Form Properties
The easiest way to change the form background color is through the Properties Window in Visual Studio.
- Select your Form in the Designer
- In the Properties panel, find BackColor
- Choose any color from the color picker
🔸 2. Change Background via Code
VB.NET
Public Class MainForm
Private Sub MainForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.BackColor = Color.LightSkyBlue
End Sub
End Class
C#
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
this.BackColor = Color.LightSkyBlue;
}
}
🎨 3. Add Texture to WinForms Background
For more advanced UI, you can paint a texture instead of using a solid color. We’ve created a free open-source library that applies procedural textures to WinForms controls.
GitHub Repository: VBTexturePainter
Usage Example in VB.NET
Imports VBTexturePainter
Public Class MainForm
Private Sub MainForm_Paint(sender As Object, e As PaintEventArgs) Handles MyBase.Paint
Dim painter As New TextureBackgroundPainter()
painter.PaintDottedBackground(Me, e.Graphics)
End Sub
End Class
Usage Example in C#
using VBTexturePainter;
public partial class MainForm : Form
{
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
var painter = new TextureBackgroundPainter();
painter.PaintDottedBackground(this, e.Graphics);
}
}
📌 Why Use Texture?
- Improves UI appeal without loading external images
- Reduces memory overhead compared to image-based textures
- Reusable across any WinForms controls
💡 Conclusion
Whether you are a beginner or an advanced developer, enhancing the UI of your desktop apps can significantly improve user experience. Start by changing the color, then move to advanced techniques like procedural textures.
🔗 Explore More
♥ Here are some online Visual Basic lessons and courses:
No comments:
Post a Comment