Solved

commonDialog Show color

Posted on 2001-06-21
34
454 Views
Last Modified: 2008-02-01
i use Visual Interdev to create a CommonDialog box to display color box for me to choose color.
but i found that the color i choosed is not same as the color display. (Not all color, but some)
So i hope anyone can help me. Thanks alot.

Below is the source code.

<%@ Language=VBScript %>
<HTML>
<HEAD>
<META name=VI60_defaultClientScript content=VBScript>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<SCRIPT ID=clientEventHandlersVBS LANGUAGE=vbscript>
<!--

Sub button1_onclick

     CommonDialog1.ShowColor
     text1.style.backgroundColor= CommonDialog1.Color
     
     
End Sub

-->
</SCRIPT>
</HEAD>
<BODY>

<P>
<OBJECT id=CommonDialog1 classid=clsid:F9043C85-F6F2-101A-A3C9-08002B2F49FB><PARAM NAME="_ExtentX" VALUE="847"><PARAM NAME="_ExtentY" VALUE="847"><PARAM NAME="_Version" VALUE="393216"><PARAM NAME="CancelError" VALUE="0"><PARAM NAME="Color" VALUE="0"><PARAM NAME="Copies" VALUE="1"><PARAM NAME="DefaultExt" VALUE=""><PARAM NAME="DialogTitle" VALUE=""><PARAM NAME="FileName" VALUE=""><PARAM NAME="Filter" VALUE=""><PARAM NAME="FilterIndex" VALUE="0"><PARAM NAME="Flags" VALUE="0"><PARAM NAME="FontBold" VALUE="0"><PARAM NAME="FontItalic" VALUE="0"><PARAM NAME="FontName" VALUE=""><PARAM NAME="FontSize" VALUE="8"><PARAM NAME="FontStrikeThru" VALUE="0"><PARAM NAME="FontUnderLine" VALUE="0"><PARAM NAME="FromPage" VALUE="0"><PARAM NAME="HelpCommand" VALUE="0"><PARAM NAME="HelpContext" VALUE="0"><PARAM NAME="HelpFile" VALUE=""><PARAM NAME="HelpKey" VALUE=""><PARAM NAME="InitDir" VALUE=""><PARAM NAME="Max" VALUE="0"><PARAM NAME="Min" VALUE="0"><PARAM NAME="MaxFileSize" VALUE="260"><PARAM NAME="PrinterDefault" VALUE="1"><PARAM NAME="ToPage" VALUE="0"><PARAM NAME="Orientation" VALUE="1"></OBJECT>
<INPUT id=text1 name=text1></P>
<P><INPUT id=button1 type=button value=Button name=button1></P>

</BODY>
</HTML>
0
Comment
Question by:chencc77
  • 17
  • 15
  • 2
34 Comments
 
LVL 20

Expert Comment

by:Silvers5
ID: 6213483
In cases I encounered that IE browsers don't show the selected colors but a close match... I thought it might be that I have a pattern of 24bit colors (FFFFFF) and my display settings are set to 16 bit or less.. this might occure..
0
 

Author Comment

by:chencc77
ID: 6213565
i found that the color box use 'long' numeric to identify the color. So how am i going to solve this problem??
0
 
LVL 20

Expert Comment

by:Silvers5
ID: 6213600
yes.. 24 bit value.. 16777215 = FFFFFF hex

what are your entered values?
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 6214068
I found the red and blue color has been change position

try this


Function RGBX(red, green, blue)
     
    On Error Resume Next
     RGBX = RGB(blue, green, red)
end Function


function GetRed(color)
     
    On Error Resume Next
     GetRed = color And &HFF
end Function

function GetGreen(color)
     
    On Error Resume Next
     GetGreen = ((color And &HFF00) / &H100) And &HFF
end Function

function GetBlue(color)
     
    On Error Resume Next
     GetBlue = ((color And &HFF0000) / &H10000) And &HFF
end Function


text1.style.backgroundColor = RGBX(getblue(color), getgreen(color), getred(color))
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 6214074
OOhs where color is

Dim color
color = CommonDialog1.Color


0
 

