I am now building a C# windows application.
I have a textArea which allows user to enter any kind of characters like English, Chinese, Japanese and etc.
Then i want to convert the content of the textarea to an bitmap file for printing.
Any ideas how this can be done?
please teach me. Iwill reward you.
I |
| Jessica Alba Monday, May 14, 2007 10:04 AM |
Control has a DrawToBitmap method.. If you search for 'Print Control' on sites like the CodeProject.com you'll find a couple of good implementations... In essence: private void printDocument1_PrintPage (object sender, System. Drawing. Printing. PrintPageEventArgs e ) { Graphics graphics = e. Graphics; Bitmap bitmap = new Bitmap (this. textBox. Width, this. textBox. Height); this. textBox. DrawToBitmap(bitmap, this. textBox. Bounds); graphics. DrawImage(bitmap); } |
| timvw Monday, May 14, 2007 7:42 PM |
I am not 100% sure that this will work... it`s only a thought.
The ideea is to make a "Print Screen" of your WinForm. After you've done that, knowing the dimensions of the textArea,you can cut the rectangle where the textArea isfrom the form the "print screen" bitmap.
If you can't print yourWinForm only but you can print the whole desktop(including your WinForm), you can get the location of the textArea (inside the "print screen" bitmap) by adding the location of the form.
Here's an example of a desktop being captured.
Hope this helps. |
| Eusebiu Monday, May 14, 2007 2:11 PM |
this is a stunning discovery. i never thought of that.
but is this the standard way of doing thing?
i feel it will have a lot of unnecessary overhead processing with this method.
anyone else?
|
| Jessica Alba Monday, May 14, 2007 3:03 PM |
I am sure that my solution is not a standard one...  |
| Eusebiu Monday, May 14, 2007 3:39 PM |
A few questions:
Why do you need to convert it to a bitmap for printing? Are you printing inside your program or outside?
Also, instead of capturing the whole screen, work with GDI+ and graphics to capture/draw the contents of the textArea to a Bitmap. It would make more sense, since you'd only need to actually capture the textArea. You can easily make a new bitmap (image) object, get the graphics object of it, and just use GDI+ to paint what is in the textArea to the bitmap.
|
| IsshouFuuraibou Monday, May 14, 2007 5:58 PM |
Control has a DrawToBitmap method.. If you search for 'Print Control' on sites like the CodeProject.com you'll find a couple of good implementations... In essence: private void printDocument1_PrintPage (object sender, System. Drawing. Printing. PrintPageEventArgs e ) { Graphics graphics = e. Graphics; Bitmap bitmap = new Bitmap (this. textBox. Width, this. textBox. Height); this. textBox. DrawToBitmap(bitmap, this. textBox. Bounds); graphics. DrawImage(bitmap); } |
| timvw Monday, May 14, 2007 7:42 PM |
Yep.... better than mine ..  |
| Eusebiu Monday, May 14, 2007 8:02 PM |
hey, good one.
i wanna know if this is applicable to compact framework. |
| Jessica Alba Tuesday, May 15, 2007 4:47 AM |
No, it is not... If you are looking to Controls's members, at methods, you can see that DrawToBitmap hasn`t a PDA image on the left. That meens it isn`t supported in .NET CF  |
| Eusebiu Tuesday, May 15, 2007 6:25 AM |
| Eusebiu wrote: |
|
No, it is not... If you are looking to Controls's members, at methods, you can see that DrawToBitmap hasn`t a PDA image on the left. That meens it isn`t supported in .NET CF
| |
i doubt what you said. i have seen a software runnig on Pocket PC to convert all the controls into bitmap. the company is called fieldsoftware.
|
| Jessica Alba Tuesday, May 15, 2007 9:41 AM |
Platforms
Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The Microsoft .NET Framework 3.0 is supported on Windows Vista
|
| Jessica Alba Tuesday, May 15, 2007 9:46 AM |
Hello...
There are times when I doubt myself of what I say... and I don`t blame you for that ... but...if you try to make a simple Pocket PC DeviceApplication or SmartPhone DeviceApplication or a Windows CE 5.0 DeviceApplication in VS 2005and try to write the line this.textBox1.DrawToBitmap(...) you will see that DrawToBitmap isn`t there...
So... I still say that DrawToBitmap isn`t supported in .NET CF. |
| Eusebiu Tuesday, May 15, 2007 10:29 AM |
| cl408e wrote: |
|
this is a stunning discovery. i never thought of that.
but is this the standard way of doing thing?
i feel it will have a lot of unnecessary overhead processing with this method.
anyone else?
| |
If you will look "inside" the Control.DrawToBitmap(...) method, you will find calls to User32.dll, GDI32.dll and GDIPlus.dll. |
| Eusebiu Tuesday, May 15, 2007 10:57 AM |