Re: Printing in .NET redundant?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: David Eu (anonymous_at_discussions.microsoft.com)
Date: 05/12/04


Date: Tue, 11 May 2004 22:06:04 -0700


> The control *paints* onto a graphics buffer. The *painting* includes overdraw
> and other features including alpha
> blending, and many other feature rich items.

I can appreciate the ability to have those features such as alpha blending or
adding custom graphics. It is great to have those things but what about the
basic task of printing a Windows Form?

> You don't need to reverse engineer OnPaint per say. Most of the control drawing
> routines can be found
> in the ControlPaint class so you can handle painting them there. The underlying
> issue is that you generally

The ControlPaint class only allows you to draw geometric primitives. If you want to
print a TabControl that contains several TabPages, each TabPage containing nested
controls such as TextBoxes, RichTextBoxes, DataGrids, etc.. how do you do that
with ControlPaint? You have to code everything yourself.
And how do you print a MonthCalendar?
I have managed to get the printing working for TextBoxes, RadioButtons, Buttons, RichTextBoxes,
Labels, CheckBoxes, etc. but what an arduous task! You have to code for all of the different
appearance attributes - example: text alignment, background images, image alignment, etc...
So yes, you have to reverse engineer OnPaint. You have to attempt to draw
the form exactly as OnPaint draws it.

> If you want to BitBlt it from the screen you are more than welcome. You can
> BitBlt from the screen area to your

That is not a practical solution. Just think of the case where the user has moved
the form so that part of it does not lie within the visible screen space. The rendered
form will be incomplete.

On the subject of BitBlt - you can load an image into a graphics context but you cannot
save a graphics context to an image. Technically this should be a trivial matter.
I suspect that the reason why you cannot save is due rather to a business motive.
Imagine if Microsoft would provide this simple function - it would then be trivial.
All you would have to do is do a form refresh and save the graphics context to an image
buffer and then print the image buffer. You could even preprocess the image buffer,
e.g. cropping, rotating, 2D effects, etc...

> Take the single case of a Listbox with 30 items with only 3 visible. How do you
> print that?
My point ***exactly***. When OnPaint() draws the ListBox does it not draw it correctly with
only the 3 visible items shown? So instead of be given the API hook to tell the ListBox
to draw itself correctly onto the graphics context, we have to write code to
mimic the behaviour of OnPaint.



Relevant Pages

  • Re: typeof for feature testing host methods
    ... I have said where I draw the line: I won't test for `typeof' anymore because ... and host features (although you may start testing for all host ... even supported by legacy browsers released almost eight years ago. ... you have made a superior choice and have justification to criticize ...
    (comp.lang.javascript)
  • Re: Creative uses for Battlemats
    ... surrounding terrain and/or other such mobile features. ... Also, even if you *can* draw in features on the main mat, sometimes ...
    (rec.games.frp.dnd)
  • Re: Gdiplus Graphics object wont draw on the hbitmap
    ... // get graphics context for image ... > draw over a loaded bitmap. ... > HBITMAP bmp, oldbmp; ...
    (microsoft.public.win32.programmer.gdi)
  • Re: How do you make DNA?
    ... or just draw it, seriously, in 3D. ... water from highest to lowest. ... ortho space system, picture each features' edge ...
    (rec.woodworking)
  • Re: select features
    ... >> than draw a line between these two features. ... > - maybeeven a snippet of ML code... ... The descriptor is a vector of 128 values normalized to unit length. ...
    (comp.soft-sys.matlab)