if (ofd.ShowDialog() == DialogResult.OK)
{
using (StreamReader sr = new StreamReader(ofd.FileName))
{
filePath = ofd.FileName;
Task text = sr.ReadToEndAsync();
richTextBox1.Text = text.Result;
}
}
}
}
private void saveToolStripMenuItem_Click(object sender, EventArgs e)
{
// saqlash
if (string.IsNullOrEmpty(filePath))
{
using (SaveFileDialog sfd = new SaveFileDialog() { Filter = "TextDocument|*.txt", ValidateNames = true })
{
if (sfd.ShowDialog() == DialogResult.OK)
{
using (StreamWriter sw = new StreamWriter(sfd.FileName))
{
sw.WriteLineAsync(richTextBox1.Text);
}
}
}
}
else{
using (StreamWriter sw = new StreamWriter(filePath))
{
sw.WriteLineAsync(richTextBox1.Text);
}
}
}
private void printPreviewToolStripMenuItem_Click(object sender, EventArgs e)
{
printPreviewDialog1.Document = printDocument1;
printPreviewDialog1.ShowDialog();
}
private void printToolStripMenuItem_Click(object sender, EventArgs e)
{
printPreviewDialog1.Document = printDocument1;
if (printDialog1.ShowDialog() == DialogResult.OK)
{
printDocument1.Print();
}
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
//close window
this.Close();
}
private void undoToolStripMenuItem_Click(object sender, EventArgs e)
{
// undan oldingi xolatga qaytarish
richTextBox1.Undo();
}
private void redoToolStripMenuItem_Click(object sender, EventArgs e)
{
// kegingiga o`tish
richTextBox1.Redo();
}
Do'stlaringiz bilan baham: |