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.Windows.Forms;
- using System.IO;
- namespace Notepad
- {
- public partial class Main : Form
- {
- public Main()
- {
- InitializeComponent();
- }
- string usedfile = string.Empty;
- private void zamknijToolStripMenuItem_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- private void otwórzToolStripMenuItem_Click(object sender, EventArgs e)
- {
- OpenFile();
- }
- private void zapiszToolStripMenuItem_Click(object sender, EventArgs e)
- {
- SaveFile();
- }
- private void OpenFile()
- {
- if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
- {
- try
- {
- TabPage tabPage1 = new TabPage();
- tabPage1.Location = new System.Drawing.Point(4, 22);
- tabPage1.Name = usedfile = Path.GetDirectoryName(openFileDialog1.FileName);
- tabPage1.Padding = new System.Windows.Forms.Padding(3);
- tabPage1.Size = new System.Drawing.Size(447, 334);
- tabPage1.TabIndex = 0;
- tabPage1.Text = "tabPage1";
- tabPage1.UseVisualStyleBackColor = true;
- RichTextBox richTextBox1 = new RichTextBox();
- // richTextBox1.Dock = DockStyle.Fill;
- //tabPage1.Controls.Add(richTextBox1);
- WebBrowser WebBrowser1 = new WebBrowser();//--
- richTextBox1.Width = tabPage1.Width / 2;//--
- richTextBox1.Height = tabPage1.Height;//--
- WebBrowser1.Left = tabPage1.Width / 2;//--
- WebBrowser1.Width = tabPage1.Width / 2;//--
- WebBrowser1.Height = tabPage1.Height;//--
- richTextBox1.TextChanged += new EventHandler(TextChanged);//--
- tabControl1.Controls.Add(tabPage1);//--
- tabPage1.Text = Path.GetFileName(openFileDialog1.FileName);
- richTextBox1.Text = File.ReadAllText(openFileDialog1.FileName);
- WebBrowser1.DocumentText = richTextBox1.Text;//--
- tabPage1.Controls.Add(richTextBox1);//--
- tabPage1.Controls.Add(WebBrowser1);//--
- }
- catch
- {
- }
- }
- }
- private void TextChanged(object sender, EventArgs e)
- {
- foreach (Control c in tabControl1.SelectedTab.Controls)
- {
- if (c is WebBrowser)
- {
- (c as WebBrowser).DocumentText = (sender as RichTextBox).Text;
- break;
- }
- }
- }
- private void SaveFile()
- {
- if (tabControl1.Controls.Count > 0)
- {
- TabPage t = (TabPage)tabControl1.Controls[tabControl1.SelectedIndex];
- saveFileDialog1.InitialDirectory = t.Name;
- saveFileDialog1.FileName = t.Text;
- RichTextBox richTextBox = (RichTextBox)t.Controls[0];
- if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
- {
- try
- {
- System.IO.File.WriteAllText(saveFileDialog1.FileName, richTextBox.Text);
- tabControl1.Controls.Remove(t);
- tabControl1.SelectTab(0);
- }
- catch
- {
- }
- }
- }
- }
- private void menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
- {
- }
- private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
- {
- }
- private void button1_Click(object sender, EventArgs e)
- {
- foreach (Control c in tabControl1.SelectedTab.Controls)
- {
- if (c is RichTextBox)
- {
- int dlugosc = (c as RichTextBox).SelectionLength;
- int start = (c as RichTextBox).SelectionStart;
- string dane = (c as RichTextBox).Text;
- dane = dane.Insert(start + dlugosc, "</br>");
- (c as RichTextBox).Text = dane;
- }
- }
- }
- private void button2_Click(object sender, EventArgs e)
- {
- foreach (Control c in tabControl1.SelectedTab.Controls)
- {
- if (c is RichTextBox)
- {
- int dlugosc = (c as RichTextBox).SelectionLength;
- int start = (c as RichTextBox).SelectionStart;
- string dane = (c as RichTextBox).Text;
- dane = dane.Insert(start, "<p>");
- (c as RichTextBox).Text = dane;
- }
- }
- }
- private void button3_Click(object sender, EventArgs e)
- {
- foreach (Control c in tabControl1.SelectedTab.Controls)
- {
- if (c is RichTextBox)
- {
- int dlugosc = (c as RichTextBox).SelectionLength;
- int start = (c as RichTextBox).SelectionStart;
- string dane = (c as RichTextBox).Text;
- dane = dane.Insert(start, "<span>");
- (c as RichTextBox).Text = dane;
- }
- }
- }
- private void button4_Click(object sender, EventArgs e)
- {
- foreach (Control c in tabControl1.SelectedTab.Controls)
- {
- if (c is RichTextBox)
- {
- int dlugosc = (c as RichTextBox).SelectionLength;
- int start = (c as RichTextBox).SelectionStart;
- string dane = (c as RichTextBox).Text;
- dane = dane.Insert(start + dlugosc, "</span>");
- (c as RichTextBox).Text = dane;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement