Passagio testo tra due Form

mercoledì 18 aprile 2007 - 11.35

corsaro Profilo | Newbie

Questa e la prima form che ne apre un altra quando clicco sul pulsante

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace ProvaForm
{
public partial class Form1 : Form
{
public IntPtr riferimento;

public Form1()
{
InitializeComponent();
riferimento = this.Handle;
}

private void button1_Click(object sender, EventArgs e)
{
Form2 finestra = new Form2(textBox1.Text);
//finestra.chiamante = riferimento;
finestra.Show();
}
}
}



Questa è la seconda Form che viene aperta

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace ProvaForm
{

public partial class Form2 : Form
{
public IntPtr chiamante;

public Form2(string textForm)
{

InitializeComponent();
parametri(textForm);
//textBoxForm2.Text = textForm;

}
public void parametri(string textForm)
{
textBoxForm2.Text = textForm;
}

private void button1_Click(object sender, EventArgs e)
{
// Form.FromHandle(chiamante).Controls["label1"].Text = "Programmazione.it";
// textBoxForm2.Text = form1.textBox1.Text;
Form1 form1 = new Form1();
textBoxForm2.Text = form1.label1.Text;
textBoxSecondo.Text = form1.textBox1.Text;
}
private void Form2_Load(object sender, EventArgs e)
{

}
}
}



Vorrei che cliccando sul bottone della seconda Form2 venga preso il testo della textBox1 della prima Form1 e trasferito sul textBox della seconda form Form2

ma non funziona vi prego Aiutatemi vi lascio anche il codice del designer....




namespace ProvaForm
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;

/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}

#region Windows Form Designer generated code

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(101, 81);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(98, 164);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(35, 13);
this.label1.TabIndex = 1;
this.label1.Text = "label1";
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(101, 25);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(100, 20);
this.textBox1.TabIndex = 2;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.label1);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
this.PerformLayout();

}

#endregion

private System.Windows.Forms.Button button1;
public System.Windows.Forms.Label label1;
public System.Windows.Forms.TextBox textBox1;
}
}



namespace ProvaForm
{
partial class Form2
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;

/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}

#region Windows Form Designer generated code

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.textBoxForm2 = new System.Windows.Forms.TextBox();
this.textBoxSecondo = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(51, 105);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// textBoxForm2
//
this.textBoxForm2.Location = new System.Drawing.Point(51, 43);
this.textBoxForm2.Name = "textBoxForm2";
this.textBoxForm2.Size = new System.Drawing.Size(100, 20);
this.textBoxForm2.TabIndex = 1;
//
// textBoxSecondo
//
this.textBoxSecondo.Location = new System.Drawing.Point(51, 79);
this.textBoxSecondo.Name = "textBoxSecondo";
this.textBoxSecondo.Size = new System.Drawing.Size(100, 20);
this.textBoxSecondo.TabIndex = 2;
//
// Form2
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.textBoxSecondo);
this.Controls.Add(this.textBoxForm2);
this.Controls.Add(this.button1);
this.Name = "Form2";
this.Text = "Form2";
this.ResumeLayout(false);
this.PerformLayout();

}

#endregion

private System.Windows.Forms.Button button1;
public System.Windows.Forms.TextBox textBoxForm2;
private System.Windows.Forms.TextBox textBoxSecondo;
}
}

alextyx Profilo | Expert

Guarda qui. L'esempio è in VB Net, ma dovrebbe essere facilmente applicabile anche in C#

http://forum.masterdrive.it/showthread.php?t=17291
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-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5