?
Solved

Add text to Second form

Posted on 2004-10-15
3
Medium Priority
?
309 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

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

777 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