Note that there are some explanatory texts on larger screens.

plurals
  1. POchanging the backcolor of a panel changes the backcolor for all panels
    primarykey
    data
    text
    <p>I have a custom control, OrderEntryCtl, with a TableLayoutPanel that uses Panels insided of the cells of the first row (call it the header row, the Panels are named HeaderPanel1, HeaderPanel2, etc[8 panels altogether, 1 for each column in row 0 of the TableLayoutPanel]). The BackColor of each Panel is set to blue first. At some point, I want to change the BackColor of each Panel to gray. Here's the problem I am running into: Changing the BackColor of 1 panel actually changes the BackColor of all Panels on all of my OrderEntryCtl's added to the Form. FYI: I'm not creating any of the panels dynamically; they are all created via the designer and the code created by VS is in OrderEntryCtl.Designer.cs</p> <p>So, consider, I have some number of OrderEntryCtl's on my form (these are added programmatically/dynamically at run time by my code, not by the designer). A user interacts with the first OrderEntryCtl (call it OrderEntry1), then clicks a button that's a part of the control. The click event handler for that button needs to turn the 8 HeaderPanel's to gray:</p> <pre><code>HeaderPanel1.BackColor = Color.DarkGray; HeaderPanel2.BackColor = Color.DarkGray; HeaderPanel3.BackColor = Color.DarkGray; //etc </code></pre> <p>I'm expecting only the 8 header Panels to turn gray for OrderEntry1, however, ALL header Panels for ALL OrderEntryCtl's are turning gray. The really odd thing is, I could comment out the last 7 "HeaderPanel#.BackColor = Color.DarkGray;" commands, leaving only HeaderPanel1.BackColor = Color.DarkGray; and this still happens. But, if I add to the event handler</p> <pre><code>HeaderPanel2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; </code></pre> <p>only the border style of panel 2 of OrderEntry1 is affected, which is the expected behavior! How do I get the BackColor property to behave the same as the BorderStyle property for my panels?</p> <p>In response to first comment, I've included the code in the Designer.cs</p> <pre><code>private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1; private System.Windows.Forms.Panel HeaderPanel1; private System.Windows.Forms.Panel HeaderPanel2; private System.Windows.Forms.Panel HeaderPanel3; private System.Windows.Forms.Panel HeaderPanel4; private System.Windows.Forms.Panel HeaderPanel5; private System.Windows.Forms.Panel HeaderPanel6; private System.Windows.Forms.Panel HeaderPanel7; private System.Windows.Forms.Panel HeaderPanel8; this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); this.HeaderPanel1 = new System.Windows.Forms.Panel(); this.HeaderPanel2 = new System.Windows.Forms.Panel(); this.HeaderPanel3 = new System.Windows.Forms.Panel(); this.HeaderPanel4 = new System.Windows.Forms.Panel(); this.HeaderPanel5 = new System.Windows.Forms.Panel(); this.HeaderPanel6 = new System.Windows.Forms.Panel(); this.HeaderPanel7 = new System.Windows.Forms.Panel(); this.HeaderPanel8 = new System.Windows.Forms.Panel(); this.tableLayoutPanel1.SuspendLayout(); this.HeaderPanel1.SuspendLayout(); this.HeaderPanel2.SuspendLayout(); this.HeaderPanel3.SuspendLayout(); this.HeaderPanel4.SuspendLayout(); this.HeaderPanel5.SuspendLayout(); this.HeaderPanel6.SuspendLayout(); this.HeaderPanel7.SuspendLayout(); this.HeaderPanel8.SuspendLayout(); // // tableLayoutPanel1 // this.tableLayoutPanel1.BackColor = System.Drawing.Color.White; this.tableLayoutPanel1.ColumnCount = 8; this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 24F)); this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 16F)); this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 26F)); this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 24F)); this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 15F)); this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 15F)); this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 12F)); this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 18F)); this.tableLayoutPanel1.Controls.Add(this.HeaderPanel1, 0, 0); this.tableLayoutPanel1.Controls.Add(this.HeaderPanel2, 1, 0); this.tableLayoutPanel1.Controls.Add(this.HeaderPanel3, 2, 0); this.tableLayoutPanel1.Controls.Add(this.HeaderPanel4, 3, 0); this.tableLayoutPanel1.Controls.Add(this.HeaderPanel5, 4, 0); this.tableLayoutPanel1.Controls.Add(this.HeaderPanel6, 5, 0); this.tableLayoutPanel1.Controls.Add(this.HeaderPanel7, 6, 0); this.tableLayoutPanel1.Controls.Add(this.HeaderPanel8, 7, 0); this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill; this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0); this.tableLayoutPanel1.Margin = new System.Windows.Forms.Padding(0); this.tableLayoutPanel1.Name = "tableLayoutPanel1"; this.tableLayoutPanel1.RowCount = 2; this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); this.tableLayoutPanel1.Size = new System.Drawing.Size(944, 90); this.tableLayoutPanel1.TabIndex = 0; // // HeaderPanel1 // this.HeaderPanel1.BackColor = global::WdRx.Fulfillment.Dispensing.Workstation.Properties.Settings.Default.OrderEntryHeader; this.HeaderPanel1.Controls.Add(this.Lbl_Header1); this.HeaderPanel1.DataBindings.Add(new System.Windows.Forms.Binding("BackColor", global::WdRx.Fulfillment.Dispensing.Workstation.Properties.Settings.Default, "OrderEntryHeader", true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged)); this.HeaderPanel1.Dock = System.Windows.Forms.DockStyle.Fill; this.HeaderPanel1.Location = new System.Drawing.Point(675, 0); this.HeaderPanel1.Margin = new System.Windows.Forms.Padding(0); this.HeaderPanel1.Name = "HeaderPanel1"; this.HeaderPanel1.Size = new System.Drawing.Size(107, 45); this.HeaderPanel1.TabIndex = 10; </code></pre> <p>Ok, after reviewing the above, I realize my problem is that I am associating the BackColor property to a color defined in my config file, and I'm doing this for all of the panels. The binding is for the property changed event, so change the property on 1 panel, updates all panels.</p> <p>So, I'm now taking suggestions on how to still fetch my initial color from my config file, but without binding the OnPropertyChange event ? ? ? Anyone ?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload