反转颜色代码 [英] Reversing a COlour Code

查看:216
本文介绍了反转颜色代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是Terry Kreft的& Stephen Lebans为用户设置颜色对话框程序

为某些应用程序中的各种控件属性选择颜色。


有没有办法获取显示的颜色代码在

backcolor / forecolor / etc属性中并计算反色?用

换句话说,如果用户为控件背景选择255(红色),我希望

能够计算出该颜色的相反或负数并且

为控件的forecolor属性赋予新的颜色。


vbWhWite和其他颜色常数不是一个选项,我不认为,

因为颜色对话框允许用户混合自己的自定义颜色...


TIA可以提供任何帮助。

- -

Tim http://www.ucs。 mun.ca/~tmarshal/

^ o<

/#)Burp-beep,burp-beep,burp-beep? - Quaker Jake

/ ^^什么是UP,Dittoooooo? - 同上

I use Terry Kreft''s & Stephen Lebans colour dialog procedures for users
to pick colours for various control properties in certain apps.

Is there a way to take the colour code that is displayed in a
backcolor/forecolor/etc property and calculate the "reverse colour"? In
other words, If a user picks 255 (red) for a control backcolor, I''d like
to be able to calculate the opposite or negative of that colour and
assign the control''s forecolor property the new colour.

vbWhite and other colour constants are not an option, I don''t think,
since the colour dialog allows a user to blend their own custom colour...

TIA for any help.
--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "What''s UP, Dittoooooo?" - Ditto

推荐答案

使用整数除法将颜色分解为红色,绿色和蓝色的字节

和Mod。

通过注意它们来翻转位

将它们与RGB()函数结合使用。


假设RGB值在名为txtCombined的文本框:

Dim btRed As Byte,btGreen As Byte,btBlue As Byte

Dim lngColor as Long

btRed = Me.txtCombined Mod 256

lngColor = Me.txtCombined \ 256

btGreen = lngColor Mod 256


btRed =不是btRed

''等等


-

Allen Browne - 微软MVP 。西澳大利亚州珀斯。

访问用户提示 - http:// allenbrowne.com/tips.html

回复群组,而不是mvps dot org的allenbrowne。


Tim Marshall < TI **** @ PurplePandaChasers.Moertherium>在消息中写道

news:do ********** @ coranto.ucs.mun.ca ...
Parse the color into bytes for red, green, and blue, using integer division
and Mod.
Flip the bits by NOTing them
Combine them with the RGB() function.

Assuming the RGB value is in a text box named txtCombined:
Dim btRed As Byte, btGreen As Byte, btBlue As Byte
Dim lngColor as Long
btRed = Me.txtCombined Mod 256
lngColor = Me.txtCombined \ 256
btGreen = lngColor Mod 256
btBlue = lngColor \ 256

btRed = Not btRed
''etc.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Tim Marshall" <TI****@PurplePandaChasers.Moertherium> wrote in message
news:do**********@coranto.ucs.mun.ca...
我使用Terry Kreft'的&安培; Stephen Lebans为用户提供颜色对话程序,以便为某些应用程序中的各种控件属性选择颜色。

有没有办法获取显示在
背景颜色中的颜色代码/ forecolor / etc属性并计算反色?换句话说,如果用户为控制背景颜色选择255(红色),我希望
能够计算该颜色的相反或负数并指定控件'的前色属性是新的颜色。

vbWhite和其他颜色常量不是一个选项,我不认为,因为
颜色对话框允许用户混合自己的自定义颜色......

TIA提供任何帮助。
-
Tim http://www.ucs.mun.ca/~tmarshal/
^ o<
/#)" Burp-beep,burp - 哔,打嗝? - Quaker Jake
/ ^^什么是UP,Dittoooooo? - Ditto
I use Terry Kreft''s & Stephen Lebans colour dialog procedures for users to
pick colours for various control properties in certain apps.

Is there a way to take the colour code that is displayed in a
backcolor/forecolor/etc property and calculate the "reverse colour"? In
other words, If a user picks 255 (red) for a control backcolor, I''d like
to be able to calculate the opposite or negative of that colour and assign
the control''s forecolor property the new colour.

vbWhite and other colour constants are not an option, I don''t think, since
the colour dialog allows a user to blend their own custom colour...

TIA for any help.
--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "What''s UP, Dittoooooo?" - Ditto



很早就没有咖啡,我的逻辑感说:


不是ColorCode和vbWhite

应该反转任何RGB类型的颜色。


---





不是ColorCode和16777215如果常量vbWhite不可用?


---


[不是ColorCode ]应该反转所有位。

[和vbWhite]应该将第四个字节中的位返回到零。

Very early in the morning and without coffee my sense of logic says:

Not ColorCode And vbWhite
should reverse any RGB type color.

