473,396 Members | 1,864 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Not able to test BackColor of control

I have a Windows form where I am trying to set the BackColor of a control
and check the color before I do it:

If control.BackColor = System.Drawing.Color.Blue Then
ChangeColor(control, Color.Red)
Else
ChangeColor(control, Color.Blue)
End If

But I get an error:

Operator '=' is not defined for types 'System.Drawing.Color' and
'System.Drawing.Color'.

I can apparently do:

control.BackColor = System.Drawing.Color.Blue

Why can't I test the color?

Thanks,

Tom

Nov 4 '07 #1
11 1909
On Nov 3, 7:58 pm, "tshad" <t...@dslextreme.comwrote:
I have a Windows form where I am trying to set the BackColor of a control
and check the color before I do it:

If control.BackColor = System.Drawing.Color.Blue Then
ChangeColor(control, Color.Red)
Else
ChangeColor(control, Color.Blue)
End If

But I get an error:

Operator '=' is not defined for types 'System.Drawing.Color' and
'System.Drawing.Color'.

I can apparently do:

control.BackColor = System.Drawing.Color.Blue

Why can't I test the color?

Thanks,

Tom
Try using:

If control.BackColor.Equals(System.Drawing.Color.Blue ) Then
....
else
....
end if

--
Tom Shelton

Nov 4 '07 #2
"Tom Shelton" <to*********@comcast.netwrote in message
news:11*********************@d55g2000hsg.googlegro ups.com...
On Nov 3, 7:58 pm, "tshad" <t...@dslextreme.comwrote:
>I have a Windows form where I am trying to set the BackColor of a control
and check the color before I do it:

If control.BackColor = System.Drawing.Color.Blue Then
ChangeColor(control, Color.Red)
Else
ChangeColor(control, Color.Blue)
End If

But I get an error:

Operator '=' is not defined for types 'System.Drawing.Color' and
'System.Drawing.Color'.

I can apparently do:

control.BackColor = System.Drawing.Color.Blue

Why can't I test the color?

Thanks,

Tom

Try using:

If control.BackColor.Equals(System.Drawing.Color.Blue ) Then
That worked.

Where else do I need to use .Equals?

I would assume that if I set a value using an assignment (=), that I would
also be able to test it the same way?

If :

control.BackColor = System.Drawing.Color.Blue

why not

IF control.BackColor = System.Drawing.Color.Blue then ...

Thanks,

Tom
...
else
...
end if

--
Tom Shelton

Nov 5 '07 #3
"tshad" <tf*@dslextreme.comschrieb:
>I have a Windows form where I am trying to set the BackColor of a control
and check the color before I do it:

If control.BackColor = System.Drawing.Color.Blue Then
ChangeColor(control, Color.Red)
Else
ChangeColor(control, Color.Blue)
End If

But I get an error:

Operator '=' is not defined for types 'System.Drawing.Color' and
'System.Drawing.Color'.
In addition to the other replies: I assume you are using VB.NET 2002/2003.
Those versions do not yet support operator overloading. With VB 2005, the
code above would compile because VB 2005 supports operator overloading and
'Color' overloads the '=' (comparison) operator.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 5 '07 #4
On Nov 5, 12:29 pm, "Herfried K. Wagner [MVP]" <hirf-spam-me-
h...@gmx.atwrote:
"tshad" <t...@dslextreme.comschrieb:
I have a Windows form where I am trying to set the BackColor of a control
and check the color before I do it:
If control.BackColor = System.Drawing.Color.Blue Then
ChangeColor(control, Color.Red)
Else
ChangeColor(control, Color.Blue)
End If
But I get an error:
Operator '=' is not defined for types 'System.Drawing.Color' and
'System.Drawing.Color'.

In addition to the other replies: I assume you are using VB.NET 2002/2003.
Those versions do not yet support operator overloading. With VB 2005, the
code above would compile because VB 2005 supports operator overloading and
'Color' overloads the '=' (comparison) operator.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
I was going to ask him if he was using VB.NET 2002/2003 - but then I
realized, he had to be or he wouldn't have gotten the error :)

--
Tom Shelton

Nov 5 '07 #5
"Tom Shelton" <to*********@comcast.netwrote in message
news:11**********************@v23g2000prn.googlegr oups.com...
On Nov 5, 12:29 pm, "Herfried K. Wagner [MVP]" <hirf-spam-me-
h...@gmx.atwrote:
>"tshad" <t...@dslextreme.comschrieb:
>I have a Windows form where I am trying to set the BackColor of a
control
and check the color before I do it:
If control.BackColor = System.Drawing.Color.Blue Then
ChangeColor(control, Color.Red)
Else
ChangeColor(control, Color.Blue)
End If
But I get an error:
Operator '=' is not defined for types 'System.Drawing.Color' and
'System.Drawing.Color'.

