无法测试BackColor的控件

编程入门 行业动态 更新时间:2024-10-28 04:16:45
本文介绍了无法测试BackColor的控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个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的控件

本文发布于:2023-11-04 05:55:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1557133.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:控件   测试   BackColor

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!