Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
229 views
in Technique[技术] by (71.8m points)

Set backgroundcolor of every form in vb.net

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

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

1 Reply

0 votes
by (71.8m points)
  • 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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...