Witam czytałem o przesyłaniu wartości zmiennych między formatkami, lecz coś mi nie idzie. Możecie rzucić okiem na kod i napisać swoje spostrzeżenia, odnośnie problemu? Wartość zmiennej node musi być przesłana do drugiej formatki.
Form1
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;
using System.Collections;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
string node;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form2 form2 = new Form2(); //kontroler
form2.ShowDialog(); //pokazanie nowego okna
//this.Enabled = false; //zablokowanie obecnego
}
private void Form1_Resize(object sender, EventArgs e)
{
list_detale.Width= (this.Width-tree_kategorie.Width); //rozszerzanie okna detali
button1.Width = this.Width;//rozszerzanie przycisku "dodaj/edytuj"
//button1.Top = this.Height-button1.Height;
}
private void tree_kategorie_DoubleClick(object sender, EventArgs e)
{
string[] kategorie = new string[] { "Model","Cena", "Processor", "Ram", "Dysk", "Karta graficzna", "Złącza", "Dodatkowe informacje" };
node = tree_kategorie.SelectedNode.Text + ".dudi";
if (File.Exists(node)) {
string szSrcLine;
//ArrayList szContents = new ArrayList(); coś jak TStringList w delphi
FileStream fsInput = new FileStream(node, FileMode.Open,
FileAccess.Read);
StreamReader srInput = new StreamReader(fsInput);
//list_detale.Columns.Add("Lp.");
for (int i = 0; i < 8; i++)
{
list_detale.Columns.Add(kategorie[i]);
}
int k=0;
while ((szSrcLine = srInput.ReadLine()) != null)
{
//szSrcLine = srInput.ReadLine();
list_detale.Items.Add(szSrcLine);
for (int j = 0; j < 7; j++)
{
szSrcLine = srInput.ReadLine();
list_detale.Items[k].SubItems.Add(szSrcLine);
}
k++;
}
}
}
}
}
Form2
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;
using System.Collections;
namespace WindowsFormsApplication1
{
public partial class Form2 : Form
{
Form1 form1;
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
form1=new Form1();
File.AppendText(form1.node,textBox1.Text);
this.Close(); //ukrycie obecnego okna
}
private void Form2_FormClosed(object sender, FormClosedEventArgs e)
{
/* TJW.
Form1 form1 = new Form1();
form1.Enabled = true;
*/
}
}
}