Link to home
Start Free TrialLog in
Avatar of isnoend2001
isnoend2001Flag for United States of America

asked on

Hide arranging form before print

I have code to change forms controls before printing and then back after print
    eg; form color from brown to white,etc
the changes is briefly visuable. before printing
.How can i stop this?


Sub BeforePrint()
    lstPrinters.Visible = False
    cmdHelp.Visible = False
    cmdDeleteCboItem.Visible = False
    miFrame1Top = Frame1.Top
    picBelowTop.Visible = False'hide the pic containg buttons
    mLFormColor = Me.BackColor
    Me.Frame1.BackColor = vbWhite
    Frame1.Top = 500'leave space at the top as a margin
    FraProjects.BackColor = vbWhite
    Me.BackColor = vbWhite
'    Command2.Visible = False
'    Command3.Visible = False
End Sub
Ihave tried this:
created another for just for printing and copied values
Tried this:
frmPrintGetBids.Left = Screen.Width + 800 'hide the form off the screen
This produced a completely black printout

setting the print forms z.order to 1,but it did not hide it.

Have not tried api setting the move to the back,
getting tired of trying things that don't work.
How can this be fixed ?
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

Add this API
Private Declare Function LockWindowUpdate Lib "user32" (ByVal hwnd As Long) As Long

And then  
LockWindowUpdate frmGetBids.hwnd
' Change colors and then print
LockWindowUpdate 0
Avatar of isnoend2001

ASKER

Thanks MartinLiss i will try that after i change code to use another form for printing
You don't need to use another form. Did you see the project I posted in the make a forms width fit printout thread?
Yes i see it and it works.
The actual color of the form is brown and has many controls
The one i sent you is how it will look when printed.
The LockWindowUpdate did not work it shows the form as before changes
Before and after printUser generated imageUser generated image
CaptureClient is added twice
' CreateBitmapPicture   - Creates a picture object from a bitmap and palette.
' CaptureWindow         - Captures any window given a window handle.
' CaptureActiveWindow   - Captures the active window on the desktop.
' CaptureClient           - Captures the entire form.
' CaptureClient         - Captures the client area of a form.
' CaptureScreen         - Captures the entire screen.
' PrintPictureToFitPage - prints any picture as big as possible on the page.
Yes I see that it doesn't work. The CaptureForm code takes a "snapshot" of the way the screen looks and since the LockWindowUpdate prevents the changes from being seen, the the snapshot is taken of the way it looked before. Let me think about this a bit and if I come up with anything I'll let you know.
Don't worry about CaptureClient since it's not used in your case.
While there might be a way to take a snapshot of a changed form without it being visible, if you use my code then literally "what you see is what you get" and you may have to live with the changes being briefly visible.
Thanks MartinLiss. I had another thought
Have another borderless form cover the client area briefly (on top)
Again with my code, what you see is what you get so if you cover it you'll get a picture of the cover.
I found this:
CaptureForm - Captures the entire form.
 CaptureClient - Captures the client area of a form.
CaptureForm is what I'm using. CaptureClient wouldn't act any differently as far as WYSIWYG.
I can't tell by looking at it so you'll need to try it.
Are you using Access or pure VB?

If Access then you can just set the Display When property of each control to Screen Only rather than writing additional lines of code.

If using pure Visual Basic, how do you print the form image?  Are you using the <Form>.PrintForm method?
not using access only vb6
MartinLiss
Re: I can't tell by looking at it so you'll need to try it.

Tried it and it did not work. it printed the cover form and the form to be printed
The only other thing i can think of to try is Put the code to print into another form
copy the data and print the other form
But it needs to be visible in order to print it so that doesn't gain you anything.
I have an idea. Be back soon.
ok
ASKER CERTIFIED SOLUTION
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks MartinLiss
What i don't understand is how the printed output does not show the forms title bar. This is good but i don't see how.
This may create another option :eg; copy the data to another form and use PrintForm on the other form
That won't work. I'll modify the project after I eat dinner.
ok
Well what I was going to do was to add a label at the top of the form that would contain "Bids" that would only be made visible for the print, but you already have lblJobName so why do you need the form's caption in the picture?
I don't want the forms caption in i thought printform always included the title bar weather you wanted it or not. is this incorrect ?
PrintForm never shows the form caption.
Thanks, thought it did
MartinLiss discovered this;
The printform will work in a form without it being shown
Public Sub PrintGetBids()
  frmPrintGetBids.Visible = True
 frmPrintGetBids.Left = Screen.Width + 500
 PrintForm
End Sub
The printform will work in a form without it being shown
Yes I know that's true, but in the code you just posted you have

 frmPrintGetBids.Visible = True

so I don't understand what you are trying to say.
yes but then i moved off the screen
 frmPrintGetBids.Left = Screen.Width + 500
Why?

Are you printing from a modified copy of the other form? If so why do you feel you need to do that?
Yes it is a modified copy of the other form, guess i did it because I had already made the modified copy  from earlier attempts, before printform eg grid and column widths,placement etc
on the upside:
No need to write code to put everything back.
On the downside:
Another form added to project.
Is there any reason why this will not work ?
Another downside is that you'll need to remember to make changes to both forms if the main one needs to be changed. I wouldn't do it that way but your way will work.
Thanks, have already ran into that:
lblRecap.Caption = "Recap for " & cboBids.Text
It should be a fairly easy thing to do it with one form. Can you provide a copy of your main form (even if it won't work by itself) and tell me all the temporary changes you want to make to it for printing purposes?
Thanks MartinLiss,but the form has ton's of ocx's that have to replaced.
This i know how to do (althought not as good as you)
i Sure like your help for what I don't how to do
If I sent the code I wrote you could not stop laughing long enough.
I have stuff like this:
Dim PaperWidth As Long
PaperWidth = 1440 * 8.5
lblRecap.Left = PaperWidth / 2 - lblRecap.Width / 2
lblJobName.Left = PaperWidth / 2 - lblJobName.Width / 2
I wouldn't laugh. Believe me I've seen it all. Many more years ago then I like to think about (circa 1973) when I was in one of my first programming classes we were being taught COBOL which has a MOVE statement, and one person attempted to write a program that contained many statements like PLEASE MOVE.... lol. I guess I do laugh at some code:)

Anyhow here's how I'd change that code.

Const PaperWidthInTwips As Long = 11520

lblRecap.Left = PaperWidthInTwips / 2 - lblRecap.Width / 2
lblJobName.Left = PaperWidthInTwips / 2 - lblJobName.Width / 2
I have had some funny support calls
had ad customer email me with a software problem
His closing comment "And I'm not looking for an email buddy"
Another lady "Your left or My Left ?"
Another lady on the phone with me telling her to click the cd.
She said "I'm holding the mouse right by the cd door and nothing happens"
never seen this before PaperWidthInTwips
PaperWidthInTwips is just a descriptive name that I made up.
It's 1440 times 8.5
I see now No wonder it didn't Google