Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Report Preview in Top Level Form

Status
Not open for further replies.

sdocker

IS-IT--Management
Aug 12, 2010
218
GB
I am using Mile Gagnon's post, listed below to preview a report in a top level form, which may have another form already open in it.

It works fine, except I cannot seem to control the width of the "PrintPreview" object. Using the Sysmetric() function looks strange on a large monitor. Is it possible affected by the size of the report when it is previewed.?

Sam

[============================================]
thread184-1632960

DEFINE CLASS printpreview as Form
titlebar = 0
Showwindow = 2 &&Top level
autocenter = .t.
name = "PrintPreview"
height = SYSMETRIC(2) && This will maximize the preview
width = SYSMETRIC(1)&& This will maximize the preview
ENDDEFINE


2. In your command button (that generates the report)

PUBLIC oPrint
oPrint= CREATEOBJECT("printPreview")
oPrint.SHOW()
REPORT FORM COUNTRY.FRX PREVIEW WINDOW PrintPreview IN WINDOW PrintPreview NOWAIT && This is borrowed from rgbean
DO WHILE EMPTY(WONTOP()) OR ;
'Printpreview' $ UPPER(WONTOP())
DOEVENTS
ENDDO
IF VARTYPE("oPrint") = "O"
oPrint.RELEASE()
ENDIF
[============================================]







 
Well, Sysmetric(1) may be the combined width of two or three displays, if you have multi monitor. Simply replace that with whatever suits you better 1280 or 1920 or whatever a single display width is.

Look around whats better. Sysmetric bases on an API function giving other system metrics better suiting your needs, but you don't always need to develop for the general case. How about simply taking the width of the form starting the report?

The width will only determine the preview size, nothing else.

Bye, Olaf.
 
Thanks Olaf,

I'm not sure I understand. I changed the width statement,

width = ofrmMain.width​

but it seems to have a mind of it's own. It is the "Form" I'm having trouble with, not the pereview window.

Thanks,
Sam
 
Sam,

The width of the print preview is not a function of the width of the form. The print preview is a fixed width (at a given screen resolution and zoom factor), and does not vary as you resize the window. If the user wants to vary the width, they use the zoom control.

The solution, therefore, is to give your window a fixed width. If your report is on A4, the width should be a little over 210 mm. What that means in pixels depends on the screen resolution, and is easy to determine.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
I don't know what you're saying. You earlier said: I cannot seem to control the width of the "PrintPreview" object. That's what I addressed.
I can't tell you, what you want as width number, but the width=SYSMETRIC(1) is the line to change to get another preview width.
Using the calling form width was just a suggestion, you can also put in a constant there, whatever suits you. The preview will show with that width, no matter what the paper format of the later print will be, and the zoom tool enebles the user to size the preview and scroll in it.

Now you say you have problems with your "Form". What problems?
Or are you not understanding that the printPreview object you create by CREATEOBJECT("printPreview") IS the form defined by DEFINE CLASS printPreview as Form?

Bye, Olaf.
 
Sam,

Have you managed to solve the problem yet? Were the suggestion you received any help?

If not, you might like to consider a couple of other ways of displaying the preview that might suit your needs. Have a look at my article, Taming the Visual FoxPro report preview window. The first section describes the IN WINDOW option that you are using. But I wonder if the second section ("VFP 9.0's alternative preview window") might be a good approach for you.

This is the method I generally use myself (except when I am using XFRX, but that's another story), and it gives good results.

The article also shows how you can customise a report listener to give you more control over the preview window, but that might be overkill in this case.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Mike,

Sorry for not getting back sooner. I have to handle other things as they pop up.
i will try the other method you suggested and get back ASAP.

Olaf,
I am aware that the PrintPreview object I create by CREATEOBJECT("PrintPreview") is the form defined by DEFINE CLASS printPreview as Form? This is the form in which the preview window is displayed and it is the "FORM" I am having trouble with. The user is using MicroSoft Remote Desktop and spanning over two screens. Sysmetric(1) returns the combined width of both screens, which is unaccepatble.

Sam
 
>Sysmetric(1) returns the combined width of both screens, which is unaccepatble.

And that's why I suggested using the width of the form starting the preview form, which I assume IS fully visible.
If that's the form, which is too wide, is THAT the problem you have with that form? Is it the form you refer to as FORM?

I suggested you set this to 1280 or 1920 or whatever suits you.

What value do you want? SYSMETRIC will NOT give a single screen width with any parameter value, you have to use something else, if you want that single screen width. Windows API.

Bye, Olaf.

 
To get the width of the primary monitor in a multi-monitor setup, I think you need SystemParametersInfo().

Something like this (this is just off the top of my head, and not tested by me):

Code:
DECLARE INTEGER SystemParametersInfo IN Win32Api ;
    INTEGER   uiAction,;
    INTEGER   uiParam,;
    STRING    @pvParam,;
    INTEGER   fWinIni

lcBuffer = SPACE(16)
SystemParametersInfo(48, 0, @lcBuffer, 0)

lcDWord = SUBSTR(lcBuffer, 9, 4)
lnWidth = ;
	          ASC(SUBSTR(lcDWord, 1,1)) + ;
	BITLSHIFT(ASC(SUBSTR(lcDWord, 2,1)),  8) +;
	BITLSHIFT(ASC(SUBSTR(lcDWord, 3,1)), 16) +;
	BITLSHIFT(ASC(SUBSTR(lcDWord, 4,1)), 24)

However, I still think that you should set the width to a fixed value, not to a proportion of the physical screen size. For an A4 report, I generally expect the width to be about 800 pixels on a 1280 x 720 screen. This has got nothing to do with the physical size of the screen.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Mike and Olaf,

Using fixed dimensions helped. The results are much more predictable.

Thanks,
Sam
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top