?
Solved

Longer forms

Posted on 2000-05-09
18
Medium Priority
?
217 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 4
  • 2
  • +3
18 Comments
 

Expert Comment

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

Expert Comment

by:AzraSound
ID: 2794577
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
ID: 2794589
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:trick_jc
ID: 2794596
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
ID: 2794602
the message above is for AzraSound

Now forBarryTice
Can I print with your solution
0
 
LVL 32

Expert Comment

by:Erick37
ID: 2794614
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
ID: 2794619
:)
0
 
LVL 32

Expert Comment

by:Erick37
ID: 2794626
Oops, forgot a zero:

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

Expert Comment

by:mark2150
ID: 2795903
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
 

Author Comment

by:trick_jc
ID: 2796022
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
ID: 2796059
mark2150 : Can you give me an example for your comment. please!!!
0
 

Author Comment

by:trick_jc
ID: 2796072
Erick37 : How can I scroll in that form
0
 
LVL 32

Expert Comment

by:Erick37
ID: 2796166
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
ID: 2796235
Erick37 : I tryed with the MDIform but it did not work
0
 
LVL 12

Accepted Solution

by:
mark2150 earned 380 total points
ID: 2796303
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
ID: 2796341
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
ID: 2796342
Adjusted points from 90 to 95
0
 

Author Comment

by:trick_jc
ID: 2797357
thanks
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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 Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month15 days, 11 hours left to enroll

741 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