Advertisement
Guest User

Untitled

a guest
May 25th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.52 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.IO;
  10.  
  11. namespace Notepad
  12. {
  13. public partial class Main : Form
  14. {
  15. public Main()
  16. {
  17. InitializeComponent();
  18. }
  19.  
  20. string usedfile = string.Empty;
  21.  
  22. private void zamknijToolStripMenuItem_Click(object sender, EventArgs e)
  23. {
  24. this.Close();
  25. }
  26.  
  27. private void otwórzToolStripMenuItem_Click(object sender, EventArgs e)
  28. {
  29. OpenFile();
  30.  
  31. }
  32.  
  33. private void zapiszToolStripMenuItem_Click(object sender, EventArgs e)
  34. {
  35. SaveFile();
  36. }
  37.  
  38. private void OpenFile()
  39. {
  40. if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  41. {
  42.  
  43. try
  44. {
  45. TabPage tabPage1 = new TabPage();
  46. tabPage1.Location = new System.Drawing.Point(4, 22);
  47. tabPage1.Name = usedfile = Path.GetDirectoryName(openFileDialog1.FileName);
  48. tabPage1.Padding = new System.Windows.Forms.Padding(3);
  49. tabPage1.Size = new System.Drawing.Size(447, 334);
  50. tabPage1.TabIndex = 0;
  51. tabPage1.Text = "tabPage1";
  52. tabPage1.UseVisualStyleBackColor = true;
  53.  
  54. RichTextBox richTextBox1 = new RichTextBox();
  55. // richTextBox1.Dock = DockStyle.Fill;
  56. //tabPage1.Controls.Add(richTextBox1);
  57. WebBrowser WebBrowser1 = new WebBrowser();//--
  58. richTextBox1.Width = tabPage1.Width / 2;//--
  59. richTextBox1.Height = tabPage1.Height;//--
  60.  
  61. WebBrowser1.Left = tabPage1.Width / 2;//--
  62. WebBrowser1.Width = tabPage1.Width / 2;//--
  63. WebBrowser1.Height = tabPage1.Height;//--
  64. richTextBox1.TextChanged += new EventHandler(TextChanged);//--
  65.  
  66. tabControl1.Controls.Add(tabPage1);//--
  67.  
  68. tabPage1.Text = Path.GetFileName(openFileDialog1.FileName);
  69. richTextBox1.Text = File.ReadAllText(openFileDialog1.FileName);
  70.  
  71. WebBrowser1.DocumentText = richTextBox1.Text;//--
  72. tabPage1.Controls.Add(richTextBox1);//--
  73. tabPage1.Controls.Add(WebBrowser1);//--
  74. }
  75. catch
  76. {
  77.  
  78. }
  79. }
  80. }
  81. private void TextChanged(object sender, EventArgs e)
  82. {
  83. foreach (Control c in tabControl1.SelectedTab.Controls)
  84. {
  85. if (c is WebBrowser)
  86. {
  87. (c as WebBrowser).DocumentText = (sender as RichTextBox).Text;
  88. break;
  89. }
  90.  
  91. }
  92.  
  93. }
  94.  
  95.  
  96.  
  97. private void SaveFile()
  98. {
  99. if (tabControl1.Controls.Count > 0)
  100. {
  101. TabPage t = (TabPage)tabControl1.Controls[tabControl1.SelectedIndex];
  102.  
  103. saveFileDialog1.InitialDirectory = t.Name;
  104. saveFileDialog1.FileName = t.Text;
  105.  
  106. RichTextBox richTextBox = (RichTextBox)t.Controls[0];
  107.  
  108. if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  109. {
  110. try
  111. {
  112. System.IO.File.WriteAllText(saveFileDialog1.FileName, richTextBox.Text);
  113. tabControl1.Controls.Remove(t);
  114. tabControl1.SelectTab(0);
  115. }
  116. catch
  117. {
  118.  
  119. }
  120. }
  121. }
  122.  
  123. }
  124.  
  125. private void menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
  126. {
  127.  
  128. }
  129.  
  130. private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
  131. {
  132.  
  133. }
  134.  
  135. private void button1_Click(object sender, EventArgs e)
  136. {
  137. foreach (Control c in tabControl1.SelectedTab.Controls)
  138. {
  139. if (c is RichTextBox)
  140. {
  141. int dlugosc = (c as RichTextBox).SelectionLength;
  142. int start = (c as RichTextBox).SelectionStart;
  143. string dane = (c as RichTextBox).Text;
  144. dane = dane.Insert(start + dlugosc, "</br>");
  145. (c as RichTextBox).Text = dane;
  146.  
  147. }
  148. }
  149. }
  150.  
  151. private void button2_Click(object sender, EventArgs e)
  152. {
  153. foreach (Control c in tabControl1.SelectedTab.Controls)
  154. {
  155. if (c is RichTextBox)
  156. {
  157. int dlugosc = (c as RichTextBox).SelectionLength;
  158. int start = (c as RichTextBox).SelectionStart;
  159. string dane = (c as RichTextBox).Text;
  160. dane = dane.Insert(start, "<p>");
  161. (c as RichTextBox).Text = dane;
  162.  
  163. }
  164. }
  165. }
  166.  
  167. private void button3_Click(object sender, EventArgs e)
  168. {
  169. foreach (Control c in tabControl1.SelectedTab.Controls)
  170. {
  171. if (c is RichTextBox)
  172. {
  173. int dlugosc = (c as RichTextBox).SelectionLength;
  174. int start = (c as RichTextBox).SelectionStart;
  175. string dane = (c as RichTextBox).Text;
  176.  
  177.  
  178. dane = dane.Insert(start, "<span>");
  179. (c as RichTextBox).Text = dane;
  180.  
  181. }
  182. }
  183. }
  184.  
  185. private void button4_Click(object sender, EventArgs e)
  186. {
  187. foreach (Control c in tabControl1.SelectedTab.Controls)
  188. {
  189. if (c is RichTextBox)
  190. {
  191. int dlugosc = (c as RichTextBox).SelectionLength;
  192. int start = (c as RichTextBox).SelectionStart;
  193. string dane = (c as RichTextBox).Text;
  194.  
  195. dane = dane.Insert(start + dlugosc, "</span>");
  196.  
  197. (c as RichTextBox).Text = dane;
  198.  
  199. }
  200. }
  201.  
  202.  
  203.  
  204.  
  205.  
  206. }
  207. }
  208.  
  209.  
  210.  
  211.  
  212.  
  213. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement