Paint order

  • Thread starter Thread starter JDR2000
  • Start date Start date
J

JDR2000

I am writing a program which creates a graph. Basically, it is a
Panel, and every x,y point on the graph is a Label, which the user can
click on. My problem is this:

If the user selects several points by clicking on some labels, I want
to be able to draw a curve through these points. I would think that
the painting of the lines should be done in the Panel. Thus, the
rendering should be as follows:

1. The background of the Panel.
2. All of the Labels which create the Graph, which are contained in
the Panel.
3. In the OnPaint method of Panel, draw a line through the selected
points (Labels).

This means that the curve (3) would be rendered after the Labels are
rendered. Is this possible?

Any help would be greatly appreciated.

Jon R.
 
Hello JDR2000,
1. The background of the Panel.
2. All of the Labels which create the Graph, which are contained in
the Panel.
3. In the OnPaint method of Panel, draw a line through the selected
points (Labels).

This means that the curve (3) would be rendered after the Labels are
rendered. Is this possible?

Any help would be greatly appreciated.

Why not !? Just do it.

By the way: You should do ALL your painting in "OnPaint" !!!
If you want to repaint, just call "panel.Invalidate()".

If you do all painting in WmPaint you can also set the styles in your panel
construtor:

class MyPanel : Panel
{
public MyPanel() {
this.SetStyle(ControlStyles.AllPaintingInWmPaint |
ControlStyles.DoubleBuffer |
ControlStyles.ResizeRedraw |
ControlStyles.UserPaint);
}
}

With this double buffering is used, and the "flicker-effect" is gone.

See:
http://msdn.microsoft.com/library/en-
us/cpref/html/frlrfsystemwindowsformscontrolstylesclasstopic.asp


--
Greetings
Jochen

Do you need a memory-leak finder ?
http://www.codeproject.com/tools/leakfinder.asp

Do you need daily reports from your server?
http://sourceforge.net/projects/srvreport/
 
Hi Jochen,

Thanks for your response. I used some of your suggestions, however, the
problem I have still exists.

Below is the code for the Panel. If you add it to a Form, you'll see
that the diagonal line that's created in OnPaint is covered by the
TestLabel. I want the line to appear on top of the TestLabel.

Any ideas?

Many thanks,

Jon Rachlin (code below)




using System;
using System.Windows.Forms;
using System.Drawing;

namespace PaintTest
{
/// <summary>
/// Summary description for PaintPanel.
/// </summary>
public class PaintPanel:Panel
{
Pen curvePen = new Pen (Color.Black,3);
Label testLabel = new Label();
public PaintPanel()
{
//
// TODO: Add constructor logic here
//

testLabel.Location = new Point (100,100);
testLabel.Size = new Size (500,500);
testLabel.BackColor = Color.Red;
testLabel.ForeColor = Color.Black;
testLabel.Text = "Hello";
this.Controls.Add(testLabel);
}



protected override void OnPaint(PaintEventArgs e)
{

base.OnPaint(e);

Graphics g = e.Graphics;

g.DrawLine (curvePen,0,0,this.Width-1,this.Height-1);
}
}
}
 
Jonathan said:
Hi Jochen,

Thanks for your response. I used some of your suggestions, however, the
problem I have still exists.

Below is the code for the Panel. If you add it to a Form, you'll see
that the diagonal line that's created in OnPaint is covered by the
TestLabel. I want the line to appear on top of the TestLabel.

Either draw the text by yourself (g.DrawText) or add a Label-element which
only displays the text!


--
Greetings
Jochen

Do you need a memory-leak finder ?
http://www.codeproject.com/tools/leakfinder.asp

Do you need daily reports from your server?
http://sourceforge.net/projects/srvreport/
 
Back
Top