[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Print current tabpage of tabcontrol

Posted on 2004-10-21
4
Medium Priority
?
1,430 Views
Last Modified: 2008-02-01
I have created a tabcontrol (TabControl1) in VB.NET with four tabpages.  I have put a button (Button1) on TabPage 2 and added a PrintDocument control.  I would like to know what code needs to be added under the Private Sub Button1_Click event to print TabPage2.  Thank you for your help.
0
Comment
Question by:georgecoppens
[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
4 Comments
 
LVL 48

Accepted Solution

by:
Mikal613 earned 500 total points
ID: 12377239
0
 
LVL 16

Assisted Solution

by:jimbobmcgee
jimbobmcgee earned 500 total points
ID: 12401248
It's a real pain to print controls in a container.  Basically you have to define your own flexible printer functions for each control type, then wrap it in a For Each/Next loop to iterate through your controls.  Not nice, or easy...

Alternatively, you can copy an area of the screen to a bitmap, then attempt to print that, but that is also difficult:  http://www.andreavb.com/tip090001.html  may give you some ideas on this...

The nicest way to print WYSIWYG controls in an area is to use the PrintForm method of the Form.  However, you don't want the whole form, so I suggest, combining the the methods to get something you might like:

I will assume you have your tab-contents in a Frame (but it will work for a Picturebox, with a little tweaking), on a form called frmInput.  It will create controls on a dummy form called frmOutput, before calling frmOutput.PrintForm:

    Private Sub CommandButton1_Click()
   
        On Error Resume Next
   
        Dim ctl As Control
       
        frmOutput.Width = frmInput.Frame1.Width
        frmOutput.Height = frmInput.Frame1.Height
   
        For Each ctl In frmInput.Controls
       
            If TypeOf ctl Is TextBox Then
           
                Set prn = frmOutput.Controls.Add("VB.TextBox", , True)    'CREATE A TEXT BOX
               
                    prn.Top = ctl.Top
                    prn.Left = ctl.Left
                    prn.Height = ctl.Height
                    prn.Width = ctl.Width
                    prn.Text = ctl.Text
                    prn.Visible = ctl.Visible                                'SET IT TO MATCH frmInput TEXT BOX
                   
                Set prn = Nothing
               
            ElseIf TypeOf ctl Is ComboBox Then
           
                Set prn = frmOutput.Controls.Add("VB.ComboBox", , True)
               
                    prn.Top = ctl.Top
                    prn.Left = ctl.Left
                    prn.Height = ctl.Height
                    prn.Width = ctl.Width
                    prn.Text = ctl.Text
                    prn.Visible = ctl.Visible
                   
                Set prn = Nothing
               
            ElseIf TypeOf ctl Is OptionButton Then
           
                Set prn = frmOutput.Controls.Add("VB.OptionButton", , True)
               
                    prn.Top = ctl.Top
                    prn.Left = ctl.Left
                    prn.Height = ctl.Height
                    prn.Width = ctl.Width
                    prn.Caption = ctl.Caption
                    prn.Value = ctl.Value
                    prn.Visible = ctl.Visible
                   
                Set prn = Nothing
               
            ElseIf TypeOf ctl Is CheckBox Then
           
                Set prn = frmOutput.Controls.Add("VB.CheckBox", , True)
               
                    prn.Top = ctl.Top
                    prn.Left = ctl.Left
                    prn.Height = ctl.Height
                    prn.Width = ctl.Width
                    prn.Caption = ctl.Caption
                    prn.Value = ctl.Value
                    prn.Visible = ctl.Visible
                   
                Set prn = Nothing
           
            End If
       
        Next ctl
       
        frmOutput.Show False
        frmOutput.Repaint
        frmOutput.PrintForm
   
    End Sub

I haven't had a chance to test this; I expect the class strings need debugging ("VB.CheckBox", "VB.TextBox", etc).  I haven't found a comprehensive list of these...

Give it try and tweak as required -- you may get something good that works for you...

HTH

J.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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 …
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
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…
Suggested Courses

649 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