3 Replies - 25077 Views - Last Post: 09 September 2008 - 11:33 AM Rate Topic: -----

#1 MrWobbles  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 31
  • View blog
  • Posts: 328
  • Joined: 11-April 08

Converting a string to Drawing.Color

Posted 09 September 2008 - 09:11 AM

I have this code:

 Dim color As Drawing.Color
		Dim tempString As String
		If My.Forms.portfolioGenerator.portTabs.SelectedIndex = 0 Then
			tempString ="ff804040"
			color = System.Drawing.ColorTranslator.FromHtml(tempString)
		End If
 Return color



And it is throwing this exception:

System.Exception: ff804040 is not a valid value for Int32. ---> System.FormatException: Input string was not in a correct format.

It was working before, and I am not sure what changed to break it. If anyone sees something I am missing, please let me know. :)

This post has been edited by MrWobbles: 09 September 2008 - 09:17 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Converting a string to Drawing.Color

#2 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Converting a string to Drawing.Color

Posted 09 September 2008 - 11:02 AM

You could try using the FromArgb method to convert the color.

color = System.Drawing.Color.FromArgb("&H" + tempString)

Was This Post Helpful? 0
  • +
  • -

#3 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9088
  • View blog
  • Posts: 34,139
  • Joined: 12-June 08

Re: Converting a string to Drawing.Color

Posted 09 September 2008 - 11:04 AM

I was under the impression that the value had to be a color name.. like 'blue' or 'red'.

From MSDN
Public Sub FromHtml_Example(ByVal e As PaintEventArgs)

    ' Create a string representation of an HTML color.
    Dim htmlColor As String = "Blue"

    ' Translate htmlColor to a GDI+ Color structure.
    Dim myColor As Color = ColorTranslator.FromHtml(htmlColor)

    ' Fill a rectangle with myColor.
    e.Graphics.FillRectangle(New SolidBrush(myColor), 0, 0, 100, 100)
End Sub



Was This Post Helpful? 0
  • +
  • -

#4 MrWobbles  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 31
  • View blog
  • Posts: 328
  • Joined: 11-April 08

Re: Converting a string to Drawing.Color

Posted 09 September 2008 - 11:33 AM

That was the problem, it could have been either (Hex or Color name), I fixed that and now it works great.

This post has been edited by MrWobbles: 09 September 2008 - 11:34 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1