|
-
Jul 7th, 2008, 10:27 AM
#1
Match the values of 3 numericUpDown's
Hi All,
I'm using VB 2008 and I have a combobox filled with all ARGB knowncolors.
When I do a selection in the combobox, the numericupdown's showing me the exact value.
What I want is, when I select some values in the numericupdown's and there's a match with the corresponding color in the combobox. The combobox will show the colors name.
How can I do that?
Thanks in advance,
sparrow1
Last edited by sparrow1; Jul 7th, 2008 at 10:55 AM.
-
Jul 7th, 2008, 11:34 AM
#2
Re: Match the values of 3 numericUpDown's
will this be a usefull?
Code to fill combobox (cmb1) with color name
Code:
Dim dtColor As DataTable = New DataTable("Color")
dtColor.Columns.Add(New DataColumn("Name"))
dtColor.Columns.Add(New DataColumn("RGBValue"))
Dim c As Color = Color.Blue
Dim i As Integer
For i = 0 To 165
c = Color.FromKnownColor(i)
If Not c.IsSystemColor Then
Dim drNewColor As DataRow
drNewColor = dtColor.NewRow
drNewColor.Item("Name") = c.ToKnownColor.ToString
drNewColor.Item("RGBValue") = c.R.ToString & "," & c.G.ToString & "," & c.B.ToString
dtColor.Rows.Add(drNewColor)
End If
Next
cmb1.DataSource = dtColor
cmb1.DisplayMember = "Name"
cmb1.ValueMember = "RGBValue"
let's say NumericUpDown control are R,G,B respectively...
so to display select the color in cmb1 you can use...
Code:
cmb1.SelectedValue = R.Value.ToString & "," & G.Value.ToString & "," & B.Value.ToString
__________________
Rate the posts that helped you 
-
Jul 8th, 2008, 03:33 AM
#3
Re: Match the values of 3 numericUpDown's
Hi,
It's not working.
I can already show the proper value in the numericUpDown, but what I want is, if you select the R.value = 255 then the combobox should give the name: RED.
Is that possible and if so, how should I do that?
Wkr,
sparrow1
-
Jul 8th, 2008, 08:37 AM
#4
Re: Match the values of 3 numericUpDown's
if you have use above method to pupulate your combobox then setting
Code:
cmb1.SelectedValue = "255,0,0"
will select the Red color in comobox.
__________________
Rate the posts that helped you 
-
Jul 8th, 2008, 08:53 AM
#5
Re: Match the values of 3 numericUpDown's
sparrow, do you have three combo boxes?
cmb1 = r value
cmb2 = g value
cmb3 = b value
-
Jul 8th, 2008, 09:11 AM
#6
Re: Match the values of 3 numericUpDown's
 Originally Posted by riteshjain1982
will this be a usefull?
Code to fill combobox (cmb1) with color name
Code:
Dim dtColor As DataTable = New DataTable("Color")
dtColor.Columns.Add(New DataColumn("Name"))
dtColor.Columns.Add(New DataColumn("RGBValue"))
Dim c As Color = Color.Blue
Dim i As Integer
For i = 0 To 165
c = Color.FromKnownColor(i)
If Not c.IsSystemColor Then
Dim drNewColor As DataRow
drNewColor = dtColor.NewRow
drNewColor.Item("Name") = c.ToKnownColor.ToString
drNewColor.Item("RGBValue") = c.R.ToString & "," & c.G.ToString & "," & c.B.ToString
dtColor.Rows.Add(drNewColor)
End If
Next
cmb1.DataSource = dtColor
cmb1.DisplayMember = "Name"
cmb1.ValueMember = "RGBValue"
let's say NumericUpDown control are R,G,B respectively...
so to display select the color in cmb1 you can use...
Code:
cmb1.SelectedValue = R.Value.ToString & "," & G.Value.ToString & "," & B.Value.ToString
This code is indeed not working correctly. The first item on the list in the ComboBox is '0' followed by what seems to be all the other colors. As soon as you change a value in any of the NUD's the ComboBox loses it's selected index.
-
Jul 8th, 2008, 10:08 AM
#7
Re: Match the values of 3 numericUpDown's
 Originally Posted by JuggaloBrotha
