Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

lstRGB.Items.Add(CStr(pixelColor.R) + " " + CStr(pixelColor.G) + " " + CStr(pixelColor.B))

 

As you can see I have added 3 separate values in the listbox.

 

Dim MyString As String

 

MyString = lstRGB.SelectedItem

 

 

lets say MyString is like "60 255 132" how do I split it in three parts ? one of them would be 60 second 255 and third 132... can you do it with split or substring ? it is 4am I can't think HELP! :)

"Everything should be made as simple as possible, but not simpler."

"It's not that I'm so smart , it's just that I stay with problems longer ."

- Albert Einstein

  • *Experts*
Posted

Yes, use the Split method. Then convert each color into an

integer and create a Color structure.

 

Dim MyColors() As String
MyColors = MyString.Split(" "c) ' Split MyString by space characters

Dim red, green, blue As Integer
red = Convert.ToInt32(MyColors(0))
green = Convert.ToInt32(MyColors(1))
blue = Convert.ToInt32(MyColors(1))

Dim MyColor As Color = Color.FromArgb(red, green, blue)

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

Posted
lol thx guys

"Everything should be made as simple as possible, but not simpler."

"It's not that I'm so smart , it's just that I stay with problems longer ."

- Albert Einstein

Posted

now it works like this:

 

Dim MyArray() As String

Dim MyString As String

 

MyString = lstRGB.SelectedItem

MyArray = MyString.Split(" "c)

 

lblIndexSelect.BackColor = _

Color.FromArgb(CByte(MyArray(0)), CByte(MyArray(1)), CByte(MyArray(2)))

 

 

is there any difference between CByte and Convert.ToByte ?

"Everything should be made as simple as possible, but not simpler."

"It's not that I'm so smart , it's just that I stay with problems longer ."

- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...