Problem working with system color

A

AussieRules

Hi,

I want to use the user color scheme to set the color of my forms.

I now I have to use the. System.Drawing.SystemColors, but which color is the
color of a form background as used in other applications.

In the end all I want to do is

form1.backcolor = system.whatever.color

Is this possible, and how?
 
A

Armin Zingler

AussieRules said:
Hi,

I want to use the user color scheme to set the color of my forms.

I now I have to use the. System.Drawing.SystemColors, but which color
is the color of a form background as used in other applications.

In the end all I want to do is

form1.backcolor = system.whatever.color

Is this possible, and how?

You've already mentioned System.Drawing.SystemColors, so why don't you use
them? Did I miss the point?

form1.backcolor = SystemColors.Window

or

form1.backcolor = SystemColors.Control

or whatever.
 
A

AussieRules

I am trying to use the color scheme as set by the user(olive green, silver,
default).

When use the systemcolors.window I get the form color to be white, not the
color that apps like office03 uses which is linked to the themes

Hope that makes sense..
 
A

Armin Zingler

AussieRules said:
I am trying to use the color scheme as set by the user(olive green,
silver, default).

When use the systemcolors.window I get the form color to be white,
not the color that apps like office03 uses which is linked to the
themes

Hope that makes sense..

Oh, I see. You want to apply the "visual styles". In Framework 1.1 you can
call System.Windows.Forms.Application.EnableVisualStyles. In Framework 1.0
you have to add some lines to the application.config file. Search this group
for "visual styles" and you'll find some hints.
 
H

Herfried K. Wagner [MVP]

* "AussieRules said:
I want to use the user color scheme to set the color of my forms.

I now I have to use the. System.Drawing.SystemColors, but which color is the
color of a form background as used in other applications.

In the end all I want to do is

form1.backcolor = system.whatever.color

'SystemColors.Control'.
 
A

_Andy_

Hi,

I want to use the user color scheme to set the color of my forms.

I now I have to use the. System.Drawing.SystemColors, but which color is the
color of a form background as used in other applications.

In the end all I want to do is

form1.backcolor = system.whatever.color

Is this possible, and how?

System.Drawing.SystemColors.Control is normal Form background.
System.Drawing.SystemColors.Window is the white bit inside a text box.
 
N

news.microsoft.com

The standard vb.net form color, is not the same as the form color of a theme
aware application.

The problem here is how to easily get the users XP theme color, and apply it
to forms and controls.

Thats how I see it
 
M

Mick Doherty

If I add a new form to any VB.Net project, it's default backcolor is
SystemColors.Control, which is the same as the form color for any Visual
Styles aware application. What's more, if left at default value, the color
changes when you change the XP Styles Color scheme. What color are you
looking for?
I am using VS.NET 2003. Is the default form backcolor for VS.NET 2002 not
'SystemColors.Control'?
 
A

AussieRules

Hi,

My from backcolor is set to systemcolors.control, and the form is the
standard grey color, not the XP theme color of blue.

I am using 03 as well. Perhaps there is some other setting/code you have to
do this ?
 
M

Mick Doherty

That Grey color is the standard form backcolor. Have a look at your
Appearance Tab under the Display Properties. The Sample Message Box has a
grey background not blue, therefore, the color you are looking for is not
standard. So what Blue color is it that you're looking for?
 
N

news.microsoft.com

If you take a look at many of the compents that are 'theme aware' or take a
look at Microsoft Office 2003, you will see that a theme aware application
have colors that are based on some other setting, outside of the display
properties apperance tab.

A good example of this is from http://www.devcomponents.com/dotnetbar/. If
you look at the job image that changes you will see two versions of the same
window(ignore the money look alike) of the dotnetbar notepad. One being
based on the display property settings, which looks like a normal Win2000k
application with its grey background, and the other which is 'theme aware'
XP with a blue background.

Under XP display setting there is a color scheme option. There are three
options out of the box, default(blue), olive green, and silver.

The color of forms is set to be one of these colors, rather than the
standard grey.

With office2003, and other MS products being XP theme aware, it would seem
that microsoft have added a nice UI feature, but made it very hard for
developers to include this in there products.



Ignore the MS Money


Ther eis
 
M

Mick Doherty

news.microsoft.com said:
If you take a look at many of the compents that are 'theme aware' or take a
look at Microsoft Office 2003, you will see that a theme aware application
have colors that are based on some other setting, outside of the display
properties apperance tab.

Office colors, just like Office Components, are not standard.
Office does it's own manipulation of colors based upon the current
System.Colors.
You can look for the WM_THEMECHANGED message to update the colors in your
app, but it is up to you to decide on what those colors are if you choose
not use the Windows Default.
A good example of this is from http://www.devcomponents.com/dotnetbar/. If
you look at the job image that changes you will see two versions of the same
window(ignore the money look alike) of the dotnetbar notepad. One being
based on the display property settings, which looks like a normal Win2000k
application with its grey background, and the other which is 'theme aware'
XP with a blue background.

They all look like XP Themed windows to me. The first Notepad Sample window
shows the DotNetBar components with a custom appearance and the second shows
these components with the Standard XP Style.
Under XP display setting there is a color scheme option. There are three
options out of the box, default(blue), olive green, and silver.

The color of forms is set to be one of these colors, rather than the
standard grey.

Have a look at the Advanced options from the Appearance Tab. The color of
forms is set by 3DObjects, which in VB.Net is SystemColors.Control.
 
N

news.microsoft.com

Ok, so I think perhaps the orginal ? might need to be reword.