In addition to the other replies: I assume you are using VB.NET
2002/2003.
Those versions do not yet support operator overloading. With VB 2005,
the
code above would compile because VB 2005 supports operator overloading
and
'Color' overloads the '=' (comparison) operator.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

I was going to ask him if he was using VB.NET 2002/2003 - but then I
realized, he had to be or he wouldn't have gotten the error :)
You're right.

It is VS.Net 2003.

Tom
>
--
Tom Shelton

Nov 5 '07 #6
On Nov 5, 4:01 pm, "tshad" <t...@dslextreme.comwrote:
"Tom Shelton" <tom_shel...@comcast.netwrote in message

news:11**********************@v23g2000prn.googlegr oups.com...


On Nov 5, 12:29 pm, "Herfried K. Wagner [MVP]" <hirf-spam-me-
h...@gmx.atwrote:
"tshad" <t...@dslextreme.comschrieb:
I have a Windows form where I am trying to set the BackColor of a
control
and check the color before I do it:
If control.BackColor = System.Drawing.Color.Blue Then
ChangeColor(control, Color.Red)
Else
ChangeColor(control, Color.Blue)
End If
But I get an error:
Operator '=' is not defined for types 'System.Drawing.Color' and
'System.Drawing.Color'.
In addition to the other replies: I assume you are using VB.NET
2002/2003.
Those versions do not yet support operator overloading. With VB 2005,
the
code above would compile because VB 2005 supports operator overloading
and
'Color' overloads the '=' (comparison) operator.
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
I was going to ask him if he was using VB.NET 2002/2003 - but then I
realized, he had to be or he wouldn't have gotten the error :)

You're right.

It is VS.Net 2003.

Tom

I figured it must be... Those versions don't support operator
overloading. Another way you could have done this is called
op_equality directly, but that is a little more ugly then just
calling .Equals.

Just so you know, in VB.NET 2005 and latter, you could just say:

If control.BackColor = Color.Red then

--
Tom Shelton

Nov 6 '07 #7

"Tom Shelton" <to*********@comcast.netwrote in message
news:11*********************@57g2000hsv.googlegrou ps.com...
On Nov 5, 4:01 pm, "tshad" <t...@dslextreme.comwrote:
>"Tom Shelton" <tom_shel...@comcast.netwrote in message

news:11**********************@v23g2000prn.googleg roups.com...


On Nov 5, 12:29 pm, "Herfried K. Wagner [MVP]" <hirf-spam-me-
h...@gmx.atwrote:
"tshad" <t...@dslextreme.comschrieb:
>I have a Windows form where I am trying to set the BackColor of a
control
and check the color before I do it:
If control.BackColor = System.Drawing.Color.Blue Then
ChangeColor(control, Color.Red)
Else
ChangeColor(control, Color.Blue)
End If
But I get an error:
Operator '=' is not defined for types 'System.Drawing.Color' and
'System.Drawing.Color'.
>In addition to the other replies: I assume you are using VB.NET
2002/2003.
Those versions do not yet support operator overloading. With VB 2005,
the
code above would compile because VB 2005 supports operator overloading
and
'Color' overloads the '=' (comparison) operator.
>--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
I was going to ask him if he was using VB.NET 2002/2003 - but then I
realized, he had to be or he wouldn't have gotten the error :)

You're right.

It is VS.Net 2003.

Tom


I figured it must be... Those versions don't support operator
overloading. Another way you could have done this is called
op_equality directly, but that is a little more ugly then just
calling .Equals.

Just so you know, in VB.NET 2005 and latter, you could just say:

If control.BackColor = Color.Red then
That's great.

I am hoping some of the other objects on forms are easier to deal with as
they are in asp.net, such as DataGrid. I'm sure you've noticed I have asked
a lot of questions about DataGrids for forms. Handling it is not as
intuitive as for the DataGrid on Asp.Net. Most of the objects are have the
same of similar methods and attributes such as getting number of rows or
getting data from the object. On windows forms, it doesn't seem to be a
straight forward.

Thanks,

Tom
>
--
Tom Shelton

Nov 6 '07 #8
On Nov 6, 2:49 pm, "tshad" <t...@dslextreme.comwrote:
"Tom Shelton" <tom_shel...@comcast.netwrote in message

news:11*********************@57g2000hsv.googlegrou ps.com...


