I want to change the font of my label so that it is white with a black outline. And I have found a way to doing so for a label I create in code, but I would like to add the outlining for already existing control labels.
In a previous stackoverflow question I have found the class (the CustomLabel class) which adds an outline to a label.
I know I can create a new label with the following code, and use this class, but I am unable to find any information how I can use this class (CustomLabel) for my control class (label) and add the outline to already existing labels in my Windows Form.
Form newForm = new Form();
CustomLabel newLabel = new CustomLabel();
newForm.Controls.Add(newLabel);
newLabel.BackColor = Color.Black;
newLabel.Font = new System.Drawing.Font("Impact", 18F,
FontStyle.Regular, GraphicsUnit.Point, ((byte)(0)));
newLabel.ForeColor = Color.Crimson;
newLabel.OutlineForeColor = Color.Black;
newLabel.OutlineWidth = 2;
newLabel.Text = "test text";
newForm.Show();
newForm.TopMost = true;
newLabel.AutoSize = true;
newLabel.Location = new Point(100, 250);
The problem I run into is I don't know how to apply this this class to the control (label), and several labels I have created in my design (GUI).
I would like if I could do something like:
// myLabel is made in the designer window
myLabel.OutlineForeColor = Color.Black;
myLabel.OutlineWidth = 2;
or another idea is, to create a function which takes all the custom properties for each label in my designer (a label is the argument for the function), adds them to newLabel (same as above), however newLabel has two custom properties like OutLineForeColor and OutlineWidth and then finally all the properties of newLabel is coppied over to the argument of the function (one of the custom labels). So something like this:
private void addNewProperties(Label myFormLabel)
{
CustomLabel newLabel = new CustomLabel();
newLabel.BackColor = myFormLabel.BackColor;
newLabel.Font = myFormLabel.Font;
newLabel.ForeColor = myFormLabel.ForeColor;
newLabel.OutlineForeColor = Color.White;
newLabel.OutlineWidth = 2;
newLabel.Text = myFormLabel.Text;
newLabel.Location = myFormLabel.Location;
myFormLabel = newLabel;
}
Finally, I wonder if a different approach would be easier; if there's a way where I can just add the CustomLabel class to the Label class itself in C#, so that I directly can add the desired methods to my form labels.