This code is indeed not working correctly. The first item on the list in the ComboBox is '0' followed by what seems to be all the other colors.
You can change For i = 0 To 165 as per your need.
 Originally Posted by JuggaloBrotha
As soon as you change a value in any of the NUD's the ComboBox loses it's selected index.
make sure combination of RGB NUD has any knownColor Name.
__________________
Rate the posts that helped you 
-
Jul 8th, 2008, 10:33 AM
#8
Re: Match the values of 3 numericUpDown's
Code:
Private Sub RGBnudValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles Rnud.ValueChanged, Gnud.ValueChanged, Bnud.ValueChanged
Dim aColor = Color.FromArgb(Convert.ToInt32(Rnud.Value), Convert.ToInt32(Gnud.Value), Convert.ToInt32(Bnud.Value))
Dim conv As ColorConverter = New ColorConverter()
Debug.WriteLine(conv.ConvertFromString(aColor.ToArgb.ToString))
End Sub
conv.ConvertFromString(aColor.ToArgb.ToString is a color name.
-
Jul 9th, 2008, 02:04 AM
#9
Re: Match the values of 3 numericUpDown's
 Originally Posted by dbasnett
sparrow, do you have three combo boxes?
cmb1 = r value
cmb2 = g value
cmb3 = b value
Hi,
I have 1 combobox and 3 numericUpDown's. and I'm populating the combobox in the formload like this:
vb.net Code:
Dim color() As String
Kleur = System.Enum.GetNames(GetType(KnownColor))
ComboBox1.Items.AddRange(color)
This is how I show the values in the numericupdown's after selection in the combobox selectedindexchanged:
vb.net Code:
Dim ColorEnum As Object
ColorEnum = System.Enum.Parse(GetType(KnownColor), ComboBox1.Text)
Dim selectedColor As KnownColor
selectedColor = CType(ColorEnum, KnownColor)
Dim color As Color = System.Drawing.Color.FromKnownColor(selectedColor)
ComboBox1.BackColor = System.Drawing.Color.FromKnownColor(selectedColor)
Label6.BackColor = color
nmr1.Value = kleur.R
nmr2.Value = kleur.G
nmr3.Value = kleur.B
How can I do a selection value in the numericupdown's and if there's a match the combobox will shown the name of the color.
Wkr,
sparrow1
-
Jul 9th, 2008, 09:31 AM
#10
Re: Match the values of 3 numericUpDown's
i posted code with 3 numeric up/downs that returned a color name based on the value of the numeric up/downs, if there is one.
Last edited by dbasnett; Jul 9th, 2008 at 10:02 AM.
-
Jul 9th, 2008, 09:51 AM
#11
Re: Match the values of 3 numericUpDown's
 Originally Posted by sparrow1
Hi,
I have 1 combobox and 3 numericUpDown's. and I'm populating the combobox in the formload like this:
vb.net Code:
Dim color() As String
Kleur = System.Enum.GetNames(GetType(KnownColor))
ComboBox1.Items.AddRange(color)
This is how I show the values in the numericupdown's after selection in the combobox selectedindexchanged:
vb.net Code:
Dim ColorEnum As Object
ColorEnum = System.Enum.Parse(GetType(KnownColor), ComboBox1.Text)
Dim selectedColor As KnownColor
selectedColor = CType(ColorEnum, KnownColor)
Dim color As Color = System.Drawing.Color.FromKnownColor(selectedColor)
ComboBox1.BackColor = System.Drawing.Color.FromKnownColor(selectedColor)
Label6.BackColor = color
nmr1.Value = kleur.R
nmr2.Value = kleur.G
nmr3.Value = kleur.B
How can I do a selection value in the numericupdown's and if there's a match the combobox will shown the name of the color.
Wkr,
sparrow1
dbasnett's code works but not every color combination has a name in that color enumeration so most of your combinations will result in a selected index of -1.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|