Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

How can I set the BackColor of every form that exists in my vb.net (fw 4.7.2) project?
And yes, I could do

Form1.BackColor = ...  
Form2.BackColor = ...
......

but that would be too messy then.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
220 views
Welcome To Ask or Share your Answers For Others

1 Answer

  • Open one of your forms in the designer, any form, doesn't matter
  • Click the form background
  • In the property grid, at the top, go to (Application Settings) then click the dots button in (Property Binding), find BackColor in the list of proeprties, click the dropdown next to it and click New at the bottom
  • Call your setting ThemeColor, pick the color you want for the light theme, such as White
  • OK everything
  • Open the designer for another form, go Application Settings/Property Binding again. This time don't click New, just bind BackColor to the existing ThemeColor setting
  • Repeat for all forms in your app

  • Add a button to the "Settings" form (or wherever you want to offer a toggle for the theme), and in its click handler write:

    My.Settings.ThemeColor = Color.White

  • Add another button to the form, make its click handler set Color.Black


  • Run the application. Open one or more forms, including the settings form. Click one of the buttons to change the setting. All forms change color

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...