Backcolor controls

Ralph

Member
Joined
Jan 1, 2008
Messages
6
Programming Experience
5-10
Hello,

I want to store the backcolor of controls in a setting form. In this setting form the color is choosen by using the color dialog.

Which can be used for disabled, enabled, focus,... coloring on other forms in the application.

how can you solve this problem, in VB6 it was simple just give a color number code along and it worked. I stored that number in a database.

I can't find how to do the same thing in VB.NET.

Is there anyone who can give me a possible solution?

With regards

Ralph
 
Add application setting of type Color. Link this to for example the BackColor property of the control. (properties window: (ApplicationSettings)(PropertyBinding)
For example use the click event of the control to show the color dialog and get the Color value.
 
Color

Thanks for the reply,

But can you explain it a bit more in detail I'm rather new in VB.NET

I know VB6 pretty well.

Thanks

ralph
 
The application settings you can find from project properties, Settings tab. Help by keyword "application settings". But this is so easy you wouldn't need to read the documentation. Just go there and make a Color setting (User scope).
The only code involved is the color dialog, something like in click event:
VB.NET:
If Me.ColorDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
    My.Settings.col1 = Me.ColorDialog1.Color
End If
Binding any control property to this setting in properties window: (ApplicationSettings)(PropertyBinding) Just a few mouse clicks.
 
Backcolor

Hello,

I think we're on different paths

What I want is a setting screen where certain backcolors are selected, which are used in the entire application.

When the data is saved, these colors apply to all users using the app.

So I need to store the color somewhere (db) when the app starts it needs to retrieve the colors and use them in the app.

Is this explanation more clear or do I need to explain my problem more in detail.

Anyway thanks for replying.

Ralph
 
The application settings are stored automatically when application exits. You can link any controls/forms BackColor/ForeColor property to this setting. If the setting is changed, then all linked elements are also changed. In some cases the property value will propagate from parent to child, for example if you change form backcolor a child panel with default backcolor will also get same backcolor.

As for setting screen this is just a form with some controls on it. For example you can use a Label control to choose your Backcolor1 setting. You link this to the setting same as other linked controls to give user indication of current setting value. For the click event of this label you can use the code in previous post to show the color dialog and change the color setting.
 
Backcolor

Hello

Again sorry that I ask so many questions.

But if this app is used by several users on the network will they use all the same backcolors?

Thnks
 
No, these settings apply per user. Doing it differently will give you lot of work, also running from network will give you trouble.
 
BackColor

Hello again :)

I want that the user has all the same colors. Otherwise it will be confusing. In VB6 it was very easy. Every color was a numeric value.

I stored it in the database and when the app was started the values were read from the database and stored in global variables.

I want to do the same in VB.NET but don't know how, since the color code is not numeric anymore.

With regards

Ralph
 
You can convert Color to Integer or String with ColorTranslator.ToWin32 .ToHtml .FromWin32 .FromHtml methods.
 
Back
Top