Aplikasi Simple Notepad |
Aplikasi seperti Notepad dengan ukuran dan fungsi yang sama tidak jauh berbeda, Anda dapat menulis rangkuman catatan anda dengan notepad yang lebih simple.
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 Pertemuan2_AplikasiSimpleNotepad
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.StartPosition = FormStartPosition.CenterScreen;
this.FormBorderStyle = FormBorderStyle.FixedSingle;
this.MaximizeBox = false;
this.MinimizeBox = false;
}
void bersih() // Disebut method atau function
{
rtb_input.Text = "";
}
void bukafile() // Disebut method atau function
{
bersih();
OpenFileDialog buka = new OpenFileDialog();
buka.DefaultExt = "txt";
buka.Filter = "Text Document| *.txt";
buka.FileName = "";
if (buka.ShowDialog() != DialogResult.Cancel)
{
string fileTerpilih = buka.FileName;
if (fileTerpilih != "")
{
rtb_input.LoadFile(fileTerpilih, RichTextBoxStreamType.PlainText);
}
}
}
void simpanfile()
{
SaveFileDialog simpan = new SaveFileDialog();
simpan.Filter = " Text Document | *.txt";
simpan.RestoreDirectory = true;
if (simpan.ShowDialog() != DialogResult.Cancel)
{
StreamWriter filesimpan = new StreamWriter(File.Create(simpan.FileName));
filesimpan.Write(rtb_input.Text);
filesimpan.Dispose();
}
}
private void btn_buka_Click(object sender, EventArgs e)
{
if (rtb_input.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 btn_simpan_Click(object sender, EventArgs e)
{
{
simpanfile();
}
}
private void Form1_Load(object sender, EventArgs e)
{
bersih();
}
}
}
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 Pertemuan2_AplikasiSimpleNotepad
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.StartPosition = FormStartPosition.CenterScreen;
this.FormBorderStyle = FormBorderStyle.FixedSingle;
this.MaximizeBox = false;
this.MinimizeBox = false;
}
void bersih() // Disebut method atau function
{
rtb_input.Text = "";
}
void bukafile() // Disebut method atau function
{
bersih();
OpenFileDialog buka = new OpenFileDialog();
buka.DefaultExt = "txt";
buka.Filter = "Text Document| *.txt";
buka.FileName = "";
if (buka.ShowDialog() != DialogResult.Cancel)
{
string fileTerpilih = buka.FileName;
if (fileTerpilih != "")
{
rtb_input.LoadFile(fileTerpilih, RichTextBoxStreamType.PlainText);
}
}
}
void simpanfile()
{
SaveFileDialog simpan = new SaveFileDialog();
simpan.Filter = " Text Document | *.txt";
simpan.RestoreDirectory = true;
if (simpan.ShowDialog() != DialogResult.Cancel)
{
StreamWriter filesimpan = new StreamWriter(File.Create(simpan.FileName));
filesimpan.Write(rtb_input.Text);
filesimpan.Dispose();
}
}
private void btn_buka_Click(object sender, EventArgs e)
{
if (rtb_input.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 btn_simpan_Click(object sender, EventArgs e)
{
{
simpanfile();
}
}
private void Form1_Load(object sender, EventArgs e)
{
bersih();
}
}
}
INGAT!!
Jika Anda kurang puas atau ingin menambahkan ide
Anda dapat mengkostumnya di Form/View code nya
Untuk keterangan lebih lanjut lihat slide
Download Slide
Download Program
0 komentar:
Posting Komentar