Solved

Add text to Second form

Posted on 2004-10-15
3
301 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
  • 2
3 Comments
 
LVL 4

Accepted Solution

by:
gdexter earned 125 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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 …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now