( franklin | 2015. 06. 24., sze – 21:46 )

Elnézést, elég sűrű volt a dolog hogy vissza tudjak térni. Szóval nem, nem ipari titok a kód - látom leveszik a szóközöket, stb.

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

namespace GUITeszt
{

public partial class Form1 : Form
{
public string host { get; set; }

public Form1()
{
Application.EnableVisualStyles();
InitializeComponent();
this.textBox1.Text = "Alapérték";
}

private void textBox1_TextChanged(object sender, EventArgs e)
{
host = this.textBox1.Text;
}

private void button1_Click(object sender, EventArgs e)
{
switch (comboBox2.SelectedIndex)
{
case -1:
MessageBox.Show("Nem választottál semmit.");
break;

case 0:
MessageBox.Show("A host értéke: " + host); // Itt még jó az érték
Form2 form_Form2 = new Form2();
form_Form2.ShowDialog();
break;
}
}
}
}

Form2:

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

namespace GUITeszt
{

public partial class Form2 : Form {

public Form2()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
Form1 adat = new Form1(); // Lehet nem kéne újat csinálnom belőle?
string host = adat.host;

if (checkBox1.Checked)
{
MessageBox.Show("Host értéke: " + host); // Itt már az "Alapérték"
}
else if (!checkBox1.Checked)
{
MessageBox.Show("Host értéke: " + host);
}
}
}
}

Azt értem hogy ott vesztem el az értéket amikor new-val újat hozok létre, de akkor hogy kell átadni a régi meglévő object-et a másiknak? Vagyis ezt hogy tudom megoldani?

Köszi a türelmet üdv :)