On Nov 5, 4:01 pm, "tshad" <t...@dslextreme.comwrote:
"Tom Shelton" <tom_shel...@comcast.netwrote in message
>news:11**********************@v23g2000prn.googleg roups.com...
On Nov 5, 12:29 pm, "Herfried K. Wagner [MVP]" <hirf-spam-me-
h...@gmx.atwrote:
"tshad" <t...@dslextreme.comschrieb:
I have a Windows form where I am trying to set the BackColor of a
control
and check the color before I do it:
If control.BackColor = System.Drawing.Color.Blue Then
ChangeColor(control, Color.Red)
Else
ChangeColor(control, Color.Blue)
End If
But I get an error:
Operator '=' is not defined for types 'System.Drawing.Color' and
'System.Drawing.Color'.
In addition to the other replies: I assume you are using VB.NET
2002/2003.
Those versions do not yet support operator overloading. With VB 2005,
the
code above would compile because VB 2005 supports operator overloading
and
'Color' overloads the '=' (comparison) operator.
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
I was going to ask him if he was using VB.NET 2002/2003 - but then I
realized, he had to be or he wouldn't have gotten the error :)
You're right.
It is VS.Net 2003.
Tom
I figured it must be... Those versions don't support operator
overloading. Another way you could have done this is called
op_equality directly, but that is a little more ugly then just
calling .Equals.
Just so you know, in VB.NET 2005 and latter, you could just say:
If control.BackColor = Color.Red then

That's great.

I am hoping some of the other objects on forms are easier to deal with as
they are in asp.net, such as DataGrid.
I don't know - asp.net and windows forms are completely different on
most things, when it comes to controls :) Comming form an asp.net
background you might find WPF a little more to your liking.
I'm sure you've noticed I have asked
a lot of questions about DataGrids for forms. Handling it is not as
intuitive as for the DataGrid on Asp.Net. Most of the objects are have the
same of similar methods and attributes such as getting number of rows or
getting data from the object. On windows forms, it doesn't seem to be a
straight forward.

Thanks,

Tom

As for the DataGrid - wish I could help you there. I'm not much of a
datagrid person. I do know that in 2005, they have deprecated the
datagrid completely (well, almost completely, the only place you would
use it is if you need to display your data in a hiearchial format).
The replacement is the DataGridView. You usually hook it to a
BindingSource, etc, etc....

To be honest, most of my grid experience has been with the Janus
Grid :)

--
Tom Shelton

Nov 6 '07 #9
Tom,

I would not see direct the DataGridView as a replacement for a windows form
DataGrid.

A datagrid can show datasets, a DataGridView only single tables of that
however too all kind of other classes. It is a complete different complex
data control).

Although I agree that in the DataGridView the problems in from the DataGrid
are not repeated in the DataGridView.

Ken has specialized himself a little bit in it, we have together a website.

http://www.vb-tips.com/default.aspx

The website needs revision, we have probably used to much Ajax in it, it is
fast but not easy to handle.

Cor

Nov 7 '07 #10
On Nov 6, 10:17 pm, "Cor Ligthert[MVP]" <notmyfirstn...@planet.nl>
wrote:
Tom,

I would not see direct the DataGridView as a replacement for a windows form
DataGrid.
According to MS, it is. They suggest, that unless you need to display
heiarchial (parent -child) relationships, that DataGridView be used
in all new development. They don't even put the old DataGrid in the
toolbox anymore.
>From the help:
"The DataGrid control is retained for backward compatibility and for
special needs. For nearly all purposes, you should use the
DataGridView control."
A datagrid can show datasets, a DataGridView only single tables of that
however too all kind of other classes. It is a complete different complex
data control).
It can't do hiearchial relationships, which is what I said. Anyway,
it doens't matter to me much - because I don't really like either one
of them :) I usually use a third party grid.

--
Tom Shelton
Nov 7 '07 #11
Tom,

You saw the smile on my face when I was reading what you wrote?

:-)

Cor
Nov 8 '07 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: perspolis | last post by:
HI I created a user control and place some control on it. I need when I change BackColor of user control,Back Color of other controls also change.. I used foloowing code: public override Color...
3
by: CVerma | last post by:
Hi, I have an embedded datagrid within a datalist. I am not able to perfrom paging in the datagrid. Any ideas? Here is my code: Here is my Simplegrid.cs file: using System; using...
1
by: Firewalker | last post by:
I am attempting to change the backColor property on the previously instantiated buttons FROM a listbox_doubleClick event. I thought it would be something like this: If...
7
by: Try Guy | last post by:
I would like the background of a button so pulsate between to given colors with the speed of a given timeinterval... I have two questions: What can I use to control the interval thing with? I...
3
by: senfo | last post by:
I developed a Windows control in VS 2005 that inherits from the PictureBox Control that adds the ability to select images in a Windows application. It is, however, experiencing a strange issue...
2
by: jfolland | last post by:
I am trying to add a basic user control to a web site; coming from visual studio 2003 this was extremely easy. I would just add the user control and then add the controls that I want on that...
4
by: Rob | last post by:
This should be simple..... The default BackColor of a button (if you look at its property) is "Control" its a gray color, but apparently not a color. During a process I set the BackColor of a...
6
by: Dmitry Duginov | last post by:
Hi, I have the following label markup (label is inside FormView): <asp:Label ID="lblIndicatorReady" runat="server" Text="RE" ToolTip="Ready" BackColor='<%#...
5
by: Rob | last post by:
Hi, I'am working with vb2005 and it's an ADO application based on an access database. i'am still have problems to get the backcolor of an control in a different color if it has the focus. I am...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.