Solved

Hide arranging form before print

Posted on 2014-10-13
44
159 Views
Last Modified: 2014-10-14
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 ?
0
Comment
Question by:isnoend2001
  • 22
  • 21
44 Comments
 
LVL 45

Expert Comment

by:Martin Liss
ID: 40378163
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
0
 

Author Comment

by:isnoend2001
ID: 40378179
Thanks MartinLiss i will try that after i change code to use another form for printing
0
 
LVL 45

Expert Comment

by:Martin Liss
ID: 40378200
You don't need to use another form. Did you see the project I posted in the make a forms width fit printout thread?
0
 

Author Comment

by:isnoend2001
ID: 40378266
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
0
 

Author Comment

by:isnoend2001
ID: 40378298
Before and after printBeforeAfterprintBeforeAfterprint
0
 

Author Comment

by:isnoend2001
ID: 40378329
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.
0
 
LVL 45

Expert Comment

by:Martin Liss
ID: 40378331
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.
0
 
LVL 45

Expert Comment

by:Martin Liss
ID: 40378339
Don't worry about CaptureClient since it's not used in your case.
0
 
LVL 45

Expert Comment

by:Martin Liss
ID: 40378409
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.
0
 

Author Comment

by:isnoend2001
ID: 40378442
Thanks MartinLiss. I had another thought
Have another borderless form cover the client area briefly (on top)
0
 
LVL 45

Expert Comment

by:Martin Liss
ID: 40378453
Again with my code, what you see is what you get so if you cover it you'll get a picture of the cover.
0
 

Author Comment

by:isnoend2001
ID: 40378462
I found this:
CaptureForm - Captures the entire form.
 CaptureClient - Captures the client area of a form.
0
 
LVL 45

Expert Comment

by:Martin Liss
ID: 40378506
CaptureForm is what I'm using. CaptureClient wouldn't act any differently as far as WYSIWYG.
0
 

Author Comment

by:isnoend2001
ID: 40378543
maybe the code i posted here: http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_28535877.html#a40377516
Would work where you pass the forms name
0
 
LVL 45

Expert Comment

by:Martin Liss
ID: 40378556
I can't tell by looking at it so you'll need to try it.
0
 
LVL 12

Expert Comment

by:jkaios
ID: 40378560
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?
0
 

Author Comment

by:isnoend2001
ID: 40378635
not using access only vb6
0
 

Author Comment

by:isnoend2001
ID: 40378689
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
0
 

Author Comment

by:isnoend2001
ID: 40378701
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
0
 
LVL 45

Expert Comment

by:Martin Liss
ID: 40378705
But it needs to be visible in order to print it so that doesn't gain you anything.
0
 
LVL 45

Expert Comment

by:Martin Liss
ID: 40378716
I have an idea. Be back soon.
0
 

Author Comment

by:isnoend2001
ID: 40378724
ok
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 45

Accepted Solution

by:
Martin Liss earned 500 total points
ID: 40378773
I know that the form that I have is not your actual form but what to rearrange that form so that it is narrower. That let's PrintForm work and PrintForm doesn't require that the changes be visible. As a demonstration this project temporarily changes the form's backcolor to vbYellow, prints it, and changes the backcolor back to what it was.
Q-28536734.zip
0
 

Author Closing Comment

by:isnoend2001
ID: 40378872
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
0
 
LVL 45

Expert Comment

by:Martin Liss
ID: 40378896
That won't work. I'll modify the project after I eat dinner.
0
 

Author Comment

by:isnoend2001
ID: 40378954
ok
0
 
LVL 45

Expert Comment

by:Martin Liss
ID: 40379007
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?
0
 

Author Comment

by:isnoend2001
ID: 40379041
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 ?
0
 
LVL 45

Expert Comment

by:Martin Liss
ID: 40379084
PrintForm never shows the form caption.
0
 

Author Comment

by:isnoend2001
ID: 40379095
Thanks, thought it did
0
 

Author Comment

by:isnoend2001
ID: 40380525
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
0
 
LVL 45

Expert Comment

by:Martin Liss
ID: 40380593
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.
0
 

Author Comment

by:isnoend2001
ID: 40380700
yes but then i moved off the screen
 frmPrintGetBids.Left = Screen.Width + 500
0
 
LVL 45

Expert Comment

by:Martin Liss
ID: 40380726
Why?

Are you printing from a modified copy of the other form? If so why do you feel you need to do that?
0
 

Author Comment

by:isnoend2001
ID: 40380967
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 ?
0
 
LVL 45

Expert Comment

by:Martin Liss
ID: 40380975
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.
0
 

Author Comment

by:isnoend2001
ID: 40381050
Thanks, have already ran into that:
lblRecap.Caption = "Recap for " & cboBids.Text
0
 
LVL 45

Expert Comment

by:Martin Liss
ID: 40381072
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?
0
 

Author Comment

by:isnoend2001
ID: 40381180
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
0
 
LVL 45

Expert Comment

by:Martin Liss
ID: 40381205
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
0
 

Author Comment

by:isnoend2001
ID: 40381384
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
0
 
LVL 45

Expert Comment

by:Martin Liss
ID: 40381392
PaperWidthInTwips is just a descriptive name that I made up.
0
 
LVL 45

Expert Comment

by:Martin Liss
ID: 40381393
It's 1440 times 8.5
0
 

Author Comment

by:isnoend2001
ID: 40381410
I see now No wonder it didn't Google
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now