Aiutoooooooo !!! Prob. con C#

martedì 20 marzo 2007 - 16.12

corsaro Profilo | Newbie

Salve non riesco a passare dei parametri tra form mi potreste dare una mano e dirmi cosa sto sbagliando, il punto è : creo due form Form1 Form2 con due textBox vorrei che al click di un button mi passi il testo da una textBox all'altra..
Per farle capire meglio il prob. le mando il codice ....
Garzie...


//Seconda Form anche se è la prima ad aprirsi creando un dialogo con la Form1
namespace WindowsApplication1
{
/// <summary>
/// Descrizione di riepilogo per Form2.
/// </summary>
public class Form2 : System.Windows.Forms.Form
{
public System.Windows.Forms.TextBox textBoxForm2;
private System.Windows.Forms.Button button1;
/// <summary>
/// Variabile di progettazione necessaria.
/// </summary>
private System.ComponentModel.Container components = null;

public Form2()
{
//
// Necessario per il supporto di Progettazione Windows Form
//
InitializeComponent();

//
// TODO: aggiungere il codice del costruttore dopo la chiamata a InitializeComponent
//
}

/// <summary>
/// Pulire le risorse in uso.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Codice generato da Progettazione Windows Form
/// <summary>
/// Metodo necessario per il supporto della finestra di progettazione. Non modificare
/// il contenuto del metodo con l'editor di codice.
/// </summary>
public void InitializeComponent()
{
this.textBoxForm2 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// textBoxForm2
//
this.textBoxForm2.Location = new System.Drawing.Point(88, 88);
this.textBoxForm2.Name = "textBoxForm2";
this.textBoxForm2.TabIndex = 0;
this.textBoxForm2.Text = "";
//
// button1
//
this.button1.Location = new System.Drawing.Point(88, 32);
this.button1.Name = "button1";
this.button1.TabIndex = 1;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form2
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.button1);
this.Controls.Add(this.textBoxForm2);
this.Name = "Form2";
this.Text = "Form2";
this.ResumeLayout(false);

}
#endregion

private void button1_Click(object sender, System.EventArgs e)
{
Form1 form1 = new Form1();
form1.ShowDialog();

}
}
}


//Form1 una volta aperta questa form al click del pulsante vorrei che la textBox
//acquisisca il testo della textBox della form2.
namespace WindowsApplication1
{
/// <summary>
/// Descrizione di riepilogo per Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
public System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button button1;
/// <summary>
/// Variabile di progettazione necessaria.
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Necessario per il supporto di Progettazione Windows Form
//

InitializeComponent();
//
// TODO: aggiungere il codice del costruttore dopo la chiamata a InitializeComponent
//
}

/// <summary>
/// Pulire le risorse in uso.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Codice generato da Progettazione Windows Form
/// <summary>
/// Metodo necessario per il supporto della finestra di progettazione. Non modificare
/// il contenuto del metodo con l'editor di codice.
/// </summary>
public void InitializeComponent()
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(72, 64);
this.textBox1.Name = "textBox1";
this.textBox1.TabIndex = 0;
this.textBox1.Text = "";
//
// button1
//
this.button1.Location = new System.Drawing.Point(80, 136);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(136, 23);
this.button1.TabIndex = 1;
this.button1.Text = "Recupero_Dati";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.button1);
this.Controls.Add(this.textBox1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// Il punto di ingresso principale dell'applicazione.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form2());
}

private void button1_Click(object sender, System.EventArgs e)
{
Form2 form2 = new Form2();
textBox1.Text = form2.textBoxForm2.Text;
}
}
}

Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?

Dopo esserti registrato potrai chiedere
aiuto sul nostro Forum oppure aiutare gli altri

Consulta le Stanze disponibili.

Registrati ora !
Copyright © dotNetHell.it 2002-2025
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5