
Signature
There are 10 kinds of people in this world. Those who understand binary and
those who don't.
yeah, it really seems to work!
try that:
class CapturePanel : Control
{
public void Snapshot(Control c, Bitmap b)
{
using (Graphics g = Graphics.FromImage(b))
{
Rectangle rect = new Rectangle(new Point(), c.Size);
PaintEventArgs e = new PaintEventArgs(g, rect);
this.InvokePaint(c, e);
}
}
}

Signature
There are 10 kinds of people in this world. Those who understand binary and those who don't.
> never tried it, but I recently discovered this method:
> class Control
[quoted text clipped - 14 lines]
>>
>> Thanks.
Terminator is coming!...
hmm.. sorry...
here you go (it just happened I upgrade my code to use that as well ;-):
public class Snapshot
{
static readonly SnapshotControl snapshotMaker = new SnapshotControl();
class SnapshotControl : Control
{
public void Snapshot(Control c, Image b, bool background, Rectangle r)
{
using (Graphics g = Graphics.FromImage(b))
{
Rectangle rect = new Rectangle(new Point(), c.Size);
PaintEventArgs e = new PaintEventArgs(g, rect);
if (background)
this.InvokePaintBackground(c, e);
this.InvokePaint(c, e);
}
}
}
public static Image GetSnapshot(Control c)
{
return GetSnapshot(c, true);
}
public static Image GetSnapshot(Control c, bool withBackground)
{
Bitmap image = new Bitmap(c.Width, c.Height);
GetSnapshot(image, c, withBackground, new Rectangle(0, 0, c.Width, c.Height));
return image;
}
public static void GetSnapshot(Image dst, Control c, bool withBackground, Rectangle rect)
{
snapshotMaker.Snapshot(c, dst, withBackground, rect);
}
}
Lloyd Dupont - 30 Jul 2005 15:26 GMT
Oops..
works well with CheckBox, doesn';t work with TextBox.... :-/
well I have to keep my old win32 code :-/

Signature
There are 10 kinds of people in this world. Those who understand binary and those who don't.
Terminator is coming!...
hmm.. sorry...
here you go (it just happened I upgrade my code to use that as well ;-):
public class Snapshot
{
static readonly SnapshotControl snapshotMaker = new SnapshotControl();
class SnapshotControl : Control
{
public void Snapshot(Control c, Image b, bool background, Rectangle r)
{
using (Graphics g = Graphics.FromImage(b))
{
Rectangle rect = new Rectangle(new Point(), c.Size);
PaintEventArgs e = new PaintEventArgs(g, rect);
if (background)
this.InvokePaintBackground(c, e);
this.InvokePaint(c, e);
}
}
}
public static Image GetSnapshot(Control c)
{
return GetSnapshot(c, true);
}
public static Image GetSnapshot(Control c, bool withBackground)
{
Bitmap image = new Bitmap(c.Width, c.Height);
GetSnapshot(image, c, withBackground, new Rectangle(0, 0, c.Width, c.Height));
return image;
}
public static void GetSnapshot(Image dst, Control c, bool withBackground, Rectangle rect)
{
snapshotMaker.Snapshot(c, dst, withBackground, rect);
}
}
BYY - 01 Aug 2005 18:15 GMT
OK I figured out that the problem is that the InvokePaint only invokes paint
on the control, but not any of its children. The pain message doesn't
propagate down through the drawing layers.
> Oops..
> works well with CheckBox, doesn';t work with TextBox.... :-/
[quoted text clipped - 37 lines]
> }
> }
BYY - 01 Aug 2005 18:32 GMT
Getting all child controls to paint is just a matter of recursively calling
InvokePaint on the Controls collection.
The unsolved problem is figuring out how to get the right
System.Windows.Forms.Control.Wm<Message> to controls like TextBox,
TrackSlider, ComboBox etc. (I think)
Basically controls that are drawing themselves correctly have some paint
methods within there defintion. The controls that do not paint correctly
listen for Windows Messages and have the WndProc(ref Message m) method
overriden within their definition.
FYI - calling InvokePaint on a TextBox or ComboBox only draws a white
(background of the textbox) rectangle. The text, borders and button
(combobox) are not drawn. So, the question is how to get all of these other
parts of these controls to draw?
> OK I figured out that the problem is that the InvokePaint only invokes paint
> on the control, but not any of its children. The pain message doesn't
[quoted text clipped - 41 lines]
> > }
> > }