Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 220
  • Last Modified:

Longer forms

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
trick_jc
Asked:
trick_jc
  • 9
  • 4
  • 2
  • +3
1 Solution
 
visualfoolCommented:
I think i saw something at http://616.org
0
 
AzraSoundCommented:
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
 
BarryTiceCommented:
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
trick_jcAuthor Commented:
I can do that but wath about the printing part. How can I printform the part that you have to scroll to see ???
0
 
trick_jcAuthor Commented:
the message above is for AzraSound

Now forBarryTice
Can I print with your solution
0
 
Erick37Commented:
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
 
Erick37Commented:
:)
0
 
Erick37Commented:
Oops, forgot a zero:

MinMax.ptMaxTrackSize.y = 15000 / Screen.TwipsPerPixelX
0
 
mark2150Commented:
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
 
trick_jcAuthor Commented:
This question is refering to Erick37 comment

Your comment is great but how can I print this new longer form ???
0
 
trick_jcAuthor Commented:
mark2150 : Can you give me an example for your comment. please!!!
0
 
trick_jcAuthor Commented:
Erick37 : How can I scroll in that form
0
 
Erick37Commented:
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
 
trick_jcAuthor Commented:
Erick37 : I tryed with the MDIform but it did not work
0
 
mark2150Commented:
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
 
trick_jcAuthor Commented:
mark2150 : could you send me a sample of your project (.frm) to this email
trick_jc@hotmail.com
please
0
 
trick_jcAuthor Commented:
Adjusted points from 90 to 95
0
 
trick_jcAuthor Commented:
thanks
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 9
  • 4
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now