Membuat notepad dengan VB
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;
using System.IO;
namespace notepad
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.StartPosition = FormStartPosition.CenterScreen;
this.FormBorderStyle = FormBorderStyle.FixedSingle;
this.MaximizeBox = false;
this.MinimizeBox = false;
}
void bersih()
{
rtinput.Text = "";
}
void bukafile()
{
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 != "")
{
rtinput.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(rtinput.Text);
filesimpan.Dispose();
}
}
private void
rtinput_TextChanged(object sender, EventArgs e)
{
}
private void
bbukafile_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
bsimpanfile_Click(object sender, EventArgs e)
{
{
simpanfile();
}
}
private void
Form1_Load(object sender, EventArgs e)
{
bersih();
}
}
}
Komentar
Posting Komentar