Author Comment

by:chencc77
ID: 6216644
hi EDDYKT,
i have edit the code, but i found it show all black color.


<%@ Language=VBScript %>
<HTML>
<HEAD>
<META name=VI60_defaultClientScript content=VBScript>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<SCRIPT ID=clientEventHandlersVBS LANGUAGE=vbscript>
<!--
Dim color

Sub button1_onclick

CommonDialog1.ShowColor
color = CommonDialog1.Color
msgbox color
msgbox RGBX(getblue(color), getgreen(color), getred(color))
text1.style.backgroundColor = RGBX(getblue(color), getgreen(color), getred(color))

End Sub



Function RGBX(red, green, blue)
    msgbox "rGBX"
   On Error Resume Next
    RGBX = RGB(blue, green, red)
end Function


function GetRed(color)
   
   On Error Resume Next
    GetRed = color And &HFF
end Function

function GetGreen(color)
   
   On Error Resume Next
    GetGreen = ((color And &HFF00) / &H100) And &HFF
end Function

function GetBlue(color)
   
   On Error Resume Next
    GetBlue = ((color And &HFF0000) / &H10000) And &HFF
end Function



-->
</SCRIPT>
</HEAD>

<BODY>

<P>&nbsp;</P>
<INPUT id=text1 name=text1>
<INPUT id=button1 type=button value=Button name=button1>
<OBJECT id=CommonDialog1 classid=clsid:F9043C85-F6F2-101A-A3C9-08002B2F49FB><PARAM NAME="_ExtentX" VALUE="847"><PARAM NAME="_ExtentY" VALUE="847"><PARAM NAME="_Version" VALUE="393216"><PARAM NAME="CancelError" VALUE="0"><PARAM NAME="Color" VALUE="0"><PARAM NAME="Copies" VALUE="1"><PARAM NAME="DefaultExt" VALUE=""><PARAM NAME="DialogTitle" VALUE=""><PARAM NAME="FileName" VALUE=""><PARAM NAME="Filter" VALUE=""><PARAM NAME="FilterIndex" VALUE="0"><PARAM NAME="Flags" VALUE="0"><PARAM NAME="FontBold" VALUE="0"><PARAM NAME="FontItalic" VALUE="0"><PARAM NAME="FontName" VALUE=""><PARAM NAME="FontSize" VALUE="8"><PARAM NAME="FontStrikeThru" VALUE="0"><PARAM NAME="FontUnderLine" VALUE="0"><PARAM NAME="FromPage" VALUE="0"><PARAM NAME="HelpCommand" VALUE="0"><PARAM NAME="HelpContext" VALUE="0"><PARAM NAME="HelpFile" VALUE=""><PARAM NAME="HelpKey" VALUE=""><PARAM NAME="InitDir" VALUE=""><PARAM NAME="Max" VALUE="0"><PARAM NAME="Min" VALUE="0"><PARAM NAME="MaxFileSize" VALUE="260"><PARAM NAME="PrinterDefault" VALUE="1"><PARAM NAME="ToPage" VALUE="0"><PARAM NAME="Orientation" VALUE="1"></OBJECT>

</BODY>
</HTML>
0
 

Author Comment

by:chencc77
ID: 6216666
EDDYKT : i found the Getxxx function doesn't work.

Silvers5 : my display setting is 24bit - TRue Color, izit the display setting will effect it?? i found the IE browser use the same color box, but it showed the exact color as i choosed. So wht was the reason there?? Thanks
0
 
LVL 20

Expert Comment

by:Silvers5
ID: 6217460
Nahh.. this has nothing with the display then.. 1 min..
0
 
LVL 20

Expert Comment

by:Silvers5
ID: 6217479
why such a turn.. simply remove all the other functions and leave this:

Sub button1_onclick

CommonDialog1.ShowColor
color = hex(CommonDialog1.Color)
text1.style.backgroundColor = "#" & color

End Sub



;o)
0
 
LVL 20

Expert Comment

by:Silvers5
ID: 6217519
hmm same issue.. I'll do it another way.. 1 min..
0
 

Author Comment

