473,395 Members | 1,996 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Paint order

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.
Nov 16 '05 #1
3 3364
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/
Nov 16 '05 #2
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);
}
}
}
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #3
Jonathan Rachlin wrote:
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/
Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Evan Dekker | last post by:
hi all im not why this code doesn't work: ///////// import java.applet.*; import java.awt.*; public class TestApplet extends Applet { public void init() {
4
by: Franck | last post by:
Hello, Sorry if that question has already been raised... I'm looking for the exact equivalent of Java paint(Graphics g) method in c# in order to paint a specific component and all its children...
5
by: Tamir Khason | last post by:
How I can paint something onClick event? I need PaintEventArgs event in order to paint and raise Graphics, but onClick I have only EventArgs Event... Thanx
0
by: vooose | last post by:
Consider a UserControl to which you do userControl.Paint += new PaintEventHandler(paint_method) If you don't like that way, and prefer to override onPaint( ) then the problem stated below...
3
by: pacemkr | last post by:
Is it possible to force a control to paint to a Graphics object (or Device Context, or a bitmap, anywhere aside from the form) that I provide. I am writing a windows form class that supports...
5
by: ruca | last post by:
Hi, Can anyone give me examples of how can I hightlight cells of my datagrid? I know that I must use ItemBound event and probably JavaScript. The thing is that I have a anual calendar,...
3
by: Mike Cooper | last post by:
I have been staring at the above error for over a week now! I have a an inherited data class looking like thus: Public Class DataGridBoolColumnInherit Inherits...
6
by: jcrouse | last post by:
I am rotating some text is some label controls. In the one place I use it it works fine. In the other place I use it I can't figure out the syntax. I don't really understand the event. Where it...
7
by: Rotsey | last post by:
Hi, I have a interface that I use for a form so I can pass the form to another object. How do I add the Paint event to the interface and subsequently handle the paint event in my other...
5
by: =?Utf-8?B?SmVzcGVyLCBEZW5tYXJr?= | last post by:
Hi, On a usercontrol I've put a set of radiobuttons within a groupbox. These radiobuttons have visual style enables, i.e. they turn orange when hovering over them and green when pushed. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.