473,397 Members | 2,099 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,397 software developers and data experts.

PrintWindow

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;
Nov 15 '05 #1
2 10201
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

Nov 15 '05 #2
Mohamoss, thanks for your response, but i have a RichTextBox, not a
PictureBox!!

Can somebody verify that RichTextBox doesn't do PrintWindow?

WHY??

"Mohamoss" <mo************@egdsc.microsoft.com> wrote in message
news:cp*************@cpmsftngxa07.phx.gbl...
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

Nov 15 '05 #3

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

Similar topics

10
by: OysterCracker | last post by:
Hi - I've used the <a href="javascript:printWindow()"><Print></a> function for printing a webpage, but I ran into an interesting variation recently, and would appreciate some help duplicating it....
2
by: Asad | last post by:
I have a main window that creates a new window called printWin (which contains the printable format of the page). From the main window I embed a javascript in the printWin window that calls the...
1
by: dibyendu_k | last post by:
Hi, There is a problem i cant solve regarding Internet Explorer 5.5. It is regarding the Print Dialog Box. From a webpage if I open a popup window (window.open()) containing buttons Print and...
2
by: WoodBeeProgrammer | last post by:
How come everybody on this newsgroup answers easy questions but not hard questions? Does PrintWindow work with RichTextBox? If not, WHY NOT? And if not, what's the workaround? TIA
9
by: Rajat Tandon | last post by:
Hello there, I am relatively new to the newsgroups and C#. I have never been disappointed with the groups and always got the prompt replies to my queries.This is yet another strange issue, I am...
3
by: Joe Black | last post by:
Hi everyone, I have a pesky little problem that is driving me nuts. I'm trying to capture an image of a web page programmatically in a background thread or process. What I'd like to do is create...
5
by: Dave A | last post by:
I am writing an ASP.NET tool that will allow the client to create their own online froms. ie the client can add tect boxes, text, drop downs,etc with absolutely no technical skill what so ever....
0
by: Berry W | last post by:
Some articles say that PrintWindow can be used to take a capture of the hidden window and save the content. How should PrintWindow used? Any sample code around how to use it? Thanks to you all!
1
by: Mark Rae [MVP] | last post by:
"Parrot" <Parrot@discussions.microsoft.comwrote in message news:D44A43E9-B6BA-4AC9-B946-A6787897CED5@microsoft.com... Dave, RegisterStartupScript is used to inject JavaScript into web pages...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.