?
Solved

Passing Variable from one form to another and opening pdf file

Posted on 2007-07-25
3
Medium Priority
?
156 Views
Last Modified: 2010-04-23
vb.net 2003

2 forms

"form1" =  with tab control(using Tab4)
"cboAdobeFiles" - combobox   this contains a list of pdf  files...
I have code loading the pdf file names ok

Command Button =   "cmdOpAdobe"

code for command button
ShowForm3()


Public f3 As FormAdobe
Public Sub ShowForm3()
        If f3 Is Nothing Then
            f3 = New FormAdobe
            AddHandler f3.Closed, AddressOf f3_Closed
            f3.Show()
        End If
        f3.BringToFront()
    End Sub




When I press this button I'am opening a form called "formAdobe"

I have an ActiveXcontrol for Adobe on this form.
"formAdobe"  =  -- has an activexcontrol called  "AxPdf1"


Pdfs are stored in dir "C:\PdfPages"

What I need:
After I select an Item in the listbox on Form1

I press the command button and it opens "formAdobe"

A NEED A variable passing the listbox selection so the
source for the "AxPdf1" is set to the path specified with the listbox(variable).


In the load event of  "formAdobe"  I'am trying to set the source of the activeXcontrol from the value in the comboxbox on form1


Private Sub FormAdobe_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ' Me.AxPdf1.LoadFile("C:\PROGRAM FILES\PDFPAGES\00010.PDF")
        ' Me.AxPdf1.LoadFile()
    End Sub


My problem is passing the variable from form1   to FormAdobe ?


Thanks
fordraiders

0
Comment
Question by:Fordraiders
3 Comments
 
LVL 8

Accepted Solution

by:
Autoeforms earned 2000 total points
ID: 19565352
i would create a public property in form2

public sAdobeOath as string

        Public Property sPDFValue() As String
            Get
                Me.axpdf1.source() ' ?what ever the source value is
            End Get
            Set(ByVal value As String)
                Me.AxPdf1.LoadFile(value)

            End Set
        End Property



then in your command button if you are doing

       If f3 Is Nothing Then
            f3 = New FormAdobe
            AddHandler f3.Closed, AddressOf f3_Closed
           f3.sAdobeOath = "your source string"
            f3.Show()
else
           f3.sAdobeOath = "your source string"
        End If


see if this solves your problem
greg
0
 
LVL 27

Expert Comment

by:planocz
ID: 19565368
Hi fordraiders,
Here is an app. that will pass vers to other forms.


'MODULE
Module Module1
   Public Sub main()
      Dim Controller As New FormController()
      Dim frm1 As New Form1(Controller)
      frm1.ShowDialog()
   End Sub
End Module

' FormController

Imports System.Collections
Public Class FormController
   Dim forms As New ArrayList()

   Public Sub Add(ByVal frm As ControlledForm)
      If Not forms.Contains(frm) Then
         forms.Add(frm)
      End If
   End Sub
   Public Sub Remove(ByVal frm As Form)
      If forms.Contains(frm) Then
         forms.Remove(frm)
      End If
   End Sub
   Public Function Form(ByVal frmName As String) As ControlledForm
      Dim o As Object
      For Each o In forms
         If CType(o, Form).Name = frmName Then
            Return CType(o, Form)
         End If
      Next
      Return Nothing
   End Function
   Public ReadOnly Property AllForms() As ArrayList
      Get
         Return forms.Clone()
      End Get
   End Property
End Class

 '  FORM2
Option Strict On
Public Class Form2
   Inherits ControlledForm
