Re: Dynamically create Drawing.Pens color?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Try Int32.Parse or TryParse to convert from string to a 32 bit value and then use that in the FromArgb.

--
--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.


"NathanC" <NathanC@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:D99DA308-E1AF-4EB8-AF92-623675B86235@xxxxxxxxxxxxxxxx
Sorry - I thought I had included that in the previous posts:

dvGetSeatStatus returns multiple values from a web service- the two I am
using in this case are named 'fore_color' and 'back_color' - these values are
long RGB values (189500)

strFore = dvGetSeatStatus(0)("fore_color").ToString() - I was just hedging
my bets here when I first threw the code together. .ToString isn't required -
the values are already strings.

The fore_color and back_color values are to be used to color rectangles that
I am drawing. Each rectangle or 'seat' may have different fore_color and
back_color values, so instead of hardcoding the seat.DrawRectangle &
seat.FillRectangle color values (example:
seat.DrawRectangle(Drawing.Pens.White,etc...) I need to be able to define the
Drawing.Pen color value dynamically using the long RGB value.

Up to this point, I have not had sucess.

Hopefully that helps,

Thanks very much -

"Bob Powell [MVP]" wrote:

It's impossible to see whats going on here because we don't have all the
info.

#1 What type is the object in the dvGetSeatStatus array?
#2 Why convert tostring and then back to something else? Why not convert
straight to the type you need?



--
--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.


"NathanC" <NathanC@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:8E47A66B-8952-4B0A-8810-7A661AAF8441@xxxxxxxxxxxxxxxx
> Still not working - not sure why - this appears to be the thing to do.
>
> Dim strFore As String
> Dim strBack As String
>
> strFore = dvGetSeatStatus(0)("fore_color").ToString()
> strBack = dvGetSeatStatus(0)("back_color").ToString()
>
> seat.DrawRectangle(New
> Drawing.Pen(Drawing.Color.FromArgb(Convert.ToInt32(strFore))), (xpos -
> offset), (ypos), 10, 16)
>
> '-----------------------------------------------------
>
> I have also tried this:
> Dim fore_color = System.Drawing.Color
> Dim strFore As String
>
> strFore = dvGetSeatStatus(0)("fore_color").ToString()
> fore_color = Drawing.Color.FromArgb(strFore)
> seat.DrawRectangle(New Drawing.Pen(fore_color), (xpos - offset), > (ypos),
> 10,
> 16)
>
> I know that the FromArgb function is correctly converting the returned
> value
> from the web service into a useable color - because I am doing it
> elsewhere
> on the site.
>
> Thanks,
>
> "Jeff Johnson" wrote:
>
>>
>> "Jeff Johnson" <i.get@xxxxxxxxxxx> wrote in message
>> news:OFdcImpqHHA.3284@xxxxxxxxxxxxxxxxxxxxxxx
>>
>> > Or, since the poster appears to be using VB (unless he's just >> > dropping
>> > the
>> > semicolons in his sample code),
>> >
>> > Using pen As New Pen(fore_color)
>> > [...]
>> > End Using
>> > [...]
>>
>> Hmmm, I forgot VB was case sensitive (been writing too much C#). I'm >> not
>> positive if it will be happy using a class name as an identifier. >> Might
>> be
>> better to use
>>
>> Using borderPen As New Pen(fore_color)
>> [...]
>> End Using
>> [...]
>>
>>
>>



.



Relevant Pages

  • Re: Dynamically create Drawing.Pens color?
    ... Find great Windows Forms articles in Windows Forms Tips and Tricks ... Answer those GDI+ questions with the GDI+ FAQ ... Dim strFore As String ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: Dynamically create Drawing.Pens color?
    ... Find great Windows Forms articles in Windows Forms Tips and Tricks ... Dim strFore As String ... offset), (ypos), 10, 16) ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: How to create a Serialnumber for App programmatically?
    ... > Find great Windows Forms articles in Windows Forms Tips and Tricks ... > Answer those GDI+ questions with the GDI+ FAQ ... >> Information as String. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: problem displaying strings in a text box
    ... Find great Windows Forms articles in Windows Forms Tips and Tricks ... Answer those GDI+ questions with the GDI+ FAQ ... > I have a text box that must display a string readed from a MSDE database. ...
    (microsoft.public.dotnet.framework.windowsforms.controls)
  • Re: Hash Code Compression
    ... just for String -- is a Java int, ... My hash table is made up of an array of n LinkedLists (where n is a ... fact the hashTable is an array of LinkedLists is so that it handles ... Because i am currently building the dictionary file by trawling news articles each word I pull from an article needs to be checked in the dictionary to see if we already have it. ...
    (comp.lang.java.programmer)