05-21-2012 09:31 AM
Hi, dear NI team.
In my winforms C# application I have a Legend with multiple LegendItem objects in it. (Using latest NI libraries)
My first question is about text wrapping:
Lets assume, that my legend has width = 200, and my legendItem A has a name that is much longer than can be displayed on avaliable space. I don't want to show scrollbar, what i want instead is text wrapped into two lines. Is it possible? (Watch attached image, left side of it)
My second question:
Do I have any control on legend item background color? Either background color for whole legend item or only background color of its caption area. (Watch attached image, right side of it)
I have many plots in my application, and there such a thing as "Active plot" in my application, this is the plot that user is currently working with. Lets say, that if I enter before/after draw event handler of LegendItem, I have a way to know whether this item is connected to active plot or not. And it is not anly the case in those event handlers, legend item in it's Tag has some object that has every relevant information on the connected plot.
So, what I need to implement is some distinction between active plot's legend item and other legend items. What can you suggest to me to implement such a feature?
Thanks in advance, best regards!
05-23-2012 09:22 AM - edited 05-23-2012 09:22 AM
Are you referencing the standard LegendItem component within the default .NET Framework? If so, you can check out the online Application Programming Interface (API) for the component to see what specific attributes we're able to modify; this should give a good indication of whether these changes are possible.
Just in case I've misunderstood, would I be able to take a look at the code that you've developed so far so that I can get a better idea of the specific functionality that you're after?
05-24-2012 01:27 AM
As far as I can understand, the control I am talking about is NI control for .NET. It is NationalInstruments.UI.Legend.LegendItem .
Regarding the functionality that I want to implement:
I can give you the code, but it will not help you in any way, because I didn't succeeded in implementing it through NI objects. Currently what I am doing is just drawing colored rectangle behind the LegendItem on control's paint event.
I will try to explain it once again(The situation below is simplified to clarify the behavior):
In my applications I have two plots: plot_A and plot_B, and I have user control called BigLegend of Legend type. BigLegend has two LegendItem controls in its Items collection. User can select some plot to be active one. This means that on some fields in my application will be shown information relevant for this active plot. And what I need is to give good visual indication of currently active plot. What I want to do is to fill the background of active plot's LegendItem with green color, while other LegendItem objects have their backround filled with white.
So I have two tree sequential questions:
1) Is it possible to change background color of LegendItem as it is shown on attached image in previous post?
2) Assuming you can know which plot is active just anytime you want, where it will be a best time to fill background? I mean on LegendItem's BeforeDraw event? Something else?
3)How can I fill the background with the color I want?
05-25-2012 10:36 AM - edited 05-25-2012 10:45 AM
When using the WaveformGraph and Legends, it is not possible to change the back color for the legend directly.
However, you can work around the problem and get the required functionality.
Below is the screenshot I got while playing around with the WaveformGraph and Legend controls.
Clicking on "Plot Test Data" button will draw some test data on the graph and hence something to show on the legends. Clicking on one of the legend, a message box will be displayed which shows which legend was clicked.
Furthermore, you can use this method to add additional functionality to your custom legends. If you want, you can change the back color of just the legend text, you can perform additional tasks like hide/show legends, control what happens on the graph depending on which legend is clicked, change colors of other legends and much more.
Take a look at the attached source files.
Hope this helps!