Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Add text to Second form

Posted on 2004-10-15
3
Medium Priority
?
310 Views
Last Modified: 2010-04-23
How can I add text to another form without re-showing it?
I can do it if I use the following code


Dim t As New Form2
        t.TextBox1.Text = "test"
t.show


But the form is already open so I don’t want to reshow it

I have tried

Dim t As New Form2
        t.TextBox1.Text = "test"
me.close

With no success
0
Comment
Question by:davidrichardson
[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
  • 2
3 Comments
 
LVL 4

Accepted Solution

by:
gdexter earned 500 total points
ID: 12322903
You can not do this by creating a new instance of Form2. You need to pass a reference to the current instance of Form2 to the other form through a property.

Does Form2 open the active form that needs to adjust the text?

If you are not using MDI you can do something like this:

Public Class OtherForm
   'declare a reference variable
   private _Form2 as Form2
 
   Public WriteOnly Property MyForm2() as Form2
      Set(ByVal Value as Form2)
         Me._Form2 = Value
      End Set
   End Property

   Public Sub WriteToForm()
      Me._Form2.TextBox1.text = "test"
   End Sub

End Class

'When you open the OtherForm object from Form2 you pass a refence to itself
'In Form2

Public Sub LoadOtherForm
   
   Dim frm as New OtherForm
   frm.MyForm2 = Me
   frm.Show

End Sub

If you are using MDI this functionality is provided through the 'MDIParent' Property


 


   
 






0
 
LVL 7

Author Comment

by:davidrichardson
ID: 12323162
form 2 does open the active form, when i run WriteToForm() i get the following error

Object reference not set to an instance of an object

On line Me.frmscaninput.TextBox1.Text = "test"

Copy of full code used below

    Private frmscaninput As frmscaninput

    Public WriteOnly Property MyForm2() As frmscaninput
        Set(ByVal Value As frmscaninput)
            Me.frmscaninput = Value
        End Set
    End Property

    Public Sub WriteToForm()
        Me.frmscaninput.TextBox1.Text = "test"
    End Sub


Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        WriteToForm()

    End Sub
0
 
LVL 7

Author Comment

by:davidrichardson
ID: 12323300
my mistake i didnt as the load form cade properly

Thanks

Dave
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

610 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