Text Editor Sederhana



kali ini kita akan coba membuat sebuah aplikasi text editor seperti gambar diatas ini berikut design dan codingan nya yang akan dijelaskan dibawah :



buatlah design seperti gambar diatas sesuai kan (Name) dari tiap komponen yang ada pada design tersebut.

Berikut kodingan untuk program tersebut sesuaikan penempatan kodingan dengan button yang diminta. Karena jika tidak sesuai kodingan tersebut tidak akan bekerja. kita bisa lihat disetiap kdoingan tesbut terdapat nama fungsi yang akan menjadi acuan dibutton mana kita bisa menempatkan kodingan tersebut.

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 SaveFile
{
    public partial class FormSimpleEditor : Form
    {
        String filename;
        Boolean newfile = false;
        //
        public FormSimpleEditor()
        {
            InitializeComponent();
            //
            textboxArea.Enabled = false;
            labelFilename.Text = "";
        }

        private void labelOpen_Click(object sender, EventArgs e)
        {
            OpenFileDialog window_open_dialog = new OpenFileDialog();
            window_open_dialog.Title = "Silahkan pilih file anda";
            window_open_dialog.Filter = "Text files(*.txt)|*.txt|Semua files(*.*)|*.*";

            if (window_open_dialog.ShowDialog() == DialogResult.OK)
            {
                StreamReader stream_read = new StreamReader(File.OpenRead(window_open_dialog.FileName));
                textboxArea.Text = stream_read.ReadToEnd();
                stream_read.Dispose();
                //
                textboxArea.Enabled = true;
                filename = window_open_dialog.FileName;
                labelFilename.Text = "(*Sedang diedit) "+filename;
            }
        }

        private void buttonSave_Click(object sender, EventArgs e)
        {
            if (newfile == true)
            {
                SaveFileDialog window_save_dialog = new SaveFileDialog();
                window_save_dialog.Title = "Pilih tempat penyimpanan";
                window_save_dialog.Filter = "Text files (*.txt)|*.txt|Semua files (*.*)|*.*";
                //
                if (window_save_dialog.ShowDialog() == DialogResult.OK)
                {
                    StreamWriter stream_write = new StreamWriter(File.Create(window_save_dialog.FileName));
                    stream_write.Write(textboxArea.Text);
                    stream_write.Dispose();
                    //
                    filename = window_save_dialog.FileName;
                    labelFilename.Text = filename;
                    newfile = false;
                }
            }
            else
            {
                StreamWriter stream_write = new StreamWriter(filename);
                stream_write.Write(textboxArea.Text);
                stream_write.Dispose();
                //
                labelFilename.Text = filename;
            }
        }

        private void labelNew_Click(object sender, EventArgs e)
        {
            newfile = true;
            textboxArea.Enabled = true;
            textboxArea.Text = "";
            labelFilename.Text = "Filename: *Untitled";
        }

        private void labelAbout_Click(object sender, EventArgs e)
        {
            String information = "Simple File Editor\n\nMediatutorial.web.id\nOKie Eko Wardoyo";
            MessageBox.Show(information, "About", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void openToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            OpenFileDialog window_open_dialog = new OpenFileDialog();
            window_open_dialog.Title = "Silahkan pilih file anda";
            window_open_dialog.Filter = "Text files(*.txt)|*.txt|Semua files(*.*)|*.*";

            if (window_open_dialog.ShowDialog() == DialogResult.OK)
            {
                StreamReader stream_read = new StreamReader(File.OpenRead(window_open_dialog.FileName));
                textboxArea.Text = stream_read.ReadToEnd();
                stream_read.Dispose();
                //
                textboxArea.Enabled = true;
                filename = window_open_dialog.FileName;
                labelFilename.Text = "(*Sedang diedit) " + filename;
            }
        }

        private void newToolStripMenuItem_Click(object sender, EventArgs e)
        {
            newfile = true;
            textboxArea.Enabled = true;
            textboxArea.Text = "";
            labelFilename.Text = "Filename: *Untitled";
        }

        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (newfile == true)
            {
                SaveFileDialog window_save_dialog = new SaveFileDialog();
                window_save_dialog.Title = "Pilih tempat penyimpanan";
                window_save_dialog.Filter = "Text files (*.txt)|*.txt|Semua files (*.*)|*.*";
                //
                if (window_save_dialog.ShowDialog() == DialogResult.OK)
                {
                    StreamWriter stream_write = new StreamWriter(File.Create(window_save_dialog.FileName));
                    stream_write.Write(textboxArea.Text);
                    stream_write.Dispose();
                    //
                    filename = window_save_dialog.FileName;
                    labelFilename.Text = filename;
                    newfile = false;
                }
            }
            else
            {
                StreamWriter stream_write = new StreamWriter(filename);
                stream_write.Write(textboxArea.Text);
                stream_write.Dispose();
                //
                labelFilename.Text = filename;
            }
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            String information = "Simple File Editor\n\nMediatutorial.web.id\nOKie Eko Wardoyo";
            MessageBox.Show(information, "About", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        private void fontStyleToolStripMenuItem_Click(object sender, EventArgs e)
        {
            fontDialog1.Font = textboxArea.Font;
            fontDialog1.Color = textboxArea.ForeColor;

            if (fontDialog1.ShowDialog() != DialogResult.Cancel)
            {
                textboxArea.Font = fontDialog1.Font;
                textboxArea.ForeColor = fontDialog1.Color;
            }
        }

        private void styleToolStripMenuItem_Click(object sender, EventArgs e)
        {
            fontDialog1.Font = textboxArea.Font;
            fontDialog1.Color = textboxArea.ForeColor;

            if (fontDialog1.ShowDialog() != DialogResult.Cancel)
            {
                textboxArea.Font = fontDialog1.Font;
                textboxArea.ForeColor = fontDialog1.Color;
               
            }
        }

        private void colorToolStripMenuItem_Click(object sender, EventArgs e)
        {
            colorDialog1.Color = textboxArea.ForeColor;
            if (colorDialog1.ShowDialog() == DialogResult.OK)
            {
                textboxArea.ForeColor = colorDialog1.Color;
            }
        }

        private void backgroundToolStripMenuItem_Click(object sender, EventArgs e)
        {
            colorDialog1.Color = textboxArea.BackColor;
            if (colorDialog1.ShowDialog() == DialogResult.OK)
            {
                textboxArea.BackColor = colorDialog1.Color;
            }
        }

        private void menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {

        }

        private void helpToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }
    }
}


Penulis : Unknown ~ Sebuah blog yang menyediakan berbagai macam informasi

Artikel Text Editor Sederhana ini dipublish oleh Unknown pada hari Minggu, 14 Mei 2017. Semoga artikel ini dapat bermanfaat.Terimakasih atas kunjungan Anda silahkan tinggalkan komentar.sudah ada 0 komentar: di postingan Text Editor Sederhana
 

0 komentar:

Posting Komentar