Steve Magoon
1/1/2005 2:16:00 AM
Why doesn't the scrolling function (below) work for the sine wave as it does
for the FillEllipse function?
Thanks for any help. Please pardon my crosspost to Controls - wasn't sure
which forum would be best to post to.
Steve
public class CustomScrollCtrl : System.Windows.Forms.ScrollableControl
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
private PointF[] pts;
private double[] wave;
public CustomScrollCtrl()
{
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();
pts = new PointF[400];
// Generate a sinewave for display: 10 Hz, 0 degrees phase, a magnitude of
10, and 400 points.
// Returns a double[].
wave = FunctionGenerator.SineWave(10, 0, 10, 400);
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if( components != null )
components.Dispose();
}
base.Dispose( disposing );
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
}
#endregion
protected override void OnPaint(PaintEventArgs pe)
{
Graphics g = pe.Graphics;
Brush backBrush = new SolidBrush(Color.Violet);
Brush circleBrush = new SolidBrush(Color.Red);
Brush foreBrush = new SolidBrush(this.ForeColor);
// Set up our drawing surface
RectangleF rect = new RectangleF(DisplayRectangle.X, DisplayRectangle.Y,
DisplayRectangle.Width, DisplayRectangle.Height);
g.FillRectangle(backBrush, rect);
g.FillEllipse(circleBrush, rect);
using (Pen pen = new Pen(Color.BlueViolet, 0))
{
for (int i = 0; i < pts.GetLength(0); i++)
{
pts[i].X = i;
pts[i].Y = (float) (wave[i] + 50);
}
g.DrawLines(pen, pts);
}
// Calling the base class OnPaint
base.OnPaint(pe);
}
}