Solved

.net - reference on control

Posted on 2002-05-18
3
130 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBA color chart bars 12 84
Reading the Contents of a Directory In Access VBA 5 68
VB6 - Compare and highlight cell not the same 3 49
RUNRMTCMD from AS/400 12 44
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

786 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