Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Legend Item Image

Solved!
Go to solution

Can I  override the Legend Item Image? i.e. make the image a different solid color for each item in the legent item collection. The waveform line and plot points are difficult to see.

0 Kudos
Message 1 of 2
(3,494 Views)
Solution
Accepted by topic author JerryBailey

Hello -

 

You can do this by creating a class that implements ILegendItemSouce and drawing the solid color in the the DrawLegendItem method.  Your code might look similar to the following:

 

class SolidColorLegendItemSource : ILegendItemSource
{
  private Color itemColor;

  public SolidColorLegendItemSource(Color color)
  {
    itemColor = color;
  }

  public void DrawLegendItem(ComponentDrawArgs args)
  {
    // create the bounds for the solid fill rectangle
    int top = args.Bounds.Height / 2 + args.Bounds.Y - args.Bounds.Height / 4;
    int height = args.Bounds.Height / 2;
    int left = args.Bounds.X;
    int width = args.Bounds.Height;

    args.Graphics.FillRectangle(new SolidBrush(itemColor), new Rectangle(new Point(left, top), new Size (width, height)));
  }

  public event EventHandler Disposed;
  protected virtual void OnDisposed(EventArgs e)
  {
    if (Disposed != null)
      Disposed(this, e);
  }

  public event EventHandler LegendItemChanged;
  protected virtual void OnLegendItemChanged(EventArgs e)
  {
    if (LegendItemChanged != null)
      LegendItemChanged(this, e);
  }
}

 

NickB_07-25_08-31-28.png

 

Let me know if you have any questions -

 

NickB

National Instruments

0 Kudos
Message 2 of 2
(3,487 Views)