How to Change the Background Color of All Other Forms from One Form

How can we change the background color of all other forms from one form?

You can use the (ApplicationSettings) property, accessible from the Form Designer's Properties panel. Expand ApplicationSettings, open up the PropertyBinding dialog, add a Setting to the BackColor property (e.g., CommonFormBackColor) and use the same setting for all Forms.

You can create the Setting directly in the Application Settings' PropertyBinding dialog:

Properties Application Settings New

This new Setting is created in the User Scope.

All settings in the User Scope are applied on a per-User basis and can be changed.

Settings in the Application Scope are considered read-only.

Properties Application Settings Add

The new Setting will then appear under the ApplicationSettings expandable property:

Properties Application Settings

Assign the same Setting to all Forms that should change their BackColor when this setting is changed.

You can of course assign a common Setting to any other Property of any other Control.

The use of a Form Template (or a base Form class) can automate the whole process.

When the Setting value is changed at run-time, all opened Forms - and those that will be opened later - will present the same BackColor.

You can set a new value to all Form's BackColor changing the Settings's Value:

(all opened Form that share the same Setting for the BackGround Color will change color immediately)

Properties.Settings.Default.CommonFormBackColor = Color.Orange;

You can save the current Settings selection (to preserve the value assigned in the current session, so it will be used again when the application is restarted) with:

Properties.Settings.Default.Save();

You can reset the default value (the value originally assigned to the Settings in the Designer) calling:

Properties.Settings.Default.Reset();

Changing background color of all forms in winform application

The OnLoad event is only triggered when the form loads, it doesn't get triggered when you click the button. So you need to change the form BackColor in button1_Click_1 also.

if (colorDlg.ShowDialog() == DialogResult.OK)
{
Properties.Settings.Default.FormsBackgroundColor= colorDlg.Color;
Properties.Settings.Default.Save();
this.BackColor = colorDlg.Color;
}

How can I change the background of the a form from a second form?

You can set the Form 2's owner to Form1. Then access it's properties that way.

Form 1

private void button1_Click(object sender, EventArgs e)
{
Form2 frm2 = new Form2();
frm2.ShowDialog(this);
}

Form 2

private void button1_Click(object sender, EventArgs e)
{
Form1 frm1 = (Form1)this.Owner;
frm1.TransparencyKey = Color.Turquoise;
frm1.BackColor = Color.Turquoise;
}

How do you change the same background color on all forms?

Add a Module to your project, then create a global variable to hold the selected color:

Module Module1
Public FormBackColor As Color = SystemColors.Control
End Module

When you select a new color, store it there. Additionally, loop through all open forms via Application.OpenForms, and change their color:

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim cd As New ColorDialog()
If cd.ShowDialog() = DialogResult.OK Then
FormBackColor = cd.Color

For Each frm As Form In Application.OpenForms
frm.BackColor = FormBackColor
Next
End If
End Sub

For all forms, add a line in the Load() event that sets the color to the current color. This will make it so that new forms will load with the current color as well:

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.BackColor = FormBackColor
End Sub

How to set different background colors for several input submit forms(HTML)?

I think I am understanding your question. You want just the input background-color vs the the entire div

If that is the case .. Either give the input the class names you have specified for the divs ... OR call the input by it's name SELECTOR: IE

input[name="first"] {
background-color: red;
}
input[name="second"] {
background-color: green;
}
input[name="third"] {
background-color: blue;
}

If that is too ambiguous, you can also "drill down": IE

.first input {
background-color: red;
}
.second input {
background-color: blue;
}
.third input {
background-color: green;
}

Both will achieve the same result. You can also give your inputs an id RECOMMENDED

<input id="third" name="third" type="submit" value="three">

Then call it by id with #:

#third {
background-color: green;
}


Related Topics



Leave a reply



Submit