Com tempo irei incrementado funções nele.
Modifica Fonte, Modifica cor da letra. Aceita e salva em formatos RTF e TXT.
Quem quiser da olhada ou testar, so fazer download. Não precisa instalar, só descompactar e abrir.
Caso anti-virus interrompa, só esperar ele examinar e pronto, abre normal.
https://www.4shared.com/rar/ZkyV-ViJba/Diary.html
Aqui está o código fonte:
Form2.cs:
using System;
using System.Windows.Forms;
using System.IO;
namespace App2Form2
{
public partial class Form2 : Form
{
public string filefilter = "Rich Text Format | *.rtf*|Texto sem Formatação|*.txt*|All Files|*.*";
public Form2()
{
InitializeComponent();
}
private void abrirToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = filefilter;
if(ofd.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
{
if (Path.GetExtension(ofd.FileName) == ".rtf")
{
richTextBox1.LoadFile(ofd.FileName);
}
else if(Path.GetExtension(ofd.FileName) == ".txt")
{
StreamReader sr = new StreamReader(ofd.FileName);
string imputline = "";
while((imputline = sr.ReadLine()) != null)
{
richTextBox1.Text += imputline + "\n";
}
sr.Close();
}
else
{
StreamReader sr = new StreamReader(ofd.FileName);
string imputline = "";
while ((imputline = sr.ReadLine()) != null)
{
richTextBox1.Text += imputline + "\n";
}
sr.Close();
}
}
}
private void salvarComoToolStripMenuItem_Click(object sender, EventArgs e)
{
salvar();
}
public void salvar()
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = filefilter;
if (sfd.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
{
if (sfd.FilterIndex == 1)
{
//RTF
if (File.Exists(sfd.FileName + ".rtf"))
{
File.Delete(sfd.FileName + ".rtf");
}
richTextBox1.SaveFile(sfd.FileName + ".rtf");
}
else if (sfd.FilterIndex == 2)
{
//TXT
if (File.Exists(sfd.FileName + ".txt"))
{
File.Delete(sfd.FileName + ".txt");
}
StreamWriter sw = new StreamWriter(sfd.FileName + ".txt");
for (int linha = 0; linha < richTextBox1.Lines.Length; linha++)
{
sw.WriteLine(richTextBox1.Lines[linha]);
}
}
else if (sfd.FilterIndex == 3)
{
//All Files
if (File.Exists(sfd.FileName))
{
File.Delete(sfd.FileName);
}
}
}
}
private void sairToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
}
private void novoToolStripMenuItem_Click(object sender, EventArgs e)
{
if (richTextBox1.Text.Length > 0)
{
DialogResult dr = MessageBox.Show("Deseja salvar seu arquivo?", "Questão", MessageBoxButtons.YesNo);
if (dr == System.Windows.Forms.DialogResult.Yes)
{
salvar();
}
if (dr == DialogResult.No)
{
richTextBox1.Text = "";
}
}
else
{
richTextBox1.Text = "";
}
}
private void fonteToolStripMenuItem_Click(object sender, EventArgs e)
{
FontDialog fd = new FontDialog();
fd.Font = richTextBox1.SelectionFont;
if(fd.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
{
richTextBox1.SelectionFont = fd.Font;
}
}
private void corDaFonteToolStripMenuItem_Click(object sender, EventArgs e)
{
ColorDialog cd = new ColorDialog();
cd.Color = richTextBox1.SelectionColor;
if(cd.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
{
richTextBox1.SelectionColor = cd.Color;
}
}
private void Form2_FormClosed(object sender, FormClosedEventArgs e)
{
if (richTextBox1.Text.Length > 0)
{
DialogResult dr = MessageBox.Show("Deseja salvar seu arquivo?", "Salvar?", MessageBoxButtons.YesNoCancel);
if (dr == System.Windows.Forms.DialogResult.Yes)
{
salvar();
}
if (dr == DialogResult.Cancel)
{
this.Dispose();
}
}
}
private void sobreToolStripMenuItem_Click(object sender, EventArgs e)
{
MessageBox.Show("Criado Por Lucas Souza!");
}
}
}Program.cs:
using System;
using System.Windows.Forms;
namespace App2Form2
{
static class Program
{
/// <summary>
/// Ponto de entrada principal para o aplicativo.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form2());
}
}
}


Nenhum comentário:
Postar um comentário