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.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace Zadacha
- {
- public partial class Form : System.Windows.Forms.Form
- {
- public Form()
- {
- InitializeComponent();
- }
- private void boldButton_Click(object sender, EventArgs e)
- {
- if (text.SelectionFont.Bold)
- {
- if (text.SelectionFont.Underline)
- {
- if (text.SelectionFont.Italic)
- {
- setFont(false, true, true);
- }
- else
- {
- setFont(false, true, false);
- }
- }
- else
- {
- setFont(false, false, false);
- }
- }
- else
- {
- text.SelectionFont = new Font(text.SelectionFont, text.SelectionFont.Style | FontStyle.Bold);
- }
- }
- private void clear_Click(object sender, EventArgs e)
- {
- text.Clear();
- }
- private void italicButton_Click(object sender, EventArgs e)
- {
- if (text.SelectionFont.Italic)
- {
- if (text.SelectionFont.Bold)
- {
- if (text.SelectionFont.Underline)
- {
- setFont(true, true, false);
- }
- else
- {
- setFont(true, false, false);
- }
- }
- else
- {
- setFont(false, false, false);
- }
- }
- else
- {
- text.SelectionFont = new Font(text.SelectionFont, text.SelectionFont.Style | FontStyle.Italic);
- }
- }
- private void underlineButton_Click(object sender, EventArgs e)
- {
- if (text.SelectionFont.Underline)
- {
- if (text.SelectionFont.Bold)
- {
- if (text.SelectionFont.Italic)
- {
- setFont(true, false, true);
- }
- else
- {
- setFont(true, false, false);
- }
- }
- else
- {
- setFont(false, false, false);
- }
- }
- else
- {
- text.SelectionFont = new Font(text.SelectionFont, text.SelectionFont.Style | FontStyle.Underline);
- }
- }
- private void setFont(bool wasB, bool wasU, bool wasI)
- {
- if (wasB)
- {
- if (wasI)
- {
- text.SelectionFont = new Font(text.SelectionFont, FontStyle.Bold | FontStyle.Italic | FontStyle.Regular);
- }
- else if (wasU)
- {
- text.SelectionFont = new Font(text.SelectionFont, FontStyle.Bold | FontStyle.Underline | FontStyle.Regular);
- }
- }
- if (wasU)
- {
- if (wasB)
- {
- text.SelectionFont = new Font(text.SelectionFont, FontStyle.Bold | FontStyle.Underline | FontStyle.Regular);
- }
- else if (wasI)
- {
- text.SelectionFont = new Font(text.SelectionFont, FontStyle.Italic | FontStyle.Underline | FontStyle.Regular);
- }
- }
- if (wasI)
- {
- if (wasU)
- {
- text.SelectionFont = new Font(text.SelectionFont, FontStyle.Underline | FontStyle.Italic | FontStyle.Regular);
- }
- else if (wasB)
- {
- text.SelectionFont = new Font(text.SelectionFont, FontStyle.Bold | FontStyle.Italic | FontStyle.Regular);
- }
- }
- }
- private void fontSize_SelectedIndexChanged(object sender, EventArgs e)
- {
- FontChange();
- }
- private void FontChange()
- {
- // throw new Not Implemented Exception();
- float fontsize = 10;
- string fontfamily = fontFont.SelectedItem.ToString();
- string fontname = text.SelectionFont.Name;
- if (fontSize.Text != "") fontsize = float.Parse(fontSize.Text);
- if (fontsize == 0) fontsize = 10;
- if (text.SelectionLength > 0)
- {
- text.SelectionFont = new Font(fontfamily, fontsize, text.SelectionFont.Style);
- }
- }
- private void fontFont_SelectedIndexChanged(object sender, EventArgs e)
- {
- float fontsize = text.SelectionFont.Size;
- string fontfamily = fontFont.SelectedItem.ToString();
- if (fontfamily != "")
- {
- text.SelectionFont = new Font(fontfamily, fontsize, text.SelectionFont.Style);
- }
- }
- bool click = false;
- private void fontColor_Click(object sender, EventArgs e)
- {
- click = true;
- change(true);
- }
- private void change(bool fontOrSize)
- {
- if (click == true)
- {
- ColorDialog fd = new ColorDialog();
- if (fd.ShowDialog() == DialogResult.OK)
- {
- if (fontOrSize)
- {
- text.SelectionColor = fd.Color;
- }
- else
- {
- text.SelectionBackColor = fd.Color;
- }
- }
- }
- }
- private void fontBGColor_Click(object sender, EventArgs e)
- {
- click = true;
- change(false);
- }
- private void save_Click(object sender, EventArgs e)
- {
- string path = Directory.GetCurrentDirectory();
- using (StreamWriter writer = new StreamWriter("saved.txt"))
- {
- foreach (var item in text.Text)
- {
- writer.Write(item);
- }
- }
- }
- private async void load_Click(object sender, EventArgs e)
- {
- OpenFileDialog fd = new OpenFileDialog();
- fd.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
- if (fd.ShowDialog() == DialogResult.OK)
- {
- using (Stream stream = fd.OpenFile())
- {
- using (var reader = new StreamReader(stream))
- {
- string line = await reader.ReadToEndAsync();
- text.Text = line;
- }
- }
- }
- }
- private void Form_Load(object sender, EventArgs e)
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement