Solved

.net - reference on control

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

706 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

22 Experts available now in Live!

Get 1:1 Help Now