CARA MEMBUAT SIMPLE NOTEPAD DENGAN VISUAL STUDIO 2010
Simple Notepad
Program Simple Notepad
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 Microsoft.Win32; //library tambahan
using System.IO;//dalam program windows 32
namespace Simple_notepad
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.StartPosition = FormStartPosition.CenterScreen; // posisi form berada di tengah,
this.FormBorderStyle = FormBorderStyle.FixedSingle; // form tidak bisa dibesar / dikecilkan,
this.MaximizeBox = false; //dan menghilangkan tombol maximize dan minimize.
this.MinimizeBox = false;
}
void bersih() //fungsi untuk membersihkan richtext input
{
rtinput.Text = "";
}
void bukafile() //fungsi untuk membuka file ".txt"
{
bersih();
OpenFileDialog buka = new OpenFileDialog();
buka.DefaultExt = ".txt";
buka.Filter = " Text Documents | *.txt";
buka.FileName = "";
if (buka.ShowDialog() != DialogResult.Cancel)
{
string fileTerpilih = buka.FileName;
if (fileTerpilih != "")
{
rtinput.LoadFile(fileTerpilih, RichTextBoxStreamType.PlainText);
}
}
}
void simpanfile() //fungsi untuk menyimpan file
{
SaveFileDialog simpan = new SaveFileDialog();
simpan.Filter = " Text Documents | *.txt";
simpan.RestoreDirectory = true;
if (simpan.ShowDialog() != DialogResult.Cancel)
{
StreamWriter filesimpan = new StreamWriter(File.Create(simpan.FileName));
filesimpan.Write(rtinput.Text);
filesimpan.Dispose();
}
}
private void button1_Click(object sender, EventArgs e)
{
if (rtinput.Text != "")
{
var pesan = MessageBox.Show("File belum tersimpan, yakin ingin membuka file baru???","konfirmasi", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (pesan == DialogResult.Yes)
{
bukafile();
}
}
else
{
bukafile();
}
}
private void button2_Click(object sender, EventArgs e)
{
{
simpanfile();
}
}
private void Form1_Load(object sender, EventArgs e)
{
bersih();
}
private void rtinput_TextChanged(object sender, EventArgs e)
{
}
}
}


Tidak ada komentar:
Posting Komentar