Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hello,

How can I do?

I have two forms (form1 and form2) open.

if I push a button on form2, I want that a value goes to a textbox on form1.

Thank you

 

Public Class Form2

Inherits System.Windows.Forms.Form

 

#Region " Codice generato da Progettazione Windows Form "

.......

.......

#End Region

 

Dim frm As New Form1()

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

 

frm.Text1.Text = "PROVAR"

frm.Refresh()

 

End Sub

End Class

  • *Experts*
Posted (edited)

Edit the form constructor. If the form1 is the one you open first, leave it like it is and edit the constructor of the second one so it accepts a form instance as an argument, like this:

'this in your second form
Dim firstform As Form1 'variable to hold an instance of the first
'form that will be available to the whole class
Public Sub New(ByVal frm As Form1) 'accept an instance of the form
MyBase.New()
InitializeComponent()
firstform = frm 'assign the passed in instance to the variable that can
'be accessed in whole class
End Sub

Then you just access form with firstform.TextBox1.Text = "something" or however you want to call it.

:)

Edited by mutant
Posted

Any ideas how to do this in c#.net

 

Hi, I'm new to .Net but working on the same

problem in c# and kinda stuck.

 

If you can help me out, I would be very greatful.

 

Cheers

 

Wacy1

  • *Experts*
Posted
Hi, I'm new to .Net but working on the same

problem in c# and kinda stuck.

 

If you can help me out, I would be very greatful.

 

Cheers

 

Wacy1

 

What is the problem you are having with it?

Posted

Form Problem

 

Hello Mutant,

 

Well I'm developing a Pocket Pc app that needs to take information from a number of forms. But there seems to be a problem with accessing the controls on a form that has been opened using the ShowDialog method.

 

Using the code below, throws a null exception when I try to access the text in test dialog's TextBox1.

 

Form2 testDialog = new Form2();

String s = "";

 

// Show testDialog as a modal dialog and determine if DialogResult = OK.

if (testDialog.ShowDialog(this) == DialogResult.OK)

{

// Read the contents of testDialog's TextBox.

s = testDialog.TextBox1.Text;

}

 

In form 2 a simple button that on click does:

DialogResult = DialogResult.OK

 

The dialog box closes and any references to the dialog box causes an exception.

 

It works fine for Windows froms, just not in a smartdevice app.

If anyone could shed some light on it, I would be greatful.

 

Cheers in advance

 

Wacy1

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...