Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.IO;
- namespace File_Browser
- {
- public partial class TextEditor : Form
- {
- FileStream fileStream;
- Byte[] dataBytes;
- string fileName;
- public TextEditor()
- {
- InitializeComponent();
- }
- public void loadTextEditor(string file)
- {
- fileName = file;
- StreamReader streamReader;
- string line;
- this.Text += " - Editing " + fileName;
- try {
- richTextBox1.Text = "";
- streamReader = new StreamReader(fileName);
- line = streamReader.ReadToEnd();
- richTextBox1.Text = line;
- streamReader.Close();
- } catch (Exception ex) {
- MessageBox.Show("Error Reading File: " + ex.StackTrace);
- this.Close();
- }
- }
- private void SaveButton_Click(object sender, EventArgs e)
- {
- if (richTextBox1.Text.Length > 0)
- {
- try {
- fileStream = new FileStream(fileName, FileMode.OpenOrCreate);
- dataBytes = Encoding.ASCII.GetBytes(richTextBox1.Text);
- fileStream.Write(dataBytes, 0, dataBytes.Length);
- fileStream.Close();
- MessageBox.Show("Successfully Saved");
- } catch (Exception err) {
- MessageBox.Show(err.Message);
- }
- }
- }
- private void AppendButton_Click(object sender, EventArgs e)
- {
- if (richTextBox1.Text.Length > 0)
- {
- try
- {
- fileStream = new FileStream(fileName, FileMode.Append);
- dataBytes = Encoding.ASCII.GetBytes(richTextBox1.Text);
- fileStream.Write(dataBytes, 0, dataBytes.Length);
- fileStream.Close();
- MessageBox.Show("Successfully Appended");
- }
- catch (Exception err)
- {
- MessageBox.Show(err.Message);
- }
- }
- }
- private void SplitButton_Click(object sender, EventArgs e)
- {
- string text;
- string[] words;
- if (richTextBox1.Text.Length > 0)
- {
- string split = Microsoft.VisualBasic.Interaction.InputBox("Iveskite simbolį pagal kurį išskirti");
- text = richTextBox1.Text;
- words = text.Split(split[0]);
- richTextBox1.Text = "";
- foreach (string item in words)
- {
- richTextBox1.Text += (item + Environment.NewLine);
- }
- }
- }
- private void SubstringButton_Click(object sender, EventArgs e)
- {
- string text;
- if (richTextBox1.Text.Length > 4)
- {
- text = richTextBox1.Text;
- string pos1 = Microsoft.VisualBasic.Interaction.InputBox("Iveskite pradžios poziciją");
- string pos2 = Microsoft.VisualBasic.Interaction.InputBox("Iveskite pabaigos poziciją");
- try
- {
- richTextBox1.Text = text.Substring(Int32.Parse(pos1), Int32.Parse(pos2));
- }
- catch (Exception ex)
- {
- MessageBox.Show("Error while substringing: " + ex.Message);
- }
- }
- }
- private void SearchButton_Click(object sender, EventArgs e)
- {
- string text;
- if (richTextBox1.Text.Length > 0)
- {
- text = richTextBox1.Text;
- string ats = Microsoft.VisualBasic.Interaction.InputBox("Iveskit teksta kurio ieskosite");
- if (text.Contains(ats))
- {
- int pos = text.IndexOf(ats);
- richTextBox1.Focus();
- richTextBox1.Select(pos, ats.Length);
- }
- else
- {
- MessageBox.Show("Ieškomos frazės nėra");
- }
- }
- }
- private void ReplaceButton_Click(object sender, EventArgs e)
- {
- string text;
- if (richTextBox1.Text.Length > 0)
- {
- text = richTextBox1.Text;
- string ats = Microsoft.VisualBasic.Interaction.InputBox("Iveskit teksta kuri pakeisite");
- string repl = Microsoft.VisualBasic.Interaction.InputBox("Iveskit teksta kuriuo pakeisite");
- if (text.Contains(ats))
- {
- richTextBox1.Text = text.Replace(ats, repl);
- }
- else
- {
- MessageBox.Show("Keičiamo teksto nėra");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement