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

前端 未结 1 1895
不知归路
不知归路 2020-12-07 04:48

How can we change the background color of all other forms from one form (settings.form)? I want to develop my graduation project. Its a social media desktop management proje

1条回答
  •  悲哀的现实
    2020-12-07 05:25

    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:

    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.

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

    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();
    

    0 讨论(0)
提交回复
热议问题