Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combobox for picking colors 1

Status
Not open for further replies.

andre65

Programmer
Jan 19, 2003
95
NL
Hi everyone,

How can I create a combobox to pick a color? ... or is there a control/subclass available to do this?

Thanks for any reply.
Gr,
André

 
Hi Andre

There is a built in function GETCOLOR

HTH

Regards

Griff
Keep [Smile]ing
 
There are several ways to do this, I have found some ocx that do that, you can use the Getcolor function as Griff say but this isn't much likely a combo box.

what is exactly you want to do, maybe if we have a better picture of what are you after we can help you better
 
Thanks for your reply,

I'm not looking for the getColor function.

Purpose: I have a grid, and one of the columns says 'Color', so I want the user to pick a color from a list and display the color in the column. I thought a dropdown (combobox) colorpicker would be nice.

Hope this explains more what i'm looking for.

Gr,
André
 
andre65

Since the combobox is a "character based" control, I not sure that the combobox is the right control for your requirements. Although it is possible to show colors in a combobox, the control itself seems to hang once the control is opened. May I suggest you change your requirements and consider a listbox (Or there may be an activex out there the will meet your requirements). Here is a "re-worked" example that I posted here last year that shows how to display colors in a listbox (copy the following in a prg file and run it.):
Code:
PUBLIC oform1
oform1=CREATEOBJECT("form1")
oform1.Show
RETURN
DEFINE CLASS form1 AS form
    Top = 0
    Left = 0
    Height = 238
    Width = 120
    DoCreate = .T.
    Caption = "Form1"
    Name = "Form1"
   ADD OBJECT list1 AS listbox WITH ;
        RowSourceType = 9, ;
        RowSource = "P_list", ;
        Height = 181, ;
        Left = 40, ;
        Top = 10, ;
        Width = 50, ;
        Name = "List1"
    
    PROCEDURE Load
        PUBLIC P_list
        DEFINE POPUP P_list
        DEFINE BAR 1 OF P_LIST ;
          PROMPT "";
          COLOR , RGB(255,255,255,192,0,0)
        DEFINE BAR 2 OF P_LIST ;
          PROMPT "";
          COLOR , RGB(255,255,255,192,0,192)
        DEFINE BAR 3 OF P_LIST ;
          PROMPT "";
           COLOR , RGB(255,255,255,192,255,0)
       DEFINE BAR 4 OF P_LIST ;
          PROMPT "";
           COLOR , RGB(255,255,255,192,255,255)
       DEFINE BAR 5 OF P_LIST ;
          PROMPT "";
           COLOR , RGB(255,255,255,0,255,255)
        DEFINE BAR 6 OF P_LIST ;
          PROMPT "";
           COLOR , RGB(255,255,255,0,255,255)
        DEFINE BAR 7 OF P_LIST ;
          PROMPT "";
           COLOR , RGB(255,255,255,0,0,255)

    ENDPROC
ENDDEFINE





Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Mike,

I've seen an OCX which have the functionality of a colorpicker on:


I've downloaded this one, but using it in VFP, will result in an empty combobox. Probably the OCX doesnot meet the VFP requirements?

I don't think I can use your popup suggestion because i want to use it in a grid, so each column in a row could have a different color.

André
 
andre65

Like I said, it is possible to show colors in a combobox, but you have to deal with the "character" factor. Here is another example:
Code:
PUBLIC oform1
oform1=CREATEOBJECT("form1")
oform1.mygrid.column1.addobject("combo1","combo1")
oform1.mygrid.column1.currentcontrol = "combo1"
oform1.mygrid.column1.sparse = .f.
oform1.mygrid.rowheight = 28
oform1.Show
RETURN
DEFINE CLASS form1 AS form
    Top = 0
    Left = 0
    Height = 238
    Width = 160
    DoCreate = .T.
    Caption = "Form1"
    Name = "Form1"
  ADD OBJECT myGrid as grid WITH ;
       columncount=1,;
       width = 150
    PROCEDURE Load
      CREATE CURSOR mycursor (color c(10))
      GO bottom
      APPEND blank
        PUBLIC P_list
        DEFINE POPUP P_list
        DEFINE BAR 1 OF P_LIST ;
          PROMPT "Red";
          COLOR , RGB(255,255,255,192,0,0)
        DEFINE BAR 2 OF P_LIST ;
          PROMPT "Purple";
          COLOR , RGB(255,255,255,192,0,192)
        DEFINE BAR 3 OF P_LIST ;
          PROMPT "Green";
           COLOR , RGB(255,255,255,192,255,0)
       DEFINE BAR 4 OF P_LIST ;
          PROMPT "Light Blue";
           COLOR , RGB(255,255,255,192,255,255)
       DEFINE BAR 5 OF P_LIST ;
          PROMPT "Cyan";
           COLOR , RGB(255,255,255,0,255,255)

    ENDPROC
ENDDEFINE
DEFINE CLASS combo1 as ComboBox
visible = .t.
rowsourcetype = 9
rowsource = "P_list"
enddefine

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Mike,

This looks good.

I see that once selected a color, the combo displays the text 'Red' instead of showing the color like the popup does. Is there a way to visualize the color red?

André
 
sure it can be done. Mike, I took you code and added something to the combo, hope you don't mind

PUBLIC oform1
oform1=CREATEOBJECT("form1")
oform1.mygrid.column1.addobject("combo1","combo1")
oform1.mygrid.column1.currentcontrol = "combo1"
oform1.mygrid.column1.sparse = .f.
oform1.mygrid.rowheight = 28
oform1.Show
RETURN
DEFINE CLASS form1 AS form
Top = 0
Left = 0
Height = 238
Width = 160
DoCreate = .T.
Caption = "Form1"
Name = "Form1"
ADD OBJECT myGrid as grid WITH ;
columncount=1,;
width = 150
PROCEDURE Load
CREATE CURSOR mycursor (color c(10))
GO bottom
APPEND blank
PUBLIC P_list
DEFINE POPUP P_list
DEFINE BAR 1 OF P_LIST ;
PROMPT "Red";
COLOR , RGB(255,255,255,192,0,0)
DEFINE BAR 2 OF P_LIST ;
PROMPT "Purple";
COLOR , RGB(255,255,255,192,0,192)
DEFINE BAR 3 OF P_LIST ;
PROMPT "Green";
COLOR , RGB(255,255,255,192,255,0)
ENDPROC
ENDDEFINE

DEFINE CLASS combo1 as ComboBox
visible = .t.
rowsourcetype = 9
rowsource = "P_list"
PROCEDURE interactivechange
LOCAL lcPromptColor , lcColor
lcPromptColor = this.value &&PRMBAR("p_List",BAR())
DO CASE
CASE lcPromptColor = 'Red'
lcColor = "RGB(192,0,0)"
CASE lcPromptColor = 'Purple'
lcColor = "RGB(192,0,192)"
CASE lcPromptColor = 'Green'
lcColor = "RGB(192,255,0)"
ENDCASE
this.BackColor = &lcColor
ENDPROC
ENDDEFINE
 
mejiaks

Mike, I took you code and added something to the combo, hope you don't mind

That's what we are here for. :)



Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top