I have a MLable which inherit Label . It’s backcolor is red. I can use it on forms with red background. But when i want to change background to black from MLabel customcontrol, already added labeles doesn’t effect. Only new MLabel’s background black, others red. What the ???
Should i have to change them one by one?
SAMPLE CODE:
MLabel.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace TestCControl
{
public partial class CustomControl1 : Label
{
public CustomControl1()
{
InitializeComponent();
}
protected override void OnPaint(PaintEventArgs pe)
{
base.OnPaint(pe);
}
}
}
Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace TestCControl
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}
Form1.Designer.cs
namespace TestCControl
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.customControl11 = new TestCControl.CustomControl1();
this.customControl12 = new TestCControl.CustomControl1();
this.SuspendLayout();
//
// customControl11
//
this.customControl11.AutoSize = true;
this.customControl11.BackColor = System.Drawing.Color.Black;
this.customControl11.Location = new System.Drawing.Point(50, 23);
this.customControl11.Name = "customControl11";
this.customControl11.Size = new System.Drawing.Size(86, 13);
this.customControl11.TabIndex = 0;
this.customControl11.Text = "customControl11";
//
// customControl12
//
this.customControl12.AutoSize = true;
this.customControl12.BackColor = System.Drawing.Color.Maroon;
this.customControl12.Location = new System.Drawing.Point(140, 74);
this.customControl12.Name = "customControl12";
this.customControl12.Size = new System.Drawing.Size(86, 13);
this.customControl12.TabIndex = 1;
this.customControl12.Text = "customControl12";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(284, 262);
this.Controls.Add(this.customControl12);
this.Controls.Add(this.customControl11);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private CustomControl1 customControl11;
private CustomControl1 customControl12;
}
}
As you can see one of the custom control has black other maroon backcolor. Changes on MLabel doesn’t effect previously added controls on winform.
A couple things to check here.
Are all of your MLabels referring to the same version? (probably)
How are you setting background of the MLabel control, is it a change to the default background color?
How are you changing the existing MLabels, are you setting them manually in the code, or are you relying on the default background color?
Also, check your winform code. If the designer code sets the MLabel background color explicitly, then this will override any defaults the control may have. If that is the case, then you will need to either remove the background color setting so that it uses the default, or you will have to change each one manually.
If the above all seems correct, then some code and/or a little more information would be useful here.
Updated Answer after seeing actual code:
In CustomControl1 you will want to do something like this:
In the Form1.Designer.cs remove the lines that set the BackColor. These are explicitly setting the backcolor and not allowing a default color