by:chencc77
ID: 6217528
silver5 : can u try my code?? really there are some color that display different color from wht i choose.
0
 

Author Comment

by:chencc77
ID: 6217534
silver5 : can u try my code?? really there are some color that display different color from wht i choose.
0
 

Author Comment

by:chencc77
ID: 6217542
silver5 : they are a error if use ur suggestion.

hex(0) = 0

no this color

:>
0
 
LVL 20

Expert Comment

by:Silvers5
ID: 6217550
the dialogue box is returning the colors info blue green red instead of red green blue ..I'll fix you a code in 1 min..
0
 
LVL 20

Expert Comment

by:Silvers5
ID: 6217567
Shake it baby ;o)


Sub button1_onclick

CommonDialog1.ShowColor
color = hex(CommonDialog1.Color)
color =  Right(color,2) & Mid(color,3,2) & left(color,2)
text1.style.backgroundColor = "#" & color
End Sub

0
 

Author Comment

by:chencc77
ID: 6217568
silver5 : they are a error if use ur suggestion.

hex(0) = 0

no this color

:>
0
 
LVL 20

Expert Comment

by:Silvers5
ID: 6217577
This issue was tricky! the dialogue box seemed to have a bug.. 100 extra points are nice :o)  jokin..
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:chencc77
ID: 6217585
silver5 : they are a error if use ur suggestion.

hex(0) = 0

no this color

:>
0
 

Author Comment

by:chencc77
ID: 6217589
no problems...  :>
need ur help.
0
 
LVL 20

Expert Comment

by:Silvers5
ID: 6217598
I'll need to polish the code for bugs.. like if the color number is less than 6 digits.. or is 0
0
 
LVL 20

Expert Comment

by:Silvers5
ID: 6217603
But the main issue is resolved.. colors are shown exactly as they are.. give me a minute for polishing..
0
 

Author Comment

by:chencc77
ID: 6217610
silver5 : not all color are fix. still got error.

 :(
0
 
LVL 20

Accepted Solution

by:
Silvers5 earned 300 total points
ID: 6217613
here's your final sub, check it:

Sub button1_onclick

CommonDialog1.ShowColor
msgbox CommonDialog1.Color
color = CommonDialog1.Color
if clng(color) = 0 then
color = "000000"
else
color = hex(color)
do while len(color) < 6
color = "0" & color
loop
end if
msgbox color
color =  Right(color,2) & Mid(color,3,2) & left(color,2)
text1.style.backgroundColor = "#" & color
End Sub
0
 
LVL 20

Expert Comment

by:Silvers5
ID: 6217619
>silver5 : not all color are fix. still got error.

what color?
0
 

Author Comment

by:chencc77
ID: 6217626
silver5 : not all color are fix. still got error.

 :(
0
 
LVL 20

Expert Comment

by:Silvers5
ID: 6217627
remove the msb boxes from the sub..
0
 
LVL 20

Expert Comment

by:Silvers5
ID: 6217629
msg boxes
0
 
LVL 20

Expert Comment

by:Silvers5
ID: 6217633
the last code I gave will take all colors.. the error you had is because of the colors that are less than 6 in hex length.. try it and report back
0
 

Author Comment

by:chencc77
ID: 6217648
silver5 : not all color are fix. still got error.

 :(
0
 
LVL 20

Expert Comment

by:Silvers5
ID: 6217654
Chen.. what is the error? or your post is duplicated (you are on a slow connection?)
0
 

Author Comment

by:chencc77
ID: 6217659
silver5 : thank you very much, really appreciate ur help.

^_^  .  really nice to meet u here!!


from,
cc chen
0
 

Author Comment

by:chencc77
ID: 6217662
silver5 : yes, the msg is duplicated. u have solve all the problems...

0
 

Author Comment

by:chencc77
ID: 6217666
here's ur points
0
 
LVL 20

Expert Comment

by:Silvers5
ID: 6217676
You're welcome ;o)  I was glad to solve.. a bug! :o)

I posted comment to your other question that you can't use getred getgreen and getblue function.. your best way is to convert them to Hex and get the part you need using mid function..

rgrds
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now