Setting FillColor on rectangle in GroupBox

I’ve got a groupBox (it has no controls, I’m just using a GroupBox for the look) with a bunch of text labels next to small rectangles. The idea is that as I get data from an external microcontroller on the state of various sensors, I will be changing the FillColor of the rectangles according to the value returned from the sensor. This is non-interactive, just to give you a visual on the sensor states.

I can’t, for the life of me, figure out how to do this though. I have a method in my application that handles parsing the serialized data from the microcontroller, and that’s working fine. However, I can’t seem to figure out what I need to do to change the fill color on the appropriate rectangle. When I use the auto-fill feature in RealStudio (I’m on 2011R1.1), I can select “Window1” (the app’s main window), then hit “.” and tab to bring up options. From there I can select either the group box, or the individual rectangle. If I choose the rectangle: “Window1.tensionSensorLeft” then hit “.” and tab, the only options that come up don’t allow me to change the fill color. If I chose “Window1.SensorStateGroup” then “.” then tab, I see a different list of options, but none are allow me to change the fill color of one of the rectangles inside this group box, far as I can tell.

Is there a simple way to do this as I have it set up, or do I need to put everything in a canvas just to change the fill color?

Thanks!

Don’t use rectangles. Use rectangular shaped canvases. You can easily do
g.fillRect
within the paint event of the canvases. In fact, I would make your canvases a control set so you can just use the paint event of the control set and use the index value passed to the paint event to determine which canvas needs painting. When you need to paint, call canvas.invalidate to force the painting.
More information forthcoming if needed.

why not use rectangles? low overhead I’d bet.

rectangle1.fillcolor=&cff0000

can’t get much easier

Autocomplete is not 100% infallible. Just type in “fillcolor” and move on.

Ok, so I did actually try just using “fillcolor” without the autocomplete, but I’m getting compile errors:

This method requires more parameters than were passed, Window1.gateOpen.FillColor = red

The rectangle is in Window1, the main window. The method containing the code is in a module in my application that I use to hold various utility methods.

If I don’t specify “Window.” in my code, it can’t find the rectangle because it’s out of scope:

This method or property does not exist, gateOpen.FillColor = red

Again, not sure if it matters, but I am using a 2011 version of RealStudio.

I’ll give the canvas thing a try, but I was hoping to keep this simple.

what is “red” … something you defined?

I am ASSUMING you created gateOpen on Window1 as a “rectangle” object

If so, all you need to do to make it red is

window1.gateOpen.Fillcolor=&cff0000

COLORS are not pre-defined… there is no “RED” constant… normally you define the colors as RGB triplets

&cff0000 is pure RED
&c00ff00 is pure GREEN
&c0000ff is pure BLUE

“red” and “green” are variables I’ve defined for the color values I want - just makes the code easier to read.

Your assumption is correct:

Ok, there’s something amiss with my rectangles. I just created a new one from scratch (dragging “rectangle” from the controls list to the window), and I’m able to set the fillcolor with that. I can’t see any difference between that rect and the ones I made a while back (months ago when I last worked on this project), when I compare the properties. They all look like the screen shot above.

I thought the issue might be that they were all inside a group Box, but that doesn’t seem to be the problem. I moved them right out onto the window and deleted the group box but I still can’t set the fill color.

The image you posted above shows that you have set the Index value of your rectangle, making it a control array. You have to specify the index when you refer to it:

Window1.gateOpen(0).FillColor = Red

Or, if you didn’t mean to make it a control array, clear the Index value of the control.

Thanks - removing the Index is indeed what fixed it.