Connecting Tech Pros Worldwide Help | Site Map

PrintWindow

WoodBeeProgrammer
Guest
 
Posts: n/a
#1: Nov 15 '05
aargh! what's wrong with the following snippet? i'm trying to use
PrintWindow with a RichTextBox.


[DllImport ("User32.dll")]
public extern static bool PrintWindow (System.IntPtr hWnd, System.IntPtr dc,
uint reservedFlag);

System.IntPtr hwnd = rtf.Handle;
Bitmap bm = new Bitmap (rtf.Size.Width, rtf.Size.Height);
if (bm != null)
{
using (Graphics g = Graphics.FromImage (bm))
{
if (g == null) return null;
System.IntPtr bmDC = g.GetHdc ();
bool ok = PrintWindow (hwnd, bmDC, 0); // RETURNS FALSE-- WHY?????
g.ReleaseHdc (bmDC);
}
}
return bm;


Mohamoss
Guest
 
Posts: n/a
#2: Nov 15 '05

re: PrintWindow


Hi
it will not work with a Rich text box objects " i expect this is what the
rtf is" , try a Picture Box instead
Here are the changes that I did to the thing to work
private System.Windows.Forms.PictureBox pp;
pp = new PictureBox();
System.IntPtr hwnd = pp.Handle;
Bitmap bm = new Bitmap (pp.Size.Width, pp.Size.Height);
if (bm != null)
{
using (Graphics g = Graphics.FromImage (bm))
{
System.IntPtr bmDC = g.GetHdc ();
bool ok =true;
ok = PrintWindow (hwnd, bmDC,0); // RETURNS FALSE-- WHY?????
MessageBox.Show(ok.ToString());
g.ReleaseHdc (bmDC);
}
}
Hope that would help

WoodBeeProgrammer
Guest
 
Posts: n/a
#3: Nov 15 '05

re: PrintWindow


Mohamoss, thanks for your response, but i have a RichTextBox, not a
PictureBox!!

Can somebody verify that RichTextBox doesn't do PrintWindow?

WHY??



"Mohamoss" <mohamed.mossad@egdsc.microsoft.com> wrote in message
news:cpXvPa79DHA.704@cpmsftngxa07.phx.gbl...[color=blue]
> Hi
> it will not work with a Rich text box objects " i expect this is what[/color]
the[color=blue]
> rtf is" , try a Picture Box instead
> Here are the changes that I did to the thing to work
> private System.Windows.Forms.PictureBox pp;
> pp = new PictureBox();
> System.IntPtr hwnd = pp.Handle;
> Bitmap bm = new Bitmap (pp.Size.Width, pp.Size.Height);
> if (bm != null)
> {
> using (Graphics g = Graphics.FromImage (bm))
> {
> System.IntPtr bmDC = g.GetHdc ();
> bool ok =true;
> ok = PrintWindow (hwnd, bmDC,0); // RETURNS FALSE-- WHY?????
> MessageBox.Show(ok.ToString());
> g.ReleaseHdc (bmDC);
> }
> }
> Hope that would help
>[/color]


Closed Thread