Visual basic 6.0 combo boxes and colour

im a useless coder but something like....

- goto combobox properties and set up a list of values for it, or add them at runtime in your form_load procedure using .additem

- create a 'combobox1_change()' procedure...

- enter something like (syntax may vary)

if combobox1.text = "red" then form1.backcolor="vbred"
if combobox1.text ="black" then form1.backcolor="vbblack"


or even better (assuming combobox contains proper colour names)


on error resume next
form1.backcolor = combobox1.text


im not 100% on syntax as not used vb6 for years... in fact none of above might work, but the idea is right. lol


the QBColor way of setting colors is just using a palette of 16 cols I think, like Form1.BackColor = QBColor(0) ...the 0 refers to black in this case

jobs a goodun :)
 
Last edited:
I know in VB 2008 the following works:

Public Class Form1
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
If ComboBox1.Text = "red" Then Me.BackColor = Color.Red
If ComboBox1.Text = "blue" Then Me.BackColor = Color.Blue
End Sub
End Class
 
pretty simple stuff to be fair, you should read up on some of the basics.

in delphi (similar to vb) it can be achieved in different ways:

if ComboBox1.Selected.Text = 'green' then Self.Color:= clGreen
else
if ComboBox1.Selected.Text = 'blue' then Self.Color:= clBlue;

or

case ComboBox1.ItemIndex of
0:
begin
clGreen;
end;

1:
begin
clBlue;
end;
end;
 
Back
Top Bottom