Builder.cz - Informacni server o programovani

Odběr fotomagazínu

Fotografický magazín "iZIN IDIF" každý týden ve Vašem e-mailu.
Co nového ve světě fotografie!

 

Zadejte Vaši e-mailovou adresu:

Kamarád fotí rád?

Přihlas ho k odběru fotomagazínu!

 

Zadejte e-mailovou adresu kamaráda:

Ukládání a načítání z txt.. Více textboxů.

Seznam témat     Nová odpověď

Přihlásit se     Registrace     Zapomenuté heslo

Re: Ukládání a načítání z txt.. Více textboxů.

Autor: tcesky

20:48:45 28.11.2010

[code]
[color=#0000ff]using[/color][color=#000000] System;
[/color][color=#0000ff]using[/color][color=#000000] System.Collections.Generic;
[/color][color=#0000ff]using[/color][color=#000000] System.ComponentModel;
[/color][color=#0000ff]using[/color][color=#000000] System.Data;
[/color][color=#0000ff]using[/color][color=#000000] System.Drawing;
[/color][color=#0000ff]using[/color][color=#000000] System.Linq;
[/color][color=#0000ff]using[/color][color=#000000] System.Text;
[/color][color=#0000ff]using[/color][color=#000000] System.Windows.Forms;
[/color][color=#0000ff]using[/color][color=#000000] System.IO;
[/color][color=#0000ff]using[/color][color=#000000] System.Runtime.Serialization;
[/color][color=#0000ff]using[/color][color=#000000] System.Xml.Serialization;

[/color][color=#0000ff]namespace[/color][color=#000000] Kuba5
{
[/color][color=#808080]///[/color][color=#008000] [/color][color=#808080]

[/color][color=#000000]
[/color][color=#808080]///[/color][color=#008000] Zdravim.. v C# začínám a zkusil jsem program s hodně textboxy. Je jich celkem 24. [/color][color=#000000]
[/color][color=#808080]///[/color][color=#008000] A já pro ně potřebuji ukládání. Což mam a není problém, ovšem Je jich víc, takže potřebuju nějak čtění z řádku. [/color][color=#000000]
[/color][color=#808080]///[/color][color=#008000] No tady je kod:[/color][color=#000000]
[/color][color=#808080]///[/color][color=#008000] [/color][color=#808080]
[/color][color=#000000]
[/color][color=#0000ff]public[/color][color=#000000] [/color][color=#0000ff]partial[/color][color=#000000] [/color][color=#0000ff]class[/color][color=#000000] [/color][color=#2b91af]Form1[/color][color=#000000] : [/color][color=#2b91af]Form[/color][color=#000000]
{
[/color][color=#0000ff]string[/color][color=#000000] file = [/color][color=#a31515]@"r:\tmp\kubula.txt"[/color][color=#000000];
[/color][color=#2b91af]Kubikula[/color][color=#000000] data = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]Kubikula[/color][color=#000000]();
[/color][color=#0000ff]public[/color][color=#000000] Form1()
{
InitializeComponent();

[/color][color=#0000ff]int[/color][color=#000000] top = 10;
[/color][color=#0000ff]for[/color][color=#000000] ([/color][color=#0000ff]var[/color][color=#000000] m = 0; m < 12; m++)
{
[/color][color=#0000ff]var[/color][color=#000000] lbl = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]Label[/color][color=#000000]();
lbl.Left = 10;
lbl.Top = top;
lbl.Parent = [/color][color=#0000ff]this[/color][color=#000000];
lbl.Text = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]DateTime[/color][color=#000000](2010, m + 1, 1).ToString([/color][color=#a31515]"MMMM"[/color][color=#000000]); ;
[/color][color=#0000ff]var[/color][color=#000000] txta = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]TextBox[/color][color=#000000]();
txta.Left = lbl.Right + 10; ;
txta.Top = top;
txta.Parent = [/color][color=#0000ff]this[/color][color=#000000];
[/color][color=#0000ff]var[/color][color=#000000] txtb = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]TextBox[/color][color=#000000]();
txtb.Left = lbl.Right + 200;
txtb.Top = top;
txtb.Parent = [/color][color=#0000ff]this[/color][color=#000000];
top += 24;
data.Add(lbl.Text, txta, txtb);
}
MakeHim([/color][color=#a31515]"Clear"[/color][color=#000000], [/color][color=#0000ff]ref[/color][color=#000000] top).Click += [/color][color=#0000ff]delegate[/color][color=#000000] { data.Clear(); };
MakeHim([/color][color=#a31515]"Read"[/color][color=#000000], [/color][color=#0000ff]ref[/color][color=#000000] top).Click += [/color][color=#0000ff]delegate[/color][color=#000000] { data.Read(file); };
MakeHim([/color][color=#a31515]"Save"[/color][color=#000000], [/color][color=#0000ff]ref[/color][color=#000000] top).Click += [/color][color=#0000ff]delegate[/color][color=#000000] { data.SaveToFile(file); };
}
[/color][color=#2b91af]Button[/color][color=#000000] MakeHim([/color][color=#0000ff]string[/color][color=#000000] text, [/color][color=#0000ff]ref[/color][color=#000000] [/color][color=#0000ff]int[/color][color=#000000] top)
{
[/color][color=#0000ff]var[/color][color=#000000] btn = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]Button[/color][color=#000000]();
btn.Top = top;
btn.Parent = [/color][color=#0000ff]this[/color][color=#000000];
btn.Text = text;
top += 24;
[/color][color=#0000ff]return[/color][color=#000000] btn;
}
}
[[/color][color=#2b91af]Serializable[/color][color=#000000]]
[/color][color=#0000ff]public[/color][color=#000000] [/color][color=#0000ff]class[/color][color=#000000] [/color][color=#2b91af]Kuba[/color][color=#000000]
{
[/color][color=#0000ff]public[/color][color=#000000] [/color][color=#0000ff]string[/color][color=#000000] first { [/color][color=#0000ff]get[/color][color=#000000]; [/color][color=#0000ff]set[/color][color=#000000]; }
[/color][color=#0000ff]public[/color][color=#000000] [/color][color=#0000ff]string[/color][color=#000000] second { [/color][color=#0000ff]get[/color][color=#000000]; [/color][color=#0000ff]set[/color][color=#000000]; }
[/color][color=#0000ff]public[/color][color=#000000] [/color][color=#0000ff]string[/color][color=#000000] name { [/color][color=#0000ff]get[/color][color=#000000]; [/color][color=#0000ff]set[/color][color=#000000]; }
[/color][color=#0000ff]public[/color][color=#000000] Kuba() { }
[/color][color=#0000ff]public[/color][color=#000000] Kuba([/color][color=#0000ff]string[/color][color=#000000] name) { [/color][color=#0000ff]this[/color][color=#000000].name = name; }
}
[[/color][color=#2b91af]Serializable[/color][color=#000000]]
[/color][color=#0000ff]public[/color][color=#000000] [/color][color=#0000ff]class[/color][color=#000000] [/color][color=#2b91af]Kubikula[/color][color=#000000]
{
[[/color][color=#2b91af]NonSerialized[/color][color=#000000]]
[/color][color=#2b91af]Dictionary[/color][color=#000000]<[/color][color=#0000ff]string[/color][color=#000000], [/color][color=#2b91af]TextBox[/color][color=#000000]> first;
[[/color][color=#2b91af]NonSerialized[/color][color=#000000]]
[/color][color=#2b91af]Dictionary[/color][color=#000000]<[/color][color=#0000ff]string[/color][color=#000000], [/color][color=#2b91af]TextBox[/color][color=#000000]> second;
[/color][color=#0000ff]public[/color][color=#000000] [/color][color=#2b91af]List[/color][color=#000000]<[/color][color=#2b91af]Kuba[/color][color=#000000]> data { [/color][color=#0000ff]get[/color][color=#000000]; [/color][color=#0000ff]set[/color][color=#000000]; }
[/color][color=#0000ff]public[/color][color=#000000] Kubikula() { data = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]List[/color][color=#000000]<[/color][color=#2b91af]Kuba[/color][color=#000000]>(); first = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]Dictionary[/color][color=#000000]<[/color][color=#0000ff]string[/color][color=#000000], [/color][color=#2b91af]TextBox[/color][color=#000000]>(); second = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]Dictionary[/color][color=#000000]<[/color][color=#0000ff]string[/color][color=#000000], [/color][color=#2b91af]TextBox[/color][color=#000000]>(); }
[/color][color=#0000ff]public[/color][color=#000000] [/color][color=#0000ff]void[/color][color=#000000] Add([/color][color=#0000ff]string[/color][color=#000000] name, [/color][color=#2b91af]TextBox[/color][color=#000000] f, [/color][color=#2b91af]TextBox[/color][color=#000000] s) { data.Add([/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]Kuba[/color][color=#000000](name)); first.Add(name, f); second.Add(name, s); }
[/color][color=#0000ff]public[/color][color=#000000] [/color][color=#0000ff]void[/color][color=#000000] Clear() { [/color][color=#0000ff]foreach[/color][color=#000000] ([/color][color=#0000ff]var[/color][color=#000000] t [/color][color=#0000ff]in[/color][color=#000000] first.Values)t.Text = [/color][color=#a31515]""[/color][color=#000000]; [/color][color=#0000ff]foreach[/color][color=#000000] ([/color][color=#0000ff]var[/color][color=#000000] t [/color][color=#0000ff]in[/color][color=#000000] second.Values)t.Text = [/color][color=#a31515]""[/color][color=#000000];}
[/color][color=#0000ff]public[/color][color=#000000] [/color][color=#0000ff]void[/color][color=#000000] Read([/color][color=#0000ff]string[/color][color=#000000] file)
{
[/color][color=#0000ff]var[/color][color=#000000] xml = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]XmlSerializer[/color][color=#000000]([/color][color=#0000ff]typeof[/color][color=#000000]([/color][color=#2b91af]Kubikula[/color][color=#000000]));
[/color][color=#2b91af]Kubikula[/color][color=#000000] d;
[/color][color=#0000ff]using[/color][color=#000000] ([/color][color=#0000ff]var[/color][color=#000000] fs = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]FileStream[/color][color=#000000](file, [/color][color=#2b91af]FileMode[/color][color=#000000].Open))
d = xml.Deserialize(fs) [/color][color=#0000ff]as[/color][color=#000000] [/color][color=#2b91af]Kubikula[/color][color=#000000];
[/color][color=#0000ff]foreach[/color][color=#000000] ([/color][color=#0000ff]var[/color][color=#000000] k [/color][color=#0000ff]in[/color][color=#000000] d.data) { first[[/color][color=#000000]k.name].Text = k.first; second[[/color][color=#000000]k.name].Text = k.second; }
}
[/color][color=#0000ff]public[/color][color=#000000] [/color][color=#0000ff]void[/color][color=#000000] SaveToFile([/color][color=#0000ff]string[/color][color=#000000] file)
{
[/color][color=#0000ff]foreach[/color][color=#000000] ([/color][color=#0000ff]var[/color][color=#000000] k [/color][color=#0000ff]in[/color][color=#000000] data) { k.first = first[[/color][color=#000000]k.name].Text; k.second = second[[/color][color=#000000]k.name].Text; }
[/color][color=#0000ff]var[/color][color=#000000] xml = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]XmlSerializer[/color][color=#000000]([/color][color=#0000ff]typeof[/color][color=#000000]([/color][color=#2b91af]Kubikula[/color][color=#000000]));
[/color][color=#0000ff]using[/color][color=#000000] ([/color][color=#0000ff]var[/color][color=#000000] fs = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]FileStream[/color][color=#000000](file, [/color][color=#2b91af]FileMode[/color][color=#000000].Create))
xml.Serialize(fs, [/color][color=#0000ff]this[/color][color=#000000]);
}
}
}

[/color][/code]
[size=10px]Designed for "uvadeni kodu bez jakehokoliv vysvetleni, ktere mozna pomuze v dany okamzik, ale nic nevyresi do budoucna a takovy clovek se stejne nestane vyvojarem a na slozitejsi otazky uz nedojde"[/size]
Zdravím

[color=#808080]
Nejezte žlutý sníh
________________________________________________
Dobře se pobavíte a od srdce zasmějete na stránkách
http://www.4itdevelopers.net/faq_at_builder.aspx

[/color]

[/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] Zdravim.. v C# začínám a zkusil jsem program s hodně textboxy. Je jich celkem 24. [/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] A já pro ně potřebuji ukládání. Což mam a není problém, ovšem Je jich víc, takže potřebuju nějak čtění z řádku. [/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] No tady je kod:[/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] [/color][color=#808080][/color][color=#000000] [/color][color=#0000ff]public[/color][color=#000000] [/color][color=#0000ff]partial[/color][color=#000000] [/color][color=#0000ff]class[/color][color=#000000] [/color][color=#2b91af]Form1[/color][color=#000000] : [/color][color=#2b91af]Form[/color][color=#000000] { [/color][color=#0000ff]string[/color][color=#000000] file = [/color][color=#a31515]@"r:\tmp\kubula.txt"[/color][color=#000000]; [/color][color=#2b91af]Kubikula[/color][color=#000000] data = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]Kubikula[/color][color=#000000](); [/color][color=#0000ff]public[/color][color=#000000] Form1() { InitializeComponent(); [/color][color=#0000ff]int[/color][color=#000000] top = 10; [/color][color=#0000ff]for[/color][color=#000000] ([/color][color=#0000ff]var[/color][color=#000000] m = 0; m < 12; m++) { [/color][color=#0000ff]var[/color][color=#000000] lbl = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]Label[/color][color=#000000](); lbl.Left = 10; lbl.Top = top; lbl.Parent = [/color][color=#0000ff]this[/color][color=#000000]; lbl.Text = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]DateTime[/color][color=#000000](2010, m + 1, 1).ToString([/color][color=#a31515]"MMMM"[/color][color=#000000]); ; [/color][color=#0000ff]var[/color][color=#000000] txta = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]TextBox[/color][color=#000000](); txta.Left = lbl.Right + 10; ; txta.Top = top; txta.Parent = [/color][color=#0000ff]this[/color][color=#000000]; [/color][color=#0000ff]var[/color][color=#000000] txtb = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]TextBox[/color][color=#000000](); txtb.Left = lbl.Right + 200; txtb.Top = top; txtb.Parent = [/color][color=#0000ff]this[/color][color=#000000]; top += 24; data.Add(lbl.Text, txta, txtb); } MakeHim([/color][color=#a31515]"Clear"[/color][color=#000000], [/color][color=#0000ff]ref[/color][color=#000000] top).Click += [/color][color=#0000ff]delegate[/color][color=#000000] { data.Clear(); }; MakeHim([/color][color=#a31515]"Read"[/color][color=#000000], [/color][color=#0000ff]ref[/color][color=#000000] top).Click += [/color][color=#0000ff]delegate[/color][color=#000000] { data.Read(file); }; MakeHim([/color][color=#a31515]"Save"[/color][color=#000000], [/color][color=#0000ff]ref[/color][color=#000000] top).Click += [/color][color=#0000ff]delegate[/color][color=#000000] { data.SaveToFile(file); }; } [/color][color=#2b91af]Button[/color][color=#000000] MakeHim([/color][color=#0000ff]string[/color][color=#000000] text, [/color][color=#0000ff]ref[/color][color=#000000] [/color][color=#0000ff]int[/color][color=#000000] top) { [/color][color=#0000ff]var[/color][color=#000000] btn = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]Button[/color][color=#000000](); btn.Top = top; btn.Parent = [/color][color=#0000ff]this[/color][color=#000000]; btn.Text = text; top += 24; [/color][color=#0000ff]return[/color][color=#000000] btn; } } [[/color][color=#2b91af]Serializable[/color][color=#000000]] [/color][color=#0000ff]public[/color][color=#000000] [/color][color=#0000ff]class[/color][color=#000000] [/color][color=#2b91af]Kuba[/color][color=#000000] { [/color][color=#0000ff]public[/color][color=#000000] [/color][color=#0000ff]string[/color][color=#000000] first { [/color][color=#0000ff]get[/color][color=#000000]; [/color][color=#0000ff]set[/color][color=#000000]; } [/color][color=#0000ff]public[/color][color=#000000] [/color][color=#0000ff]string[/color][color=#000000] second { [/color][color=#0000ff]get[/color][color=#000000]; [/color][color=#0000ff]set[/color][color=#000000]; } [/color][color=#0000ff]public[/color][color=#000000] [/color][color=#0000ff]string[/color][color=#000000] name { [/color][color=#0000ff]get[/color][color=#000000]; [/color][color=#0000ff]set[/color][color=#000000]; } [/color][color=#0000ff]public[/color][color=#000000] Kuba() { } [/color][color=#0000ff]public[/color][color=#000000] Kuba([/color][color=#0000ff]string[/color][color=#000000] name) { [/color][color=#0000ff]this[/color][color=#000000].name = name; } } [[/color][color=#2b91af]Serializable[/color][color=#000000]] [/color][color=#0000ff]public[/color][color=#000000] [/color][color=#0000ff]class[/color][color=#000000] [/color][color=#2b91af]Kubikula[/color][color=#000000] { [[/color][color=#2b91af]NonSerialized[/color][color=#000000]] [/color][color=#2b91af]Dictionary[/color][color=#000000]<[/color][color=#0000ff]string[/color][color=#000000], [/color][color=#2b91af]TextBox[/color][color=#000000]> first; [[/color][color=#2b91af]NonSerialized[/color][color=#000000]] [/color][color=#2b91af]Dictionary[/color][color=#000000]<[/color][color=#0000ff]string[/color][color=#000000], [/color][color=#2b91af]TextBox[/color][color=#000000]> second; [/color][color=#0000ff]public[/color][color=#000000] [/color][color=#2b91af]List[/color][color=#000000]<[/color][color=#2b91af]Kuba[/color][color=#000000]> data { [/color][color=#0000ff]get[/color][color=#000000]; [/color][color=#0000ff]set[/color][color=#000000]; } [/color][color=#0000ff]public[/color][color=#000000] Kubikula() { data = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]List[/color][color=#000000]<[/color][color=#2b91af]Kuba[/color][color=#000000]>(); first = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]Dictionary[/color][color=#000000]<[/color][color=#0000ff]string[/color][color=#000000], [/color][color=#2b91af]TextBox[/color][color=#000000]>(); second = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]Dictionary[/color][color=#000000]<[/color][color=#0000ff]string[/color][color=#000000], [/color][color=#2b91af]TextBox[/color][color=#000000]>(); } [/color][color=#0000ff]public[/color][color=#000000] [/color][color=#0000ff]void[/color][color=#000000] Add([/color][color=#0000ff]string[/color][color=#000000] name, [/color][color=#2b91af]TextBox[/color][color=#000000] f, [/color][color=#2b91af]TextBox[/color][color=#000000] s) { data.Add([/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]Kuba[/color][color=#000000](name)); first.Add(name, f); second.Add(name, s); } [/color][color=#0000ff]public[/color][color=#000000] [/color][color=#0000ff]void[/color][color=#000000] Clear() { [/color][color=#0000ff]foreach[/color][color=#000000] ([/color][color=#0000ff]var[/color][color=#000000] t [/color][color=#0000ff]in[/color][color=#000000] first.Values)t.Text = [/color][color=#a31515]""[/color][color=#000000]; [/color][color=#0000ff]foreach[/color][color=#000000] ([/color][color=#0000ff]var[/color][color=#000000] t [/color][color=#0000ff]in[/color][color=#000000] second.Values)t.Text = [/color][color=#a31515]""[/color][color=#000000];} [/color][color=#0000ff]public[/color][color=#000000] [/color][color=#0000ff]void[/color][color=#000000] Read([/color][color=#0000ff]string[/color][color=#000000] file) { [/color][color=#0000ff]var[/color][color=#000000] xml = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]XmlSerializer[/color][color=#000000]([/color][color=#0000ff]typeof[/color][color=#000000]([/color][color=#2b91af]Kubikula[/color][color=#000000])); [/color][color=#2b91af]Kubikula[/color][color=#000000] d; [/color][color=#0000ff]using[/color][color=#000000] ([/color][color=#0000ff]var[/color][color=#000000] fs = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]FileStream[/color][color=#000000](file, [/color][color=#2b91af]FileMode[/color][color=#000000].Open)) d = xml.Deserialize(fs) [/color][color=#0000ff]as[/color][color=#000000] [/color][color=#2b91af]Kubikula[/color][color=#000000]; [/color][color=#0000ff]foreach[/color][color=#000000] ([/color][color=#0000ff]var[/color][color=#000000] k [/color][color=#0000ff]in[/color][color=#000000] d.data) { first[[/color][color=#000000]k.name].Text = k.first; second[[/color][color=#000000]k.name].Text = k.second; } } [/color][color=#0000ff]public[/color][color=#000000] [/color][color=#0000ff]void[/color][color=#000000] SaveToFile([/color][color=#0000ff]string[/color][color=#000000] file) { [/color][color=#0000ff]foreach[/color][color=#000000] ([/color][color=#0000ff]var[/color][color=#000000] k [/color][color=#0000ff]in[/color][color=#000000] data) { k.first = first[[/color][color=#000000]k.name].Text; k.second = second[[/color][color=#000000]k.name].Text; } [/color][color=#0000ff]var[/color][color=#000000] xml = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]XmlSerializer[/color][color=#000000]([/color][color=#0000ff]typeof[/color][color=#000000]([/color][color=#2b91af]Kubikula[/color][color=#000000])); [/color][color=#0000ff]using[/color][color=#000000] ([/color][color=#0000ff]var[/color][color=#000000] fs = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]FileStream[/color][color=#000000](file, [/color][color=#2b91af]FileMode[/color][color=#000000].Create)) xml.Serialize(fs, [/color][color=#0000ff]this[/color][color=#000000]); } } } [/color][/code] [size=10px]Designed for "uvadeni kodu bez jakehokoliv vysvetleni, ktere mozna pomuze v dany okamzik, ale nic nevyresi do budoucna a takovy clovek se stejne nestane vyvojarem a na slozitejsi otazky uz nedojde"[/size] Zdravím TČ [color=#808080] Nejezte žlutý sníh ________________________________________________ Dobře se pobavíte a od srdce zasmějete na stránkách http://www.4itdevelopers.net/faq_at_builder.aspx [/color]

Citovat příspěvek

 

Re: Ukládání a načítání z txt.. Více textboxů.

Autor: tcesky

18:11:46 28.11.2010

[code]
[color=#0000ff]using[/color][color=#000000] System;
[/color][color=#0000ff]using[/color][color=#000000] System.Collections.Generic;
[/color][color=#0000ff]using[/color][color=#000000] System.ComponentModel;
[/color][color=#0000ff]using[/color][color=#000000] System.Data;
[/color][color=#0000ff]using[/color][color=#000000] System.Drawing;
[/color][color=#0000ff]using[/color][color=#000000] System.Linq;
[/color][color=#0000ff]using[/color][color=#000000] System.Text;
[/color][color=#0000ff]using[/color][color=#000000] System.Windows.Forms;
[/color][color=#0000ff]using[/color][color=#000000] System.IO;

[/color][color=#0000ff]namespace[/color][color=#000000] Kuba5
{
[/color][color=#808080]///[/color][color=#008000] [/color][color=#808080]

[/color][color=#000000]
[/color][color=#808080]///[/color][color=#008000] Zdravim.. v C# začínám a zkusil jsem program s hodně textboxy. Je jich celkem 24. [/color][color=#000000]
[/color][color=#808080]///[/color][color=#008000] A já pro ně potřebuji ukládání. Což mam a není problém, ovšem Je jich víc, takže potřebuju nějak čtění z řádku. [/color][color=#000000]
[/color][color=#808080]///[/color][color=#008000] No tady je kod:[/color][color=#000000]
[/color][color=#808080]///[/color][color=#008000] [/color][color=#808080]
[/color][color=#000000]
[/color][color=#0000ff]public[/color][color=#000000] [/color][color=#0000ff]partial[/color][color=#000000] [/color][color=#0000ff]class[/color][color=#000000] [/color][color=#2b91af]Form1[/color][color=#000000] : [/color][color=#2b91af]Form[/color][color=#000000]
{
[/color][color=#0000ff]string[/color][color=#000000] file = [/color][color=#a31515]@"r:\tmp\kubula.txt"[/color][color=#000000];

[/color][color=#0000ff]public[/color][color=#000000] Form1()
{
InitializeComponent();

[/color][color=#0000ff]int[/color][color=#000000] top = 10;
[/color][color=#0000ff]for[/color][color=#000000] ([/color][color=#0000ff]var[/color][color=#000000] m = 0; m < 12; m++)
{
[/color][color=#0000ff]var[/color][color=#000000] lbl = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]Label[/color][color=#000000]();
lbl.Left = 10;
lbl.Top = top;
lbl.Parent = [/color][color=#0000ff]this[/color][color=#000000];
lbl.Text = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]DateTime[/color][color=#000000](2010, m + 1, 1).ToString([/color][color=#a31515]"MMMM"[/color][color=#000000]); ;
[/color][color=#0000ff]var[/color][color=#000000] txt = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]TextBox[/color][color=#000000]();
txt.Left = lbl.Right + 10; ;
txt.Top = top;
txt.Parent = [/color][color=#0000ff]this[/color][color=#000000];
txt = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]TextBox[/color][color=#000000]();
txt.Left = lbl.Right + 200;
txt.Top = top;
txt.Parent = [/color][color=#0000ff]this[/color][color=#000000];
top += 24;
}
[/color][color=#0000ff]var[/color][color=#000000] btn = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]Button[/color][color=#000000]();
btn.Top = top;
btn.Parent = [/color][color=#0000ff]this[/color][color=#000000];
btn.Text = [/color][color=#a31515]"Clear"[/color][color=#000000];
top += 24;
btn.Click += [/color][color=#0000ff]delegate[/color][color=#000000] { [/color][color=#0000ff]foreach[/color][color=#000000] ([/color][color=#0000ff]var[/color][color=#000000] c [/color][color=#0000ff]in[/color][color=#000000] Controls)[/color][color=#0000ff]if[/color][color=#000000] (c [/color][color=#0000ff]is[/color][color=#000000] [/color][color=#2b91af]TextBox[/color][color=#000000])(c [/color][color=#0000ff]as[/color][color=#000000] [/color][color=#2b91af]TextBox[/color][color=#000000]).Text = [/color][color=#a31515]""[/color][color=#000000]; };
btn = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]Button[/color][color=#000000]();
btn.Top = top;
btn.Parent = [/color][color=#0000ff]this[/color][color=#000000];
btn.Text = [/color][color=#a31515]"Save"[/color][color=#000000];
top += 24;
btn.Click += [/color][color=#0000ff]delegate[/color][color=#000000]
{
[/color][color=#0000ff]using[/color][color=#000000] ([/color][color=#0000ff]var[/color][color=#000000] sw = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]StreamWriter[/color][color=#000000](file))
[/color][color=#0000ff]foreach[/color][color=#000000] ([/color][color=#0000ff]var[/color][color=#000000] c [/color][color=#0000ff]in[/color][color=#000000] Controls) [/color][color=#0000ff]if[/color][color=#000000] (c [/color][color=#0000ff]is[/color][color=#000000] [/color][color=#2b91af]TextBox[/color][color=#000000]) sw.WriteLine((c [/color][color=#0000ff]as[/color][color=#000000] [/color][color=#2b91af]TextBox[/color][color=#000000]).Text);
};
btn = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]Button[/color][color=#000000]();
btn.Top = top;
btn.Parent = [/color][color=#0000ff]this[/color][color=#000000];
btn.Text = [/color][color=#a31515]"Read"[/color][color=#000000];
top += 24;
btn.Click += [/color][color=#0000ff]delegate[/color][color=#000000]
{
[/color][color=#0000ff]using[/color][color=#000000] ([/color][color=#0000ff]var[/color][color=#000000] sr = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]StreamReader[/color][color=#000000](file))
[/color][color=#0000ff]foreach[/color][color=#000000] ([/color][color=#0000ff]var[/color][color=#000000] c [/color][color=#0000ff]in[/color][color=#000000] Controls) [/color][color=#0000ff]if[/color][color=#000000] (c [/color][color=#0000ff]is[/color][color=#000000] [/color][color=#2b91af]TextBox[/color][color=#000000]) (c [/color][color=#0000ff]as[/color][color=#000000] [/color][color=#2b91af]TextBox[/color][color=#000000]).Text=sr.ReadLine();
};
}
}
}

[/color][/code]
[size=10px]Designed for "uvadeni kodu bez jakehokoliv vysvetleni, ktere mozna pomuze v dany okamzik, ale nic nevyresi do budoucna a takovy clovek se stejne nestane vyvojarem a na slozitejsi otazky uz nedojde"[/size]
Zdravím

[color=#808080]
Nejezte žlutý sníh
________________________________________________
Dobře se pobavíte a od srdce zasmějete na stránkách
http://www.4itdevelopers.net/faq_at_builder.aspx

[/color]

[/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] Zdravim.. v C# začínám a zkusil jsem program s hodně textboxy. Je jich celkem 24. [/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] A já pro ně potřebuji ukládání. Což mam a není problém, ovšem Je jich víc, takže potřebuju nějak čtění z řádku. [/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] No tady je kod:[/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] [/color][color=#808080][/color][color=#000000] [/color][color=#0000ff]public[/color][color=#000000] [/color][color=#0000ff]partial[/color][color=#000000] [/color][color=#0000ff]class[/color][color=#000000] [/color][color=#2b91af]Form1[/color][color=#000000] : [/color][color=#2b91af]Form[/color][color=#000000] { [/color][color=#0000ff]string[/color][color=#000000] file = [/color][color=#a31515]@"r:\tmp\kubula.txt"[/color][color=#000000]; [/color][color=#0000ff]public[/color][color=#000000] Form1() { InitializeComponent(); [/color][color=#0000ff]int[/color][color=#000000] top = 10; [/color][color=#0000ff]for[/color][color=#000000] ([/color][color=#0000ff]var[/color][color=#000000] m = 0; m < 12; m++) { [/color][color=#0000ff]var[/color][color=#000000] lbl = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]Label[/color][color=#000000](); lbl.Left = 10; lbl.Top = top; lbl.Parent = [/color][color=#0000ff]this[/color][color=#000000]; lbl.Text = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]DateTime[/color][color=#000000](2010, m + 1, 1).ToString([/color][color=#a31515]"MMMM"[/color][color=#000000]); ; [/color][color=#0000ff]var[/color][color=#000000] txt = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]TextBox[/color][color=#000000](); txt.Left = lbl.Right + 10; ; txt.Top = top; txt.Parent = [/color][color=#0000ff]this[/color][color=#000000]; txt = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]TextBox[/color][color=#000000](); txt.Left = lbl.Right + 200; txt.Top = top; txt.Parent = [/color][color=#0000ff]this[/color][color=#000000]; top += 24; } [/color][color=#0000ff]var[/color][color=#000000] btn = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]Button[/color][color=#000000](); btn.Top = top; btn.Parent = [/color][color=#0000ff]this[/color][color=#000000]; btn.Text = [/color][color=#a31515]"Clear"[/color][color=#000000]; top += 24; btn.Click += [/color][color=#0000ff]delegate[/color][color=#000000] { [/color][color=#0000ff]foreach[/color][color=#000000] ([/color][color=#0000ff]var[/color][color=#000000] c [/color][color=#0000ff]in[/color][color=#000000] Controls)[/color][color=#0000ff]if[/color][color=#000000] (c [/color][color=#0000ff]is[/color][color=#000000] [/color][color=#2b91af]TextBox[/color][color=#000000])(c [/color][color=#0000ff]as[/color][color=#000000] [/color][color=#2b91af]TextBox[/color][color=#000000]).Text = [/color][color=#a31515]""[/color][color=#000000]; }; btn = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]Button[/color][color=#000000](); btn.Top = top; btn.Parent = [/color][color=#0000ff]this[/color][color=#000000]; btn.Text = [/color][color=#a31515]"Save"[/color][color=#000000]; top += 24; btn.Click += [/color][color=#0000ff]delegate[/color][color=#000000] { [/color][color=#0000ff]using[/color][color=#000000] ([/color][color=#0000ff]var[/color][color=#000000] sw = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]StreamWriter[/color][color=#000000](file)) [/color][color=#0000ff]foreach[/color][color=#000000] ([/color][color=#0000ff]var[/color][color=#000000] c [/color][color=#0000ff]in[/color][color=#000000] Controls) [/color][color=#0000ff]if[/color][color=#000000] (c [/color][color=#0000ff]is[/color][color=#000000] [/color][color=#2b91af]TextBox[/color][color=#000000]) sw.WriteLine((c [/color][color=#0000ff]as[/color][color=#000000] [/color][color=#2b91af]TextBox[/color][color=#000000]).Text); }; btn = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]Button[/color][color=#000000](); btn.Top = top; btn.Parent = [/color][color=#0000ff]this[/color][color=#000000]; btn.Text = [/color][color=#a31515]"Read"[/color][color=#000000]; top += 24; btn.Click += [/color][color=#0000ff]delegate[/color][color=#000000] { [/color][color=#0000ff]using[/color][color=#000000] ([/color][color=#0000ff]var[/color][color=#000000] sr = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]StreamReader[/color][color=#000000](file)) [/color][color=#0000ff]foreach[/color][color=#000000] ([/color][color=#0000ff]var[/color][color=#000000] c [/color][color=#0000ff]in[/color][color=#000000] Controls) [/color][color=#0000ff]if[/color][color=#000000] (c [/color][color=#0000ff]is[/color][color=#000000] [/color][color=#2b91af]TextBox[/color][color=#000000]) (c [/color][color=#0000ff]as[/color][color=#000000] [/color][color=#2b91af]TextBox[/color][color=#000000]).Text=sr.ReadLine(); }; } } } [/color][/code] [size=10px]Designed for "uvadeni kodu bez jakehokoliv vysvetleni, ktere mozna pomuze v dany okamzik, ale nic nevyresi do budoucna a takovy clovek se stejne nestane vyvojarem a na slozitejsi otazky uz nedojde"[/size] Zdravím TČ [color=#808080] Nejezte žlutý sníh ________________________________________________ Dobře se pobavíte a od srdce zasmějete na stránkách http://www.4itdevelopers.net/faq_at_builder.aspx [/color]

Citovat příspěvek

 

Re: Ukládání a načítání z txt.. Více textboxů.

Autor: Kuba5

17:37:10 28.11.2010

No mě se zbláznil počítač, takže to musím dělat znova, ale nevadí. Tak já ti radši ukážu screen jak to mam: http://www1.picturepush.com/photo/a/4600669/img/Anonymous/takto.jpg
Jinak řeč o buttonu sice nebyla, ale v kodu je:
private void ulozit_Click(object sender, EventArgs e)
...

Citovat příspěvek

 

Re: Ukládání a načítání z txt.. Více textboxů.

Autor: tcesky

17:19:05 28.11.2010

[ital]a uložení do buttonu.[/ital]

O nejakem buttonu zatim nebyla zadna rec.

Navrhoval bych aby jsi zkusil formulovat dotaz tak, ze bude srozumitelny. Pak by se videlo dal.

Zdravim

TC

Citovat příspěvek

 

Re: Ukládání a načítání z txt.. Více textboxů.

Autor: Kuba5

17:07:56 28.11.2010

No děkuju, ale použít to nejde.. já už textboxy mám.. i názvy měsícu.. já prostě potřebuju jen čistě kod na to ukázání.. a uložení do buttonu. To taky mam, asi i správně, takže já bych řešil jen to ukázání.. aby to prostě bralo po jednom řádku. No ještě se to z toho nějak pokusim udělat..

Citovat příspěvek

 

Re: Ukládání a načítání z txt.. Více textboxů.

Autor: tcesky

16:52:17 28.11.2010

[code]
[color=#0000ff]using[/color][color=#000000] System;
[/color][color=#0000ff]using[/color][color=#000000] System.Collections.Generic;
[/color][color=#0000ff]using[/color][color=#000000] System.ComponentModel;
[/color][color=#0000ff]using[/color][color=#000000] System.Data;
[/color][color=#0000ff]using[/color][color=#000000] System.Drawing;
[/color][color=#0000ff]using[/color][color=#000000] System.Linq;
[/color][color=#0000ff]using[/color][color=#000000] System.Text;
[/color][color=#0000ff]using[/color][color=#000000] System.Windows.Forms;
[/color][color=#0000ff]using[/color][color=#000000] System.IO;

[/color][color=#0000ff]namespace[/color][color=#000000] Kuba5
{
[/color][color=#808080]///[/color][color=#008000] [/color][color=#808080]

[/color][color=#000000]
[/color][color=#808080]///[/color][color=#008000] Zdravim.. v C# začínám a zkusil jsem program s hodně textboxy. Je jich celkem 24. A já pro ně potřebuji ukládání. Což mam a není problém, ovšem Je jich víc, takže potřebuju nějak čtění z řádku. No tady je kod:[/color][color=#000000]
[/color][color=#808080]///[/color][color=#008000] [/color][color=#808080]
[/color][color=#000000]
[/color][color=#0000ff]public[/color][color=#000000] [/color][color=#0000ff]partial[/color][color=#000000] [/color][color=#0000ff]class[/color][color=#000000] [/color][color=#2b91af]Form1[/color][color=#000000] : [/color][color=#2b91af]Form[/color][color=#000000]
{
[/color][color=#0000ff]string[/color][color=#000000] file = [/color][color=#a31515]@"r:\tmp\kubula.txt"[/color][color=#000000];
[/color][color=#0000ff]string[/color][color=#000000] kubikula = [/color][color=#a31515]@"leden:hovno[/color][color=#000000]
[/color][color=#a31515]unor:porad hovno[/color][color=#000000]
[/color][color=#a31515]bresen:porad hovno[/color][color=#000000]
[/color][color=#a31515]duben:porad hovno[/color][color=#000000]
[/color][color=#a31515]kveten:porad hovno[/color][color=#000000]
[/color][color=#a31515]cerven:porad hovno[/color][color=#000000]
[/color][color=#a31515]cervenec:porad hovno[/color][color=#000000]
[/color][color=#a31515]srpen:porad hovno[/color][color=#000000]
[/color][color=#a31515]zari:porad hovno[/color][color=#000000]
[/color][color=#a31515]rijen:porad hovno[/color][color=#000000]
[/color][color=#a31515]listopad:porad hovno[/color][color=#000000]
[/color][color=#a31515]mesic pratelstvi:Na to jsme cekali[/color][color=#000000]
[/color][color=#a31515]prosinec:zase hovno"[/color][color=#000000];
[/color][color=#0000ff]public[/color][color=#000000] Form1()
{
InitializeComponent();
[/color][color=#0000ff]using[/color][color=#000000] ([/color][color=#0000ff]var[/color][color=#000000] sw = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]StreamWriter[/color][color=#000000](file)) sw.Write(kubikula);

[/color][color=#0000ff]int[/color][color=#000000] top=10;
[/color][color=#0000ff]using[/color][color=#000000]([/color][color=#0000ff]var[/color][color=#000000] sr=[/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]StreamReader[/color][color=#000000](file))
[/color][color=#0000ff]for[/color][color=#000000] ([/color][color=#0000ff]string[/color][color=#000000] line; [/color][color=#0000ff]null[/color][color=#000000] != (line = sr.ReadLine()); )
{
[/color][color=#0000ff]var[/color][color=#000000] str = line.Split([/color][color=#a31515]':'[/color][color=#000000]);
[/color][color=#0000ff]if[/color][color=#000000] (str.Length == 2)
{
[/color][color=#0000ff]var[/color][color=#000000] lbl = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]Label[/color][color=#000000]();
lbl.Left = 10;
lbl.Top = top;
lbl.Parent = [/color][color=#0000ff]this[/color][color=#000000];
lbl.Text = str[[/color][color=#000000]0];
[/color][color=#0000ff]var[/color][color=#000000] txt = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]TextBox[/color][color=#000000]();
txt.Left = lbl.Right + 10; ;
txt.Top = top;
txt.Parent = [/color][color=#0000ff]this[/color][color=#000000];
txt.Text = str[[/color][color=#000000]1];
top += 24;
}
}
}
}
}

[/color][/code]
[size=10px]Designed for "uvadeni kodu bez jakehokoliv vysvetleni, ktere mozna pomuze v dany okamzik, ale nic nevyresi do budoucna a takovy clovek se stejne nestane vyvojarem a na slozitejsi otazky uz nedojde"[/size]
Zdravím

[color=#808080]
Nejezte žlutý sníh
________________________________________________
Dobře se pobavíte a od srdce zasmějete na stránkách
http://www.4itdevelopers.net/faq_at_builder.aspx

[/color]

[/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] Zdravim.. v C# začínám a zkusil jsem program s hodně textboxy. Je jich celkem 24. A já pro ně potřebuji ukládání. Což mam a není problém, ovšem Je jich víc, takže potřebuju nějak čtění z řádku. No tady je kod:[/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] [/color][color=#808080][/color][color=#000000] [/color][color=#0000ff]public[/color][color=#000000] [/color][color=#0000ff]partial[/color][color=#000000] [/color][color=#0000ff]class[/color][color=#000000] [/color][color=#2b91af]Form1[/color][color=#000000] : [/color][color=#2b91af]Form[/color][color=#000000] { [/color][color=#0000ff]string[/color][color=#000000] file = [/color][color=#a31515]@"r:\tmp\kubula.txt"[/color][color=#000000]; [/color][color=#0000ff]string[/color][color=#000000] kubikula = [/color][color=#a31515]@"leden:hovno[/color][color=#000000] [/color][color=#a31515]unor:porad hovno[/color][color=#000000] [/color][color=#a31515]bresen:porad hovno[/color][color=#000000] [/color][color=#a31515]duben:porad hovno[/color][color=#000000] [/color][color=#a31515]kveten:porad hovno[/color][color=#000000] [/color][color=#a31515]cerven:porad hovno[/color][color=#000000] [/color][color=#a31515]cervenec:porad hovno[/color][color=#000000] [/color][color=#a31515]srpen:porad hovno[/color][color=#000000] [/color][color=#a31515]zari:porad hovno[/color][color=#000000] [/color][color=#a31515]rijen:porad hovno[/color][color=#000000] [/color][color=#a31515]listopad:porad hovno[/color][color=#000000] [/color][color=#a31515]mesic pratelstvi:Na to jsme cekali[/color][color=#000000] [/color][color=#a31515]prosinec:zase hovno"[/color][color=#000000]; [/color][color=#0000ff]public[/color][color=#000000] Form1() { InitializeComponent(); [/color][color=#0000ff]using[/color][color=#000000] ([/color][color=#0000ff]var[/color][color=#000000] sw = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]StreamWriter[/color][color=#000000](file)) sw.Write(kubikula); [/color][color=#0000ff]int[/color][color=#000000] top=10; [/color][color=#0000ff]using[/color][color=#000000]([/color][color=#0000ff]var[/color][color=#000000] sr=[/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]StreamReader[/color][color=#000000](file)) [/color][color=#0000ff]for[/color][color=#000000] ([/color][color=#0000ff]string[/color][color=#000000] line; [/color][color=#0000ff]null[/color][color=#000000] != (line = sr.ReadLine()); ) { [/color][color=#0000ff]var[/color][color=#000000] str = line.Split([/color][color=#a31515]':'[/color][color=#000000]); [/color][color=#0000ff]if[/color][color=#000000] (str.Length == 2) { [/color][color=#0000ff]var[/color][color=#000000] lbl = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]Label[/color][color=#000000](); lbl.Left = 10; lbl.Top = top; lbl.Parent = [/color][color=#0000ff]this[/color][color=#000000]; lbl.Text = str[[/color][color=#000000]0]; [/color][color=#0000ff]var[/color][color=#000000] txt = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]TextBox[/color][color=#000000](); txt.Left = lbl.Right + 10; ; txt.Top = top; txt.Parent = [/color][color=#0000ff]this[/color][color=#000000]; txt.Text = str[[/color][color=#000000]1]; top += 24; } } } } } [/color][/code] [size=10px]Designed for "uvadeni kodu bez jakehokoliv vysvetleni, ktere mozna pomuze v dany okamzik, ale nic nevyresi do budoucna a takovy clovek se stejne nestane vyvojarem a na slozitejsi otazky uz nedojde"[/size] Zdravím TČ [color=#808080] Nejezte žlutý sníh ________________________________________________ Dobře se pobavíte a od srdce zasmějete na stránkách http://www.4itdevelopers.net/faq_at_builder.aspx [/color]

Citovat příspěvek

 

Re: Ukládání a načítání z txt.. Více textboxů.

Autor: Kuba5

16:37:35 28.11.2010

Ajo, omlouvam se, prosim at moderatori přesunou do kategorie .Net .. děkuji..

Martin Holy:a kde myslíš? Já nevim co jinýho bych mohl dát třeba do toho ReadLine(co?); apod.

Citovat příspěvek

 

Re: Ukládání a načítání z txt.. Více textboxů.

Autor: Martin Holy

16:27:23 28.11.2010

C/C++ != C#
missing code tags

Citovat příspěvek

 

Ukládání a načítání z txt.. Více textboxů.

Autor: Kuba5

16:03:41 28.11.2010

Zdravim.. v C# začínám a zkusil jsem program s hodně textboxy. Je jich celkem 24. A já pro ně potřebuji ukládání. Což mam a není problém, ovšem Je jich víc, takže potřebuju nějak čtění z řádku. No tady je kod:


private void Form1_Load(object sender, EventArgs e)
{
string cesta = "C:\\Program Files\\Prijmy a vydaje\\ukladani.txt";

FileInfo fi = new FileInfo(cesta);

StreamReader sr = new StreamReader(fi.OpenRead());

while (sr.Peek() > -1)

prijmyleden.Text= sr.ReadLine();
vydajeleden.Text = sr.ReadLine();

sr.Close();
}

private void ulozit_Click(object sender, EventArgs e)
{

string cesta = "C:\\Program Files\\Prijmy a vydaje\\ukladani.txt";

string Obsah = prijmyleden.Text;
string Obsah2 = vydajeleden.Text;

FileInfo fi = new FileInfo(

Path.Combine(Environment.CurrentDirectory, cesta));

// Pokud soubor neexistuje, vytvoříme ho a zapíšeme do něj text:

if (fi.Exists)
{

StreamWriter sw = fi.CreateText();

sw.WriteLine(Obsah);
sw.WriteLine(Obsah2);


sw.Close();

fi.Refresh();

}
}

Číslo z prijmu se normálně uloží na řádek a výdaj zase na nový řádek. To přesně chci. Jenže čtění už je problém. Když mam takto to čtení, tak v příjmu se mi objeví dvojka a ve výdaji nic. (Dvojku jsem zadal pro výdaj a jedničku pro příjem) .. Takže se zobrazí jen Dvojka (výdaj) a ještě k tomu na špatným místě (na příjmu) .. Vim, že někde bude chyba v tom while, ale fakt to moc neovládám. Předem děkuji za pomoc.

Citovat příspěvek

 

 

 

Přihlášení k mému účtu

Uživatelské jméno:

Heslo: