Solved

.net - reference on control

Posted on 2002-05-18
3
129 Views
Last Modified: 2010-05-02
Hi!

I am writing test vb.net app and I cannot solve this problem:

Let say I have two independent forms Form1 and Form2. On Form1 is textbox1 and on Form2 is button1.
Button_click code should be (like in VB6): form1.textbox1.text = »test«

But obviously in .net things are more restrictive. Can anyone tell me, how to solve this?
I already write this app in vb6 and then upgrade it to .net. Upgraded project works fine with upgrade code added »Public Shared Property DefInstance()«.

I believe this in not the way to write new apps (always and on every form add this property) in .net and I am looking for right way to do this.

Thanks for help!
Mitja
0
Comment
Question by:mitja040500
  • 2
3 Comments
 
LVL 10

Accepted Solution

by:
smegghead earned 100 total points
ID: 7020065
Hi,

try this...

1. Create a new project & add form1 & form2 to it
2. Put a button on form1
3. Put a textbox on form2
4. Add a variable to Class Form1 (MyForm2 as Form2)
5. See the form_load & button1_click events below.

Public Class Form1
    Inherits System.Windows.Forms.Form

    Private MyForm2 As Form2

#Region " Windows Form Designer generated code "

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        MyForm2 = New Form2()
        MyForm2.Show()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        MyForm2.TextBox1.Text = "hello"
    End Sub
End Class
0
 
LVL 10

Expert Comment

by:smegghead
ID: 7024921
Thanks for the points, but ... Grade B ??? :-(

It doesn't cost you any more to award an 'A'

Smg.
0
 

Author Comment

by:mitja040500
ID: 7025359
Sorry for grade B, but if I am honest, answer did not satisfy me at all, but because in meanwhile I found solution I decide to close this question.

Maybe I was not enough specific, but question was meant, that I have two independent forms, what means, that form1 or form2 are already opened (maybe my third form) and I would like to transfer some data from one Form to another.

Your solution is simple and also documented in help (it is even simpler):
    Private Sub Button1_Click(…)
        Dim myform2 As New Form2()
        myform2.TextBox1.Text = "Something"
        myform2.Show()
    End Sub
So opening and writing to a form in this case is simple, but you MUST always open new form.

What should you do if the form2 is already opened (by formX), and you would like to write to form2 from form1? Hmm... That’s why grade B.
Of course I could give you A and it does not cost me nothing, but it is not fair to other users, who will expect »real solution«.

I hope you will understand my decision.

Mitja
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need VBS version of Excel date conversion 4 64
VB 6.0 printer how to align 6 57
VBA error replacing data 6 37
Can we place a tooltip on the actual vb6 form 5 35
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

911 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

16 Experts available now in Live!

Get 1:1 Help Now