Skip to content

Instantly share code, notes, and snippets.

@Michal-Szczepaniak
Last active October 15, 2015 09:57
Show Gist options
  • Save Michal-Szczepaniak/a177fd6ee04aad7c6551 to your computer and use it in GitHub Desktop.
Save Michal-Szczepaniak/a177fd6ee04aad7c6551 to your computer and use it in GitHub Desktop.
Okienka z plikami
/**
* Bez openFileDialog
*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.IO;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void zapisz_Click(object sender, EventArgs e)
{
StreamWriter writer = new StreamWriter("plik.txt");
writer.Write(richTextBox1.Text);
writer.Flush();
writer.Close();
}
private void otworz_Click(object sender, EventArgs e)
{
StreamReader reader = new StreamReader("plik.txt");
richTextBox1.Text = reader.ReadToEnd();
reader.Close();
}
}
}
/**
* Z openFileDialog
*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.IO;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void zapisz_Click(object sender, EventArgs e)
{
saveFileDialog1.Filter = "Wszystkie pliki|*.*";
saveFileDialog1.FileName = "plik.txt";
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
StreamWriter writer = new StreamWriter(saveFileDialog1.FileName);
writer.Write(richTextBox1.Text);
writer.Close();
}
}
private void otworz_Click(object sender, EventArgs e)
{
openFileDialog1.Filter = "Wszystkie pliki|*.*";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
StreamReader reader = new StreamReader(openFileDialog1.FileName);
richTextBox1.Text = reader.ReadToEnd();
reader.Close();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment