Solved

Longer forms

Posted on 2000-05-09
18
206 Views
Last Modified: 2010-05-02
I want do do a longer form that the one VB offers and I want to be able to print it. A kind of forms that Access let you do. May someone help me please ?
0
Comment
Question by:trick_jc
  • 9
  • 4
  • 2
  • +3
18 Comments
 

Expert Comment

by:visualfool
Comment Utility
I think i saw something at http://616.org
0
 
LVL 28

Expert Comment

by:AzraSound
Comment Utility
you have some options...create an MDI form in which its child forms can be longer and the MDI form can scroll to view its contents, or create a scrollable form:


http://www.thescarms.com/VBasic/ScrollForm.htm

you can also use a picturebox as a container to allow for scrolling that way
0
 
LVL 7

Expert Comment

by:BarryTice
Comment Utility
You get limitations on your form size based on your screen size, unfortunately. You can subclass your form to get around this.

I posted a question about this a few months back, and Erick37's response included the following:

You can make the form any size you want.  Windows has a MINMAXINFO structure which holds info regarding a window's minimum and maximum sizes.  By subclassing your form, you can intercept the WM_GETMINMAXINFO message and then set the max size to whatever you like.  Then you will be able to set the  form's width and height beyond the screen.

Example:

 "HOWTO: Limit a Window's Minimum and Maximum size"
http://support.microsoft.com/support/kb/articles/Q185/7/33.ASP

You can read the whole post for 10 points at
http://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=10308833

Hope this helps. -- b.r.t.
0
 

Author Comment

by:trick_jc
Comment Utility
I can do that but wath about the printing part. How can I printform the part that you have to scroll to see ???
0
 

Author Comment

by:trick_jc
Comment Utility
the message above is for AzraSound

Now forBarryTice
Can I print with your solution
0
 
LVL 32

Expert Comment

by:Erick37
Comment Utility
If you subclass the form, then you can modify the minimum and maximum limits the form can be sized.  VB restricts the max height to the height of the screen.  But you can override this.  The following MS article demonstrates how to modify this information.

To set a specific height, use:

'~~~Form code example
Private Sub Form_Load()          
  'Save handle to the form.
  gHW = Me.hwnd          
  'Begin subclassing.          
  Hook
  Me.Height = 15000 'Twips
End Sub

'~~~BAS module code example
'Excerpt from MS article (modified)

'Specify new maximum size for window.
'Pixels are used here
'...
MinMax.ptMaxTrackSize.y = 1500 / Screen.TwipsPerPixelX
'...

Example code:

"HOWTO: Limit a Window's Minimum and Maximum Size"
http://support.microsoft.com/support/kb/articles/Q185/7/33.ASP
0
 
LVL 32

Expert Comment

by:Erick37
Comment Utility
:)
0
 
LVL 32

Expert Comment

by:Erick37
Comment Utility
Oops, forgot a zero:

MinMax.ptMaxTrackSize.y = 15000 / Screen.TwipsPerPixelX
0
 
LVL 12

Expert Comment

by:mark2150
Comment Utility
Printing with PrintForm is easy, but not the best way to handle things. The PrintForm basically does a screen dump. This will give you ragged looking text and essentially no control over the print job. Additionally it will be printer resolution sensitive where the function will print differently on different printers.

The problem of having a form too large for the screen and printer is easily solved by recoding the print routine to *draw* the form as a series of graphic elements when printing. This means that you can split your on-screen display into several screens as now there is no longer a need to PrintForm. This gives your application a much more professional feel and gives much higher quality output that will render the same on *any* printer (even those not yet developed - when their driver is added to windows, your app will print correctly on it)

Use the Printer.Scale command to set the page dimensions to an appropriate scale and then position the print cursor with Printer.CurrentX/Y. Print text with Printer.Print or lines with Printer.Line. The .Line command can also draw boxes or solid filled rectangles. The .Circle command can draw circles or filled pie segments. PicturePrint can toss out graphics and images.

While the print routine will be more than a simple PrintForm, the results will be well worth it.

One additional benefit is that if you code your print routine where the printer object is passed to it you can then use the SAME routine for screen preview and final printing. You pass the routine a PictureBox or a Form and you'll get screen preview. You pass the routine the Printer object and you'll get high quality printing. You will have to put a little conditional logic around certain device specific statements, but 99% of the printer commands are common to both the screen and the printer (you can't .EndDoc the screen or you can't set the .BackGround color of the printer)

M
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:trick_jc
Comment Utility
This question is refering to Erick37 comment

Your comment is great but how can I print this new longer form ???
0
 

Author Comment

by:trick_jc
Comment Utility
mark2150 : Can you give me an example for your comment. please!!!
0
 

Author Comment

by:trick_jc
Comment Utility
Erick37 : How can I scroll in that form
0
 
LVL 32

Expert Comment

by:Erick37
Comment Utility
If you make the form an MDIChild form, and place it in an MDIForm, then the MDIForm will automatically allow you to scroll to view the large form.

You can print using PrintForm, but, as Mark has pointed out, the quality of the printout may be less than you require.  PrintForm renders a snapshot of the form to the printer.
0
 

Author Comment

by:trick_jc
Comment Utility
Erick37 : I tryed with the MDIform but it did not work
0
 
LVL 12

Accepted Solution

by:
mark2150 earned 95 total points
Comment Utility
Here is the complete source code to a business card printer I wrote.

It prints ten copies of a business card on a single page and shows the basic techniques.

'
' Program to print Networking Experts, Inc. Business cards
' By: Mark M. Lambert on February 15, 2000
' Copyright 2000 - Networking Experts, Inc. - All Rights Reserved
'
' V1.0.x - 15 Feb 00 - MML - Initial code
'
Option Explicit

Private Sub Btn_Exit_Click()
Call Die
'
End Sub

Private Sub Btn_Print_Click()
'
' Here when print requested
'
Dim X As Double
Dim Y As Double
'
If Not ArmPrinter Then Exit Sub
'
Printer.Scale (0, 0)-(8, 10.5) '8-1/2 x 11 with 1/4" margins
Printer.FillColor = vbBlack
Printer.ForeColor = vbBlack
Printer.Font = "Times New Roman"
Printer.FontSize = 10
'
For Y = 0 To 8 Step 2
    For X = 0 To 3.5 Step 3.5
        Call aCard(X, Y)
    Next X
Next Y
'
Printer.EndDoc
End Sub

Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
Call CheckOK
'
End Sub

Private Sub Form_Load()
'
If App.PrevInstance Then Call Die
'
End Sub

Public Sub CheckOK()
'
' Check to see if [Print] button should be enabled
'
Btn_Print.Enabled = (Len(Trim(FullName.Text)) > 0 And _
                        Len(Trim(Title.Text)) > 0 And _
                        Len(Trim(Phone.Text)) = 10 And _
                        Len(Trim(eMail.Text)) > 0)
'
End Sub

Public Sub Die()
'
' Program termination
'
Dim Frm As Form
'
For Each Frm In Forms
    Unload Frm
    Set Frm = Nothing
Next Frm
'
End
' =====================================
' =====================================
'
' Fin
'
' =====================================
' =====================================
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
'
' Don't recurse if called by code...
'
If UnloadMode <> vbFormCode Then Cancel = True
'
End Sub

Public Sub aCard(X As Double, Y As Double)
'
Dim OldParam    As Variant
Dim LineSpace   As Double
Dim Xoffset     As Double
Dim Yoffset     As Double
Dim TelNo       As String
'
Const Factor    As Double = 1.05
'
' This prints a single card
'
Printer.Line (X, Y)-(X + 3.5, Y + 2), vbBlack, B
'
Printer.PaintPicture ImageList1.ListImages(1).Picture, X + 0.25, Y + 0.25, 1.5, 1.5
'
' Put in name
'
LineSpace = Printer.TextHeight("X") * Factor
Xoffset = 3.25
Yoffset = 1
'
Printer.CurrentX = (X + Xoffset) - Printer.TextWidth(FullName.Text)
Printer.CurrentY = Y + Yoffset
Printer.Print FullName.Text
'
' Now title
'
Printer.FontItalic = True
Printer.CurrentX = (X + Xoffset) - Printer.TextWidth(Title.Text)
Printer.CurrentY = Y + Yoffset + LineSpace
Printer.Print Title.Text
Printer.Line (X + Xoffset, Y + Yoffset + LineSpace * 2)-(X + Xoffset - 1.5, Y + Yoffset + LineSpace * 2), vbBlack
Printer.FontItalic = False
'
' Change to smaller font for balance of card
'
OldParam = Printer.FontSize
Printer.FontSize = 8
LineSpace = Printer.TextHeight("X") * Factor
Yoffset = 0.675
'
TelNo = Format(Phone.Text, "(###) ###-####")
Printer.CurrentX = (X + Xoffset) - Printer.TextWidth(TelNo)
Printer.CurrentY = Y + Yoffset + LineSpace * 7
Printer.Print TelNo
'
Xoffset = 0.75
Printer.CurrentX = X + Xoffset
Printer.CurrentY = Y + Yoffset
Printer.Print "www.netexperts.cc"
'
Printer.CurrentX = X + Xoffset
Printer.CurrentY = Y + Yoffset + LineSpace
Printer.Print eMail.Text
'
Printer.CurrentX = X + Xoffset
Printer.CurrentY = Y + Yoffset + 6 * LineSpace
Printer.Print "POB 1234-5678"
'
Printer.CurrentX = X + Xoffset
Printer.CurrentY = Y + Yoffset + 7 * LineSpace
Printer.Print "New Smyrna Beach, FL   32168"
'
Printer.FontSize = OldParam
'
End Sub

Public Function ArmPrinter() As Boolean
'
' This function is used to determine if printing is required
' The big savings is that any form can call us and that
' particular form doesn't need a COMMONDIALOG object locally
' to determine if printing is switched on. This function returns
' a logical:
'
'   TRUE - Print
'   FALSE - Cancel
'
' Thus the caller can simply use:
'
'   if not armprinter then goto {abort label}
'
' Pretty slick, eh?
'
ArmPrinter = True
On Error GoTo trapped
CommonDialog1.Flags = 0
CommonDialog1.CancelError = True
CommonDialog1.ShowPrinter
'
' We make it here then user said OK to print, pass default
' value back
'
GoTo drain
' =================
'
' Here on error trap of [Cancel], pass falsity back
'
trapped:
ArmPrinter = False
Resume drain
' = = = = = = No fallthru
'
drain:
End Function

0
 

Author Comment

by:trick_jc
Comment Utility
mark2150 : could you send me a sample of your project (.frm) to this email
trick_jc@hotmail.com
please
0
 

Author Comment

by:trick_jc
Comment Utility
Adjusted points from 90 to 95
0
 

Author Comment

by:trick_jc
Comment Utility
thanks
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

772 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

16 Experts available now in Live!

Get 1:1 Help Now