[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
www.undertowsoftware.com • View topic - Polygon colors????

Polygon colors????

A forum made available for users of the MapPro OCX SDK to exchange ideas, ask each other questions, etc.

Polygon colors????

Postby FletcherJ » Wed Feb 01, 2012 8:34 pm

Hi all,

Simple question.
I create a polygon using the axMapPro1.Cad.Polygon() method. One of the options is to specify a color. Again, the manual is a little weak on the docs so I thought I would check here. Using VS 2010 and C#

If I set the brush mode = Color.FromArgb(0, 255, 0, 0).ToArgb(), I would expect to see the color in red (since I am using ARGB, the first value is the alpha value).
Just to make sure I am not getting confused in my old age, I also assign the same value to a label (which I can click on to show/hide the polygon).

The code to assign the color is simply:
tpg1.Brush.Color = Color.FromArgb(0, 255, 0, 0).ToArgb();
and the label is:
this.label1.ForeColor = Color.FromArgb(tpg1.Brush.Color);

Where tpg1 is defined as:
MapPro80.CadObj tpg1 ;

I have commented out the code to set the brush.mode, brush.style, and pen.ROP

The pen settings (which I thought were just to paint the outline) are:
tpg1.Pen.Color = Color.FromArgb(0, 255, 255, 255).ToArgb(); // black
tpg1.Pen.Width = 1;

Given all that, I would expect the polygon to render in red. The label is red. But the polygon is colored blue.

At first I thought it was that the conversion from/to argb was the culpret (it still might be). But that is why I used the color in the control to set the color of the label.

I know I can "using System.Visualbasic.xxx" and then use the VB RGB method, but I kinda thought that I could do this in C# without calling in VB. Of course, I can always write my own RGB method (heck its just a 3 byte value) as well, but I haven't had to write code to do things like that for a decade or two. Now back in the 80s....

Any ideas on what I am missing?

Thanks,
me




When I run the app
User avatar
FletcherJ
Active User
Active User
 
Posts: 36
Joined: Fri Jan 20, 2012 5:33 pm

Re: Polygon colors????

Postby FletcherJ » Thu Feb 02, 2012 2:52 am

Hi all,

Ok, I found the problem. VS 2010 Colors require an alpha value (the a in ARGB). And instead of being smart by making the alpha value = 0 for a solid color, they require that it be 255 for a solid color.
This means that to get red, I actually need to pass it -65536, to get green, I need to pass a control -16744448, etc.

Whereas the MapOCX control just expects a standard RGB color value. Now I just need to figure out if there is a simple convert untility that filters out the alpha portion or if I have to write one (I have to believe that one exists...)

Anyway, now that I have this figured out, I thought I would post it so none of you wasted time trying to figure it out.

Take care,
me
User avatar
FletcherJ
Active User
Active User
 
Posts: 36
Joined: Fri Jan 20, 2012 5:33 pm

Re: Polygon colors????

Postby Gyrotech » Thu Feb 02, 2012 9:45 am

Thanks, but why are you using ARGB() since there is no alpha and the value will be zero ? Please, don't tell me "because it's there" ;-) Are you new to C# ?
User avatar
Gyrotech
Frequent User
Frequent User
 
Posts: 52
Joined: Mon May 03, 2010 11:23 pm

Re: Polygon colors????

Postby FletcherJ » Thu Feb 02, 2012 4:25 pm

Gyrotech,

I am using argb() because I need to use the Color structure to set colors for controls etc. And that does not have a .ToRGB or .FromRGB method, only the argb versions. Yes, I can create my own RGB method (and did out of frustration), but I was hoping for a better way. Yes, I did find an RGB method that was part of the VB library, but I didn't want to load the whole library just for one simple easy to write method.

In terms of my experience, I have been coding since the early 80s. I am currently working on projects written in PHP, Javascript, MySQL, MSSQL, C#, VB, Java, VFP, and a few others. This week I have had to write code in PHP, MySQL, Javascript, C#, and VB. But as soon as I get this map thing to a point, I also have a bunch of MSSQL coding I need to do (hopefully starting on Friday.) My point is that I have to jump from language to language and often, I know exactly what I want to do and some very good ways to accomplish it. But for the life of me, I can't figure out which method is the correct one to use for a given language. The good thing is that I don't have to worry about getting bored very often... :)

Anyway, if you know of a better way to handle having one value that I can pass to controls and to a polygon and get the same image, please let me know. It would certainy save me some time (which is why I posted here in the first place.)

Take care,

me
User avatar
FletcherJ
Active User
Active User
 
Posts: 36
Joined: Fri Jan 20, 2012 5:33 pm

Re: Polygon colors????

Postby FletcherJ » Thu Feb 09, 2012 7:15 pm

Hi all,

In case anyone cares, the easy way to use the VS.NET Color structure for colors with the MapOCX is via the following approach:

xxx.Brush.Color = ColorTranslator.ToOle(Color.Blue);

Take care,

me
User avatar
FletcherJ
Active User
Active User
 
Posts: 36
Joined: Fri Jan 20, 2012 5:33 pm

Re: Polygon colors????

Postby StephenE » Fri Feb 10, 2012 2:24 am

Of course that's the function to use. You can also use it to specify a pen color, as shown by the line: axMapPro1.Cad.Font.Color = ColorTranslator.ToOle(Color.Red) (in the axMapPro1_ClickEvent routine of the sample code on teh DVD) to specify a transparent color, as shown by the line: axMapPro1.UnderlayImg.TransparentColor = ColorTranslator.ToOle(Color.White) (in the radioButton6_CheckedChanged routine of the sample code) and so on.
User avatar
StephenE
New User
New User
 
Posts: 9
Joined: Mon Feb 06, 2012 4:49 pm


Return to MapPro OCX

Who is online

Users browsing this forum: No registered users and 2 guests

cron