witam
mam problem z pobieraniem informacji z okna B, gdy używam okna A
chce zrobic proste wyszukiwanie tekstu
w glownym oknie A laduje tekst z pliku (Formularz dokumentu)
w oknie B wyszukujemy, podajemy parametry (Formularz przeszukiwania)
http://img32.yfrog.com/img32/9477/goale.jpg
problem mam z pobraniem wartosci TextBox1.Text (z okna A) po uruchomieniu okna B
tzn. pobieram wartosc txtboxa po zaladowaniu do niego tekstu - ok
pobieram wartosc txtboxa po zamknieciu okna B - ok
chce pobrac wartosc txtboxa w oknie B - problem
wrzucam kod 2 okienek:
problem w funkcji button1_Click() w Form2.cs
Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace _002_wyszukiwanie_tekstu
{
public partial class Form1 : Form
{
public Form2 szukaj;
public static bool closed = true;
public string szukany;
public Form1()
{
InitializeComponent();
}
//szukaj
private void button1_Click(object sender, EventArgs e)
{
if (closed)
{
closed = false;
szukaj = new Form2();
szukaj.Owner = this;
szukaj.Show();
}
else
szukaj.Activate();
}
public string getText()
{
return textBox1.Text;
}
/*public void wyszukaj(string t)
{
//int first = textBox1.Text.IndexOf(t);
string a = "abcdef";
int first = a.IndexOf("de");
MessageBox.Show(this.textBox1.Text, "la");
}*/
//wczytaj tekst z pliku
private void textBox1_MouseDoubleClick(object sender, MouseEventArgs e)
{
openFileDialog1 = new OpenFileDialog();
openFileDialog1.DefaultExt = "txt";
openFileDialog1.Filter = "Pliki tekstowe (*.txt)|*.txt|Wszystkie pliki (*.*)|*.*";
openFileDialog1.ShowDialog();
string filename = openFileDialog1.FileName.ToString();
//otwieranie pliku
if (File.Exists(filename))
{
FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read);
StreamReader reader = new StreamReader(fs);
textBox1.Text = reader.ReadToEnd();
reader.Close();
}
}
//pomocniczy klawisz
private void button2_Click(object sender, EventArgs e)
{
MessageBox.Show(getText(), "la");
}
}
}
Form2.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace _002_wyszukiwanie_tekstu
{
public partial class Form2 : Form
{
public Form1 glowne;
public Form2()
{
InitializeComponent();
}
//zamknij
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
//znajdź następny
private void button1_Click(object sender, EventArgs e)
{
glowne = new Form1();
glowne.Activate();
MessageBox.Show(glowne.getText(), "la");
//glowne.wyszukaj(textBox1.Text);
}
private void Form2_FormClosed(object sender, FormClosedEventArgs e)
{
Form1.closed = true;
}
}
}
To moj pierwszy program w c#, wiec moze jakis podstawowy blad robie
Z gory dziekować ;]