#Region " Windows Form Designer generated code "

   Public Sub New(ByVal Controller As FormController)
      MyBase.New(Controller)

      'This call is required by the Windows Form Designer.
      InitializeComponent()

      'Add any initialization after the InitializeComponent() call

   End Sub

   'Form overrides dispose to clean up the component list.
   Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
      If disposing Then
            Dim frm As Form = Me.Controller.Form("Form1")
            Dim lbl As Label = CType(Me.FindControl(frm, "Label1"), Label)
            lbl.Text = ""
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
      MyBase.Dispose(disposing)
   End Sub

   'Required by the Windows Form Designer
   Private components As System.ComponentModel.IContainer

   'NOTE: The following procedure is required by the Windows Form Designer
   'It can be modified using the Windows Form Designer.  
   'Do not modify it using the code editor.
   Friend WithEvents Button1 As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.Button1 = New System.Windows.Forms.Button
        Me.SuspendLayout()
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(300, 12)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(136, 24)
        Me.Button1.TabIndex = 0
        Me.Button1.Text = "Button1"
        '
        'Form2
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(448, 362)
        Me.Controls.Add(Me.Button1)
        Me.Name = "Form2"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.Manual
        Me.Text = "Form2"
        Me.ResumeLayout(False)

    End Sub

#End Region

   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
      Dim frm As Form = Me.Controller.Form("Form1")
      If Not frm Is Nothing Then
         Dim lbl As Label = CType(Me.FindControl(frm, "Label1"), Label)
         If Not lbl Is Nothing Then
            lbl.Text = "Got here"
         End If
      End If
   End Sub
    Private Function FindControl(ByVal frm As Form, ByVal ctrlName As String) As Control
        Dim ctrl As Control
        For Each ctrl In frm.Controls
            If ctrl.Name = ctrlName Then
                Return ctrl
            End If
        Next
        Return Nothing
    End Function
End Class

' FORM1
Option Strict On
Imports System
Imports System.Globalization
Public Class Form1
    Inherits ControlledForm

#Region " Windows Form Designer generated code "

    Public Sub New(ByVal Controller As FormController)
        MyBase.New(Controller)

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Button1 As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.Label1 = New System.Windows.Forms.Label
        Me.Button1 = New System.Windows.Forms.Button
        Me.SuspendLayout()
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(20, 28)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(108, 16)
        Me.Label1.TabIndex = 0
        Me.Label1.Text = "Hello"
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(176, 16)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(68, 32)
        Me.Button1.TabIndex = 1
        Me.Button1.Text = "Button1"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(292, 266)
        Me.Controls.Add(Me.Button1)
        Me.Controls.Add(Me.Label1)
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim frm2 As New Form2(Controller)
        frm2.Location = New Point(Me.Left + 200, Me.Top + 100)
        frm2.Show()
    End Sub
End Class

' ControlledForm
Public Class ControlledForm
   Inherits System.Windows.Forms.Form
   Private m_Controller As FormController
   Public Sub New()
   End Sub
   Public Sub New(ByVal controller As FormController)
      m_Controller = controller
      controller.Add(Me)
   End Sub
   Public ReadOnly Property Controller() As FormController
      Get
         Return m_Controller
      End Get
   End Property

   Private Sub InitializeComponent()
      '
      'ControlledForm
      '
      Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
      Me.ClientSize = New System.Drawing.Size(288, 229)
      Me.Name = "ControlledForm"

   End Sub

   Private Sub ControlledForm_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Closed
      Me.Controller.Remove(Me)
   End Sub

End Class

0
 
LVL 27

Expert Comment

by:VBRocks
ID: 19565477
Here's an example of how you can do this.

First, on FormAdobe, instead of the AxPdf control, I have a WebBrowser control, which works very nicely.

You can create a constructor on FormAdobe to receive an argument of the .pdf file that is to be opened.
This will let you pass the name of the file from your main form to FormAdobe.


Example:

    Private Sub cmdOpAdobe_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles cmdOpAdobe.Click

        Dim file As String = Me.ComboBox1.Text
        If My.Computer.FileSystem.FileExists(file) = True Then

            'Code to open form and pass the name of the adobe .pdf file to FormAdobe
            Dim f3 As New FormAdobe(file)
            f3.Show()

        End If

    End Sub




'Here's the FormAdobe code:
Public Class FormAdobe

    'This is a constructor that receives an argument of the .pdf file path
    Public Sub New(ByVal adobeFilePath As String)

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        Me.WebBrowser1.Navigate(adobeFilePath)

    End Sub

End Class

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Screencast - Getting to Know the Pipeline
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…

862 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