[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

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);

}

}


5 Answers

Bob Powell

1/1/2005 3:15:00 PM

0

Perhaps if you post code I can compile it'll be easier to give a definite
answer...

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tips...

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/f...

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.





"Steve Magoon" <steve_magoon@hotmail.com> wrote in message
news:uSMRVf67EHA.2804@TK2MSFTNGP15.phx.gbl...
> 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);
>
> }
>
> }
>
>


Steve Magoon

1/1/2005 11:06:00 PM

0

Bob,

Sorry. How should I post the code so you can compile?

Steve

"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
news:ObQ1KTB8EHA.2032@tk2msftngp13.phx.gbl...
> Perhaps if you post code I can compile it'll be easier to give a definite
> answer...
>
> --
> Bob Powell [MVP]
> Visual C#, System.Drawing
>
> Find great Windows Forms articles in Windows Forms Tips and Tricks
> http://www.bobpowell.net/tips...
>
> Answer those GDI+ questions with the GDI+ FAQ
> http://www.bobpowell.net/f...
>
> All new articles provide code in C# and VB.NET.
> Subscribe to the RSS feeds provided and never miss a new article.
>
>
>
>
>
> "Steve Magoon" <steve_magoon@hotmail.com> wrote in message
> news:uSMRVf67EHA.2804@TK2MSFTNGP15.phx.gbl...
>> 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);
>>
>> }
>>
>> }
>>
>>
>
>


Bob Powell

1/2/2005 11:56:00 AM

0

There's no function to generate the sine waves. I reproduced something that
filled the wave array with sine function info but I don't see in your
control what you think is wrong with it. I see an ellipse on a background
with the wiggly sine-waves on top... there's no scrolling going on.

If you want questions answered then post code that reproduces the problems
you are having.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tips...

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/f...

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.





"Steve Magoon" <steve_magoon@hotmail.com> wrote in message
news:%23i6v$ZF8EHA.2788@TK2MSFTNGP15.phx.gbl...
> Bob,
>
> Sorry. How should I post the code so you can compile?
>
> Steve
>
> "Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
> news:ObQ1KTB8EHA.2032@tk2msftngp13.phx.gbl...
> > Perhaps if you post code I can compile it'll be easier to give a
definite
> > answer...
> >
> > --
> > Bob Powell [MVP]
> > Visual C#, System.Drawing
> >
> > Find great Windows Forms articles in Windows Forms Tips and Tricks
> > http://www.bobpowell.net/tips...
> >
> > Answer those GDI+ questions with the GDI+ FAQ
> > http://www.bobpowell.net/f...
> >
> > All new articles provide code in C# and VB.NET.
> > Subscribe to the RSS feeds provided and never miss a new article.
> >
> >
> >
> >
> >
> > "Steve Magoon" <steve_magoon@hotmail.com> wrote in message
> > news:uSMRVf67EHA.2804@TK2MSFTNGP15.phx.gbl...
> >> 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);
> >>
> >> }
> >>
> >> }
> >>
> >>
> >
> >
>
>


Bob Powell

1/3/2005 9:19:00 AM

0

Hi Steve,
I adjusted your control to use a matrix rather than the display rectangle.
This has the advantage of shifting the whole drawing surface so that you
just do the output based upon the fixed origin rather than worrying about
where the display has been moved to. This principle is actually explained in
some detail in my Windows Forms Tips and Tricks article on understanding
auto-scroll.

See the code below.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tips...

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/f...

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

----------------------------------------------------------------------------

using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Data;
using System.Windows.Forms;

namespace WindowsApplication1
{
public class CustomScrollCtrl : System.Windows.Forms.ScrollableControl
{
private System.ComponentModel.Container components = null;
private PointF[] pts;
private double[] wave;

public CustomScrollCtrl()
{
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);


//alternatively... use a matrix.
rect=ClientRectangle;
Matrix mx=new
Matrix(1,0,0,1,this.AutoScrollPosition.X,this.AutoScrollPosition.Y);
g.Transform=mx;


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);

}
}
}


"Steve Magoon" <steve_magoon@hotmail.com> wrote in message
news:uNsC$UT8EHA.4028@TK2MSFTNGP15.phx.gbl...
> Bob,
>
> I've attached C# files that reproduce my problem. I can get the red
ellipse
> to scoll just fine, but at least for me, the Sine wave will not scroll
with
> it. It looks like it's repainting the ellipse just fine, but not the wave.
> What am I doing wrong?
>
> Thanks man,
>
> Steve
>
>
> "Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
> news:eXA6YIM8EHA.3124@TK2MSFTNGP11.phx.gbl...
> > There's no function to generate the sine waves. I reproduced something
> > that
> > filled the wave array with sine function info but I don't see in your
> > control what you think is wrong with it. I see an ellipse on a
background
> > with the wiggly sine-waves on top... there's no scrolling going on.
> >
> > If you want questions answered then post code that reproduces the
problems
> > you are having.
> >
> > --
> > Bob Powell [MVP]
> > Visual C#, System.Drawing
> >
> > Find great Windows Forms articles in Windows Forms Tips and Tricks
> > http://www.bobpowell.net/tips...
> >
> > Answer those GDI+ questions with the GDI+ FAQ
> > http://www.bobpowell.net/f...
> >
> > All new articles provide code in C# and VB.NET.
> > Subscribe to the RSS feeds provided and never miss a new article.
> >
> >
> >
> >
> >
> > "Steve Magoon" <steve_magoon@hotmail.com> wrote in message
> > news:%23i6v$ZF8EHA.2788@TK2MSFTNGP15.phx.gbl...
> >> Bob,
> >>
> >> Sorry. How should I post the code so you can compile?
> >>
> >> Steve
> >>
> >> "Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
> >> news:ObQ1KTB8EHA.2032@tk2msftngp13.phx.gbl...
> >> > Perhaps if you post code I can compile it'll be easier to give a
> > definite
> >> > answer...
> >> >
> >> > --
> >> > Bob Powell [MVP]
> >> > Visual C#, System.Drawing
> >> >
> >> > Find great Windows Forms articles in Windows Forms Tips and Tricks
> >> > http://www.bobpowell.net/tips...
> >> >
> >> > Answer those GDI+ questions with the GDI+ FAQ
> >> > http://www.bobpowell.net/f...
> >> >
> >> > All new articles provide code in C# and VB.NET.
> >> > Subscribe to the RSS feeds provided and never miss a new article.
> >> >
> >> >
> >> >
> >> >
> >> >
> >> > "Steve Magoon" <steve_magoon@hotmail.com> wrote in message
> >> > news:uSMRVf67EHA.2804@TK2MSFTNGP15.phx.gbl...
> >> >> 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);
> >> >>
> >> >> }
> >> >>
> >> >> }
> >> >>
> >> >>
> >> >
> >> >
> >>
> >>
> >
> >
>
>
>


Steve Magoon

1/3/2005 2:01:00 PM

0

Thanks for the help Bob!

Steve


"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
news:ecrB8UX8EHA.1392@tk2msftngp13.phx.gbl...
> Hi Steve,
> I adjusted your control to use a matrix rather than the display rectangle.
> This has the advantage of shifting the whole drawing surface so that you
> just do the output based upon the fixed origin rather than worrying about
> where the display has been moved to. This principle is actually explained
> in
> some detail in my Windows Forms Tips and Tricks article on understanding
> auto-scroll.
>
> See the code below.
>
> --
> Bob Powell [MVP]
> Visual C#, System.Drawing
>