我有一个Windows窗体,我试图设置一个控件的BackColor 并在我做之前检查颜色: 如果控制.BackColor = System.Drawing.Color.Blue然后 ChangeColor(control,Color.Red) Else ChangeColor(control,Color。蓝色) 结束如果 但我收到错误: 运营商''=''不是为类型''System.Drawing.Color''和 定义''System.Drawing.Color''。 我显然可以这样做: control.BackColor = System.Drawing.Color.Blue 为什么我不能测试颜色? 谢谢, Tom
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
推荐答案11月3日,7日:58 pm,tshad < t ... @dslextremewrote: On Nov 3, 7:58 pm, "tshad" <t...@dslextremewrote: 我有一个Windows窗体,我试图设置一个控件的BackColor 并在我做之前检查颜色: 如果control.BackColor = System.Drawing.Color.Blue那么 ChangeColor(control,Color.Red ) 其他 ChangeColor(对照,Color.Blue) 结束如果 但是我得到一个错误: 运算符''=''没有定义类型''System.Drawing.Color''和 ''System.Drawing .Color''。 我显然可以这样做: control.BackColor = System.Drawing.Color.Blue 为什么我不能测试颜色? 谢谢, Tom 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
尝试使用: 如果是control.BackColor.Equals(System.Drawing.Color.Blue)那么 。 ... 其他 .... 结束如果 - Tom Shelton
Try using: If control.BackColor.Equals(System.Drawing.Color.Blue ) Then .... else .... end if -- Tom Shelton
" Tom Shelton" < to ********* @ comcastwrote in message news:11 ********************* @ d55g2000hsg.googlegro ups ... "Tom Shelton" <to*********@comcastwrote in message news:11*********************@d55g2000hsg.googlegro ups... 11月3日晚上7:58,tshad < t ... @ dslextremewrote: On Nov 3, 7:58 pm, "tshad" <t...@dslextremewrote: >我有一个Windows表单,我试图设置一个控件的BackColor 和在我做之前检查颜色: 如果control.BackColor = System.Drawing.Color.Blue那么 ChangeColor(control,Color.Red)其他 ChangeColor(control,Color.Blue)结束如果 但是我收到错误: 运算符'''''没有为类型''系统定义.Drawing.Color''和''System.Drawing.Color''。 我显然可以这样做: control.BackColor = System.Drawing。 Color.Blue 为什么我不能测试颜色? 谢谢, Tom >I have a Windows form where I am trying to set the BackColor of a controland 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 IfBut 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.BlueWhy can''t I test the color?Thanks,Tom
尝试使用: 如果control.BackColor.Equals(System.Drawing.Color.Blue)那么
Try using: If control.BackColor.Equals(System.Drawing.Color.Blue ) Then
工作正常。 我需要在哪里使用.Equals? 如果我设置一个值,我会假设作业( =),我会 也可以用同样的方式测试它吗? 如果: control.BackColor = System.Drawing.Color.Blue 为什么不 如果control.BackColor = System.Drawing.Color.Blue那么... 谢谢, Tom
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
... 其他 ... 结束如果 - Tom Shelton ... else ... end if -- Tom Shelton
" tshad" < tf*@dslextremeschrieb: "tshad" <tf*@dslextremeschrieb: >我有一个Windows表单,我试图设置控件的BackColor 并检查我之前的颜色: 如果control.BackColor = System.Drawing.Color.Blue那么 ChangeColor(control,Color.Red) 其他 ChangeColor(控件,Color.Blue) 结束如果 但我收到错误: 运算符''=''没有定义类型''System.Drawing.Color''和 ''System.Drawing.Color'' 。 >I have a Windows form where I am trying to set the BackColor of a controland 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''.
除了其他回复:我假设你使用的是VB.NET 2002/2003。 那些版本还不支持运算符超载。使用VB 2005,上面的 代码将编译,因为VB 2005支持运算符重载和 ''Color''重载''=''(比较)运算符。 br /> - MS Herfried K. Wagner MVP< URL:http://dotnet.mvps/> ; VB< URL:http://dotnet.mvps/dotnet/faqs/>
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:dotnet.mvps/> V B <URL:dotnet.mvps/dotnet/faqs/>
更多推荐
无法测试BackColor的控件
发布评论