|
-
June 24th, 2010, 05:34 AM
#1
Printing custom control
Hello,
I have a custom control, graphChart. I am using this control to draw graph, area , shape etc.
MainForm is using this control. I want to print some part of graph.
For example, my graph has grid, labels, shapes. I want to print only shapes.
If it is whole graph, I can use control.CreateGraphics() but I want to print some part.
Is there any way to achieve it?
With regard,
-
June 24th, 2010, 10:54 AM
#2
Re: Printing custom control
What do you mean by print? Do you mean you only want to draw specific element of the control? If so, show the OnPaint code.
-
June 24th, 2010, 12:03 PM
#3
Re: Printing custom control
One down and dirty way is to get the image of the control into a bitmap the you can manipulate the image however you want, including drawing over regions that you dont want.
-
June 24th, 2010, 09:39 PM
#4
Re: Printing custom control
@Pickels
You are right. Thats is what I am trying to do.
Here is my code (psudo code)
In My chartUserControl
public Graphics graphicWithoutData;
private void drawingPanel_Paint_1(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics
DrawGrid(g);
DrawShape(g);
graphicWithoutData = g;
//I even tried with bitmap
Size s = this.Size;
BitmapWithoutDistData = new Bitmap(s.Width, s.Height, g);
DrawData(g);
}
when i try to access graphicWithoutData (public member) in my main form, it gave me an exception : Invalid parameter.
When I try to print BitmapWithoutDistData (public member) in my main form, it was blank
Is there any wrong in my way of approach to this problem.
If you know any other way let me know.
@[email protected]
Above is my code. But even that bitmap (BitmapWithoutDistData) is blank. i.e when I print it on doc it was blank
-
June 30th, 2010, 01:14 PM
#5
Re: Printing custom control
try doing it this way
Code:
private void drawingPanel_Paint_1(object sender, PaintEventArgs e)
{
using (Bitmap bmp = new Bitmap(s.Width, s.Height))
{
using (Graphics g = Graphics.FromImage(bmp))
{
DrawGrid(g);
DrawShape(g);
}
//At this point bmp should be the image I think you are looking for
e.Graphics.DrawImage(bmp) ;
DrawData(e.Graphics);
}
}
-
July 22nd, 2010, 10:53 PM
#6
Re: Printing custom control
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|