Place a Colored Border on a Control

Place a Colored Border on a Control

Suppose you simply want to change the border color of a control to something other than black, so you looked for the BorderColor property in the Properties Window…but it’s not there.

There is actually a very easy answer to this problem, but you’re asking the wrong question. “How to give a control a colored border” is apparently very complicated, but “How to make a control APPEAR to have a colored border,” is mindlessly easy.

The answer is to put the control in a Panel.

Simply follow these steps:

  1. Add a Panel> to your form. Make sure the BorderStyle is None. Set BackColor to the color you want as a border, red, for example. Set Padding to 1,1,1,1 for a 1 pixel wide border.
  2. Draw the control you really want, a TextBox perhaps, inside the Panel. Set BorderStyle to None and Dock to Fill.
  3. When you want to move, hide, and/or whatever to the TextBox, do it to the Panel instead.

This technique will work with virtually any control. Rocket science it isn’t, but for most of us, it will get the job done. And best of all, you don’t have to add a single line of code.

Notes:

  • Adjust the border width by changing the size of the Padding.
  • For a TextBox, if Multiline is False, you’ll have to adjust the Height of the Panel manually. For a 1 pixel wide border, set it be 2 greater than the Height of the TextBox.
  • If you use a Label instead of a Textbox, make sure you set AutoSize to False, and set the label’s BackColor to match the Form.

Share the Post:
XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes

ransomware cyber attack

Why Is Ransomware Such a Major Threat?

One of the most significant cyber threats faced by modern organizations is a ransomware attack. Ransomware attacks have grown in both sophistication and frequency over the past few years, forcing

data dictionary

Tools You Need to Make a Data Dictionary

Data dictionaries are crucial for organizations of all sizes that deal with large amounts of data. they are centralized repositories of all the data in organizations, including metadata such as