Taking a screen shot of a control
-
Hi. I need to take a screen shot of a control - the control is plotterForm.expressionPlotter. I am using the following code:
private Bitmap GetBitmap() { Bitmap bmp = new Bitmap(plotterForm.expressionPlotter.Width, plotterForm.expressionPlotter.Height); Graphics g = Graphics.FromImage(bmp); Screen screen = Screen.FromControl(plotterForm.expressionPlotter); g.CopyFromScreen(new Point(screen.Bounds.Location.X, screen.Bounds.Location.Y), Point.Empty, plotterForm.expressionPlotter.Size); return bmp; }
The problem is that the location of which the screen shot is always the upper left corner of the desktop, not the upper left corner of the control. In other words the screen.Bounds.Location is a point which is always (0;0). When i added MessageBox.Show(screen.ToString()); i received the following message:Screen[Bounds={X=0,Y=0,Width=1024,Height=768} WorkingArea={X=0,Y=0,Width=1024,Height=739} Primary=True DeviceName=\\.\DISPLAY1
As if the screen hasn't captured the control. How can i fix this???Still learning...
-
Hi. I need to take a screen shot of a control - the control is plotterForm.expressionPlotter. I am using the following code:
private Bitmap GetBitmap() { Bitmap bmp = new Bitmap(plotterForm.expressionPlotter.Width, plotterForm.expressionPlotter.Height); Graphics g = Graphics.FromImage(bmp); Screen screen = Screen.FromControl(plotterForm.expressionPlotter); g.CopyFromScreen(new Point(screen.Bounds.Location.X, screen.Bounds.Location.Y), Point.Empty, plotterForm.expressionPlotter.Size); return bmp; }
The problem is that the location of which the screen shot is always the upper left corner of the desktop, not the upper left corner of the control. In other words the screen.Bounds.Location is a point which is always (0;0). When i added MessageBox.Show(screen.ToString()); i received the following message:Screen[Bounds={X=0,Y=0,Width=1024,Height=768} WorkingArea={X=0,Y=0,Width=1024,Height=739} Primary=True DeviceName=\\.\DISPLAY1
As if the screen hasn't captured the control. How can i fix this???Still learning...
-
I realized that the Screen.FromControl is something entirely different from the thing i expected! But here comes another question - how can i find the location of a control in relation to the desktop?
Still learning...
Use...
PointToScreen(control.Location);
Matthew Butler
-
Hi. I need to take a screen shot of a control - the control is plotterForm.expressionPlotter. I am using the following code:
private Bitmap GetBitmap() { Bitmap bmp = new Bitmap(plotterForm.expressionPlotter.Width, plotterForm.expressionPlotter.Height); Graphics g = Graphics.FromImage(bmp); Screen screen = Screen.FromControl(plotterForm.expressionPlotter); g.CopyFromScreen(new Point(screen.Bounds.Location.X, screen.Bounds.Location.Y), Point.Empty, plotterForm.expressionPlotter.Size); return bmp; }
The problem is that the location of which the screen shot is always the upper left corner of the desktop, not the upper left corner of the control. In other words the screen.Bounds.Location is a point which is always (0;0). When i added MessageBox.Show(screen.ToString()); i received the following message:Screen[Bounds={X=0,Y=0,Width=1024,Height=768} WorkingArea={X=0,Y=0,Width=1024,Height=739} Primary=True DeviceName=\\.\DISPLAY1
As if the screen hasn't captured the control. How can i fix this???Still learning...
Can you not just use
DrawToBitmap
as in:int height = plotterForm.expressionPlotter.Height;
int width = plotterForm.expressionPlotter.Width;
Bitmap bmp = new Bitmap(width, height);
plotterForm.expressionPlotter.DrawToBitmap(bmp, new Rectangle(0,0,width,height));Because if you could i imagine it will be much easier.
My current favourite word is: Nipple!
-SK Genius
-
Hi. I need to take a screen shot of a control - the control is plotterForm.expressionPlotter. I am using the following code:
private Bitmap GetBitmap() { Bitmap bmp = new Bitmap(plotterForm.expressionPlotter.Width, plotterForm.expressionPlotter.Height); Graphics g = Graphics.FromImage(bmp); Screen screen = Screen.FromControl(plotterForm.expressionPlotter); g.CopyFromScreen(new Point(screen.Bounds.Location.X, screen.Bounds.Location.Y), Point.Empty, plotterForm.expressionPlotter.Size); return bmp; }
The problem is that the location of which the screen shot is always the upper left corner of the desktop, not the upper left corner of the control. In other words the screen.Bounds.Location is a point which is always (0;0). When i added MessageBox.Show(screen.ToString()); i received the following message:Screen[Bounds={X=0,Y=0,Width=1024,Height=768} WorkingArea={X=0,Y=0,Width=1024,Height=739} Primary=True DeviceName=\\.\DISPLAY1
As if the screen hasn't captured the control. How can i fix this???Still learning...
Take a screen shot of the whole screen and then use an image editor? Or, what I did was write a simple applet that I can position over the section of the screen I want to capture and have do the capture.
-
Can you not just use
DrawToBitmap
as in:int height = plotterForm.expressionPlotter.Height;
int width = plotterForm.expressionPlotter.Width;
Bitmap bmp = new Bitmap(width, height);
plotterForm.expressionPlotter.DrawToBitmap(bmp, new Rectangle(0,0,width,height));Because if you could i imagine it will be much easier.
My current favourite word is: Nipple!
-SK Genius
I changed the code of the project a little bit and the control which i want to capture is a panel. The panel has a written text using the
DrawString
method of theGraphics
class.The screen shot is stored in the clipboard. When i take a screen shot usingDrawToBitmap
, when i paste the image in paint it appears, but the text isn't there. The taken screen shot[^] The image as it should be[^] Why doesn't theDrawToBitmap
method capture the text???Still learning...
-
Hi. I need to take a screen shot of a control - the control is plotterForm.expressionPlotter. I am using the following code:
private Bitmap GetBitmap() { Bitmap bmp = new Bitmap(plotterForm.expressionPlotter.Width, plotterForm.expressionPlotter.Height); Graphics g = Graphics.FromImage(bmp); Screen screen = Screen.FromControl(plotterForm.expressionPlotter); g.CopyFromScreen(new Point(screen.Bounds.Location.X, screen.Bounds.Location.Y), Point.Empty, plotterForm.expressionPlotter.Size); return bmp; }
The problem is that the location of which the screen shot is always the upper left corner of the desktop, not the upper left corner of the control. In other words the screen.Bounds.Location is a point which is always (0;0). When i added MessageBox.Show(screen.ToString()); i received the following message:Screen[Bounds={X=0,Y=0,Width=1024,Height=768} WorkingArea={X=0,Y=0,Width=1024,Height=739} Primary=True DeviceName=\\.\DISPLAY1
As if the screen hasn't captured the control. How can i fix this???Still learning...
Im 99% sure that the DrawToBitmap method will invoke the OnPaint method on the control and pass a graphics object containing the bitmap. so if you draw the text outside of the OnPaint method, that code will not be triggered when calling DrawToBitmap. How are you drawing the text? Control.CreateGraphics?
Blog: http://www.rogeralsing.com Projects: http://www.puzzleframework.com
-
Im 99% sure that the DrawToBitmap method will invoke the OnPaint method on the control and pass a graphics object containing the bitmap. so if you draw the text outside of the OnPaint method, that code will not be triggered when calling DrawToBitmap. How are you drawing the text? Control.CreateGraphics?
Blog: http://www.rogeralsing.com Projects: http://www.puzzleframework.com
This is how things are: I have created a control -
ExpressionPlotter
. It is used to plot math graphs - they are drawn on the control. The control has a panel which contains the graphs' information. In theOnPaint
method of theExpressionPlotter
is the method which draws the text -DisplayExpressionsText
. InDisplayExpressionsText
the panel is sized according to the text and then in the drawing of the text the methodpanel.CreateGraphics
is used to obtain theGraphics
class. When it comes to the screen shot theDrawToBitmap
is called for theExpressionPlotter
control. I tried to draw the text in thePaint
event of the panel, but when i started the program, the panel didn't show.Still learning...
-
I changed the code of the project a little bit and the control which i want to capture is a panel. The panel has a written text using the
DrawString
method of theGraphics
class.The screen shot is stored in the clipboard. When i take a screen shot usingDrawToBitmap
, when i paste the image in paint it appears, but the text isn't there. The taken screen shot[^] The image as it should be[^] Why doesn't theDrawToBitmap
method capture the text???Still learning...
i don't know, i had trouble with a textbox not drawing the text when i used DrawToBitmap. Then all of a sudden it just started working. and i'm not sure why/
My current favourite word is: Nipple!
-SK Genius
-
This is how things are: I have created a control -
ExpressionPlotter
. It is used to plot math graphs - they are drawn on the control. The control has a panel which contains the graphs' information. In theOnPaint
method of theExpressionPlotter
is the method which draws the text -DisplayExpressionsText
. InDisplayExpressionsText
the panel is sized according to the text and then in the drawing of the text the methodpanel.CreateGraphics
is used to obtain theGraphics
class. When it comes to the screen shot theDrawToBitmap
is called for theExpressionPlotter
control. I tried to draw the text in thePaint
event of the panel, but when i started the program, the panel didn't show.Still learning...
-
Hi. I need to take a screen shot of a control - the control is plotterForm.expressionPlotter. I am using the following code:
private Bitmap GetBitmap() { Bitmap bmp = new Bitmap(plotterForm.expressionPlotter.Width, plotterForm.expressionPlotter.Height); Graphics g = Graphics.FromImage(bmp); Screen screen = Screen.FromControl(plotterForm.expressionPlotter); g.CopyFromScreen(new Point(screen.Bounds.Location.X, screen.Bounds.Location.Y), Point.Empty, plotterForm.expressionPlotter.Size); return bmp; }
The problem is that the location of which the screen shot is always the upper left corner of the desktop, not the upper left corner of the control. In other words the screen.Bounds.Location is a point which is always (0;0). When i added MessageBox.Show(screen.ToString()); i received the following message:Screen[Bounds={X=0,Y=0,Width=1024,Height=768} WorkingArea={X=0,Y=0,Width=1024,Height=739} Primary=True DeviceName=\\.\DISPLAY1
As if the screen hasn't captured the control. How can i fix this???Still learning...
Take a look at my article clickety in which I cover basic screen capture as well as capturing a specific area of the screen. The source code is available for download from the article as well. Regards Guy
You always pass failure on the way to success.
-
This is how things are: I have created a control -
ExpressionPlotter
. It is used to plot math graphs - they are drawn on the control. The control has a panel which contains the graphs' information. In theOnPaint
method of theExpressionPlotter
is the method which draws the text -DisplayExpressionsText
. InDisplayExpressionsText
the panel is sized according to the text and then in the drawing of the text the methodpanel.CreateGraphics
is used to obtain theGraphics
class. When it comes to the screen shot theDrawToBitmap
is called for theExpressionPlotter
control. I tried to draw the text in thePaint
event of the panel, but when i started the program, the panel didn't show.Still learning...
nike_arh wrote:
in the drawing of the text the method panel.CreateGraphics is used to obtain the Graphics class.
That's your problem. That means that you are always drawing the text on the screen. Use the Graphics object that is supplied in the event arguments to the Paint event.
Despite everything, the person most likely to be fooling you next is yourself.