2017-02-20 15 views
1

好了,所以我想一個textboxbackColor轉換爲在文本框中的文本(這是VB)轉換textbox.text到textbox.backcolor

這是我,但我說不能將字符串轉換爲彩色:

textbox.backColor = textbox.text (example of text in the box "ff000000") 

我得到了文本的方式是通過將一個文本框的背景色與此有關的文字:

TextBox3.Text = TextBox2.BackColor.Name 
+0

您沒有將文本框的背景顏色轉換爲文本。您只是將顏色名稱(字符串)分配給textbox3.text(另一個字符串)。 – RSon1234

+0

是的,我意識到,我想要的顏色的名稱?但我想在另一個文本框上使用該顏色的名稱backcolor – TextToColour

回答

0

可以使用ColorTranslator類做到這一點。我假設它是RGB ...這需要一個十六進制代碼並將其轉換爲其顏色...

Dim col As System.Drawing.Color = System.Drawing.ColorTranslator.FromHtml(txtbox.Text.Trim()) 

If col IsNot Nothing Then 
    txtbox.BackColor = col 
End If 
+0

欣賞幫助,非常感謝:D – TextToColour

+0

只需製作一個Tweek Dim col As System.Drawing.Color = System.Drawing.ColorTranslator.FromHtml( 「#」&txtbox.Text.Trim()) – TextToColour