How do you set the standard windows form system.color to be the same color
as those applications that use a customer color, such as office03, (ie the
Olive Green, Blue, or silver.. XP Color Style)

So far from what I have been able to see, lots of people have ideas, but no
body has provided a confirmed, working concept or code sample on how to do
this.
 
M

Mick Doherty

OK. You won't do this through the Framework, you will have to use some
uxtheme functions. You will also need to monitor for the theme changes.

The following code will do what you want. The Color I chose was Color1 of
the two color gradient of the TasksPanel in Explorer:

**** Code starts **********************************************

#Region " XP Theme API "

'The uxtheme.dll function IsAppThemed() returns True
'if only the TitleBar has Visual Styles applied. A
'better way to check for Visual Styles is to check
'whether Comctl32.dll version 6 is in use.
Private Structure DLLVERSIONINFO
Dim cbSize As Integer
Dim dwMajorVersion As Integer
Dim dwMinorVersion As Integer
Dim dwBuildNumber As Integer
Dim dwPlatformID As Integer
End Structure

<DllImport("Comctl32.dll", _
entrypoint:="DllGetVersion", _
CallingConvention:=CallingConvention.Cdecl)> _
Private Overloads Shared Function IsAppThemed( _
ByRef pdvi As DLLVERSIONINFO) As Integer
End Function

<DllImport("UxTheme.dll", _
CallingConvention:=CallingConvention.Cdecl, _
CharSet:=CharSet.Unicode)> _
Private Shared Function OpenThemeData( _
ByVal hwnd As IntPtr, _
ByVal pszClassList As String) As IntPtr
End Function

<DllImport("UxTheme.dll", _
CallingConvention:=CallingConvention.Cdecl)> _
Private Shared Function CloseThemeData( _
ByVal hTheme As IntPtr) As Integer
End Function

<DllImport("UxTheme.dll", _
CallingConvention:=CallingConvention.Cdecl)> _
Private Shared Function GetThemeColor( _
ByVal hTheme As IntPtr, _
ByVal iPartID As Integer, _
ByVal iStateId As Integer, _
ByVal iPropId As Integer, _
ByRef pColor As rgbColor) As Integer
End Function

Private Const EBP_HEADERBACKGROUND As Integer = 1

Private Const TMT_GRADIENTCOLOR1 As Integer = 3810
Private Const TMT_GRADIENTCOLOR2 As Integer = 3811
Private Const TMT_GRADIENTCOLOR3 As Integer = 3812
Private Const TMT_GRADIENTCOLOR4 As Integer = 3813
Private Const TMT_GRADIENTCOLOR5 As Integer = 3814

Private S_OK As Integer = 0

Private Const WM_THEMECHANGED As Integer = &H31A

Private Structure rgbColor
Dim r As Byte
Dim g As Byte
Dim b As Byte
End Structure

#End Region

Private Function SetFormColor() As Boolean

Dim ReturnValue As Boolean = False

'----Check we are using Visual Styles
Dim dvi As New DLLVERSIONINFO
dvi.cbSize = Marshal.SizeOf(dvi)
IsAppThemed(dvi)
If dvi.dwMajorVersion < 6 Then Return False
'----------------------------------

Dim hTheme As IntPtr = OpenThemeData(Me.Handle, _
"EXPLORERBAR")

If Not hTheme.Equals(IntPtr.Zero) Then
Dim c As New rgbColor
If GetThemeColor(hTheme, EBP_HEADERBACKGROUND, 0, _
TMT_GRADIENTCOLOR1, _
c) = S_OK Then
Me.BackColor = Color.FromArgb(255, c.r, c.g, c.b)
ReturnValue = True
End If
End If

CloseThemeData(hTheme)

Return ReturnValue

End Function

Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load

SetFormColor()

End Sub

Protected Overrides Sub WndProc( _
ByRef m As System.Windows.Forms.Message)

MyBase.WndProc(m)
If m.Msg = WM_THEMECHANGED Then SetFormColor()

End Sub

**** Code ends ***********************************************

HTH

Mick
 
A

AussieRules

Hi,

Thanks for the code. I have plugged it into a new VB project and stepped
through the code to learn from it.

The following command however returns false, and therefore the color is not
set

If dvi.dwMajorVersion < 6 Then Return False

I have the color theme set on my XP machine(olive green), so I figure that
the comcontrol vb.net is using is less than version 6.

How do I get the Comctl32.dll to be used(I figure this is the problem but I
could be wrong ?)

Thanks heaps!
 
M

Mick Doherty

Sorry! I totally forgot that New users don't know about Enabling Visual
Styles.

For Framework 1.1(VS2003):
Expand the Windows Form Designer generated code region.
Add Application.EnableVisualStyles() to Sub New(). Several people also
suggest adding Application.DoEvents. I add it although I have never
experienced problems without it.

Alternatively add a Manifest File for your App.
 
A

AussieRules

Followed your advice... but the same still occurs ?

I figure I must be doing something wrong, so my sub new code attached


--
#Region " Windows Form Designer generated code "

Public Sub New()

MyBase.New()

'This call is required by the Windows Form Designer.

InitializeComponent()

Application.EnableVisualStyles()

Application.DoEvents()

'Add any initialization after the InitializeComponent() call

End Sub
 
M

Mick Doherty

It should all be working. Add a Command button to your form and set it's
Flatstyle property to system. If the button is using Visual Styles then the
code should be working since the themed controls are in Common Controls 6.
If not then you have another problem.
Is your Titlebar displayed using Visual Styles?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top