---

or

Not ColorCode And 16777215 if the constant vbWhite isn''t available?

---

[Not ColorCode] should reverse all the bits.
[And vbWhite] should return the bits in the fourth byte to zero.


Allen Browne写道:
Allen Browne wrote:
使用整数除法
和Mod将颜色分解为红色,绿色和蓝色的字节。
Parse the color into bytes for red, green, and blue, using integer division
and Mod.




HI Allen - 感谢你和Lyle的回复。对于子孙后代,

这里是基于你的提交的功能(Lyle'似乎有效,

但是对于我做的非常有限的测试它,我一直得到

黑色)。


我尝试将颜色解析成整数,因为RGB()函数

需要整数参数,但我最终看到了大致不同的颜色,大部分都是黑色的。我不明白为什么使用字节

工作得更好,但是<耸肩>

公共函数fReverseColour(lngColour As Long)As Long

''采用RGB颜色规格并将其反转。

''感谢Allen Browne&莱尔费尔菲尔德对cdma的回应

''

''参数LngColour是用颜色代替的颜色代码
''属性一个控件的BackColor(通常在TCM中使用

'),foreColor等。


Dim by ByRed As Byte,bytGreen As Byte, bytBlue As Byte


Dim bytTemp As Byte


''在使用上述bytRed等字节之前,

''使用bytTemp进行计算,因为对于某些

''lngColour代码,如标准Access默认

''形成BG颜色,结果部分划分和

''mod函数大于255.查看错误处理


Dim lngC As Long


出错GoTo Err_Proc


bytTemp = lngColour Mod 256

bytRed = bytTemp


lngC = lngColour \\ \\ 256


bytTemp = lngC Mod 256

bytGreen = bytTemp


bytTemp = lngC \ 256


bytBlue = bytTemp


bytRed = not bytRed


bytGreen =不是byGreen


bytBlue =非bytBlue


fReverseColour = RGB(bytRed,bytGreen,bytBlue)


Debug.PrintOriginal Color Fed: &安培; lngColour& _

"反向: &安培; fReverseColour


Exit_Proc:


退出功能


Err_Proc:

Select Case Err.Number


案例6''溢出ontTemp计算


bytTemp = 255


继续下一步


Case Else


MsgBox"错误" &安培; Err.Number& " " &安培; _

Err.Description,vbCritical,_

" Function fReverseColour",Err.HelpFile _

,Err.HelpContext


简历Exit_Proc


结束选择


结束功能


-

Tim http://www.ucs .mun.ca / ~tmarshal /

^ o<

/#)Burp-beep,burp-beep,burp-beep? - Quaker Jake

/ ^^什么是UP,Dittoooooo? - 同上



HI Allen - thanks to you and Lyle for your responses. For posterity,
here''s the function I based on your submission (Lyle''s seemed to work,
but for the very limited amount of testing I did with it, I kept getting
black colours).

I tried parsing the colour into integers since the RGB() function
requires integer arguments, but I ended up with vastly different looking
colours which were mostly black. I don''t understand why using bytes
worked better, but <shrug>
Public Function fReverseColour(lngColour As Long) As Long

''Takes an RGB colour spec and reverses it.
''Thanks to Allen Browne & Lyle Fairfield''s responses on cdma
''
''Argument LngColour is the colour code fed from a colour
''property of a control''s BackColor (the usual one used
''in TCM), foreColor, etc.

Dim bytRed As Byte, bytGreen As Byte, bytBlue As Byte

Dim bytTemp As Byte

''Before using the above bytRed, etc bytes,
''use bytTemp for a calculation because for some
''lngColour codes such as the standard Access default
''form BG colour, the results of some of the division and
''mod functions is greater than 255. See error handling

Dim lngC As Long

On Error GoTo Err_Proc

bytTemp = lngColour Mod 256

bytRed = bytTemp

lngC = lngColour \ 256

bytTemp = lngC Mod 256

bytGreen = bytTemp

bytTemp = lngC \ 256

bytBlue = bytTemp

bytRed = Not bytRed

bytGreen = Not bytGreen

bytBlue = Not bytBlue

fReverseColour = RGB(bytRed, bytGreen, bytBlue)

Debug.Print "Original Colour Fed: " & lngColour & _
" Reverse: " & fReverseColour

Exit_Proc:

Exit Function

Err_Proc:

Select Case Err.Number

Case 6 ''overflow on bytTemp calc

bytTemp = 255

Resume Next

Case Else

MsgBox "Error " & Err.Number & " " & _
Err.Description, vbCritical, _
"Function fReverseColour", Err.HelpFile _
, Err.HelpContext

Resume Exit_Proc

End Select

End Function

--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "What''s UP, Dittoooooo?" - Ditto


这篇关于反转颜色代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