C# and Object graphics

Oriolesboy

Member
Joined
Jul 18, 2003
Messages
10
Sorry if this has been posted before, I looked around as well as searched and did not find anything.

Here goes:

I have this board class (like a checker/chess/whatever_game board) and I want to send it to the printer to print it out.

There are two ways I am trying to do it each with their own problem:

1) Display the board on the screen and bitblt it to image then send it to the printer.
1p) The problem: Unfortunately the board is too large for the form and so the form adds a scroll bar, this results in part of the board missing and whatever is on the desktop being taken as an image (since the size of the board is greater then the form). I cannot just make the board fit on the screen as it needs to remain a certain size and i cannot change the resolution as this program may end up on many computers with different resolution sizes.

code: Graphics g is passed into the method
/*****************************************/
Image MyImage = new Bitmap(total_width, total_height, g);
Graphics g2 = Graphics.FromImage(MyImage);

IntPtr dc1 = g.GetHdc();
IntPtr dc2 = g2.GetHdc();
BitBlt(dc2, 0, 0,
boards[0].Width,
boards[0].Height,
dc1, 0, 0, 13369376);

g.ReleaseHdc(dc1);
g2.ReleaseHdc(dc2);

/******************************************/


2) Create the objects without displaying (ie- never drawing them to the current graphics- not displaying it on the screen in any way), and then bitblt that and draw the images to the printer
2p) The problem here is my board ends up transparents in most of the places and still ends with the desktop or the printer dialog as part of the image.
The code is pretty much the same, except that in the above code (not that it shows it) the objects are showing on the screen, and for this part the objects have not been drawn to the screen only created.
Also i try grabbing the objects graphics with:

Graphics temp_g = boards.CreateGraphics();



Any ideas how to do this?
- ps, my board is nothing but a collection of extended labels that I modified to display the appropriate graphics

EDIT: My board extends a GroupBox if that helps /EDIT

Thanks for any help!

I have found printing custom forms/objects to a printer to be a very pain, and have not found an easy way to do it.
 
Last edited by a moderator:
actually theres a possibility to tell a Control to redraw itself on (for example) an image... I wrote a test-app which does this.. doesnt look that good but it works! ;-)

Hope this helps!

Andreas
 

Attachments

Last edited by a moderator:
Thanks Ill check it out.

I was actually just looking into WM_PRINT through windowproc, though im not sure how to use it, i have a feeling what you just posted might be it.
 
I gave it a try and didnt work.

I then tried editing yours and throwing a button into the group.

It seems that copy of the image does not copy the contents inside the group box.

Ill keep playing with sendmessage and similar functions and see what i can get to work.
 
Thanks ill check it out! Ive even posted on gotdotnet and havent found anything helpful. Ill let you know how this goes, thanks again!
 
All right, almost done!

I have a one question though, so here goes:

1) Now for some reason when i do repaint, it repaints the labels but ignores the border with the label. I printed out to the prompt the Label.borderstyle.toString() and its correct, but it doesnt seem like (this is in my label class)

this.onpaint(e); //this is C# i converted all your stuff

is looking at borders when painting. Any ideas? Ill keep playing and seeing what i can get, but if anyone can help, thank you!

Just in case this may make a difference, this is how my label class really is (not the actual names, but a fair representation):

MyBoardLabel extends Label - label class but
defines RePaint as in downloadable code

MyBoardLabelMark extends MyBoardLabel
MyBoardLabelMark2 extends MyBoardLabel

EDIT: I tried your code, and switched the buttons to labels (through the inheritance), and gave button5 (label5) a border. Your program also doesnt redraw the border, so it has to be the onpaint method, now to figure out why that happens and how to fix it.
 
Last edited by a moderator:
Looks like you just have to use the pen class to draw a border (by means of a rectangle) beats me why. Im asking on the gotdotnet to try and figure out why onpaint doesnt do the border for you.

Oh and Hamburger1984 I owe you a beer if youre ever in western new york in the US
 
thanks for the beer... ;) thats exactly what I need - its danm hot here...


the problem with Labels, ListBoxes, ComboBoxes, TextBoxes etc is that they are mostly drawn at a lower level - so the OnPaint-Method doesnt really draw them (at least not correct). but you can fake the borderdrawing by using the System.Windows.Forms.ControlPaint-Class and do a DrawBorder or DrawBorder3D... should work and almost look the same than the Windows-Drawn Controls..

Hope this helps!

Andreas
 
Back
Top