12-09-2008 05:43 AM
Is it possible to add a rectangle where all colors behind are inverted?
Or is it possible to have different plot area color, wave color, major division color for different areas of the graph.
I have attached a picture of what I want the result to be.
regards
Per Helge
12-16-2008 10:53 AM - edited 12-16-2008 10:54 AM
Hello Per Helge,
This is possible, but it requires a decent amount of work on your part. Basically, you will have to create your own CustomGraph class, inheriting from our WaveformGraph, and override the OnPaint method. Then what you will do is instead of drawing the control directly, you will instead draw the control to a bitmap, make your color inversions, and then draw that bitmap to the control. The only issue you may run into with this is that some fonts won't look as nice once they've been drawn to bitmap, so places where you have text (such as the axes) may look a little bit distorted. You can get around this by only drawing the bitmap of the actual plot area, instead of for the entire graph control. Note the differences below:
Because the code for converting the entire graph area to a bitmap and plotting is a little simpler, you can see that code below for reference:
public class CustomDrawingGraph : WaveformGraph
{
// The _invertRect is the rectangular area inside the
// Graph control which the user wants inverted colors
private Rectangle _invertRect = new Rectangle();
public Rectangle InvertRect
{
get { return _invertRect; }
set {_invertRect = value;}
}
protected override void OnPaint(PaintEventArgs e)
{
// Create a bitmap the height and width of the graph area
using (Bitmap bitmap = new Bitmap(Width, Height))
{
Graphics g = e.Graphics;
Graphics newG = Graphics.FromImage(bitmap);
PaintEventArgs newE = new PaintEventArgs(newG, e.ClipRectangle);
// Draw the control to the bitmap object and not directly to screen
base.OnPaint(newE);
// Code to invert pixel colors
for (int i = _invertRect.X; i < _invertRect.X + _invertRect.Width; i++)
{
for (int j = InvertRect.Y; j < InvertRect.Y + _invertRect.Height; j++)
{
Color bgColor = bitmap.GetPixel(i, j);
Color newColor = Color.FromArgb(230, 255 - bgColor.R, 255 - bgColor.G, 255 - bgColor.B);
bitmap.SetPixel(i, j, newColor);
}
}
g.DrawImage(bitmap, 0, 0);
}
}
}
Please let me know if you have any questions!
NickB
National Instruments
12-17-2008 09:35 AM
Thanks for the help.
I would like the area to move along when pan'ing. Now it seems as if the coordinates of the rectangle is given in pixel-coordinates on the screen, not in seconds or similar. Can I do that using annotations or similar somehow?
regards
-per helge