Bahasa C# : untuk pemula dalam menggunakan text box1 dan text box2
diatas adalah contoh tampilan hasil programnya.
terdapat 2 text box dan beberapa fitur seperti copy, cut, delete, backspace, dan paste.
berikut programnya dalam bahasa c# :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace coba2
{
public partial class Form1 : Form
{
int status = 0;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e) //on
{
if(status==1)
textBox1.Text = "Halo";
if (status == 2)
textBox2.Text = "Halo";
}
private void button2_Click(object sender, EventArgs e) //backspace
{
if(status==1)
if(textBox1.Text.Length>0)
textBox1.Text = textBox1.Text.Substring(0, textBox1.Text.Length - 1);
if(status==2)
if(textBox2.Text.Length>0)
textBox2.Text = textBox1.Text.Substring(0, textBox2.Text.Length - 1);
}
private void button3_Click(object sender, EventArgs e) //delete
{
if(status==1)
textBox1.Clear();
if(status==2)
textBox2.Clear();
}
private void button4_Click(object sender, EventArgs e) //copy
{
if (status == 1)
Clipboard.SetText(textBox1.SelectedText);
if (status == 2)
Clipboard.SetText(textBox2.SelectedText);
}
private void button5_Click(object sender, EventArgs e) //paste
{
if (status == 1)
textBox1.SelectedText = Clipboard.GetText();
if (status == 2)
textBox2.SelectedText = Clipboard.GetText();
}
private void textBox1_MouseClick(object sender, MouseEventArgs e)
{
status = 1;
}
private void textBox2_MouseClick(object sender, MouseEventArgs e)
{
status = 2;
}
private void button6_Click(object sender, EventArgs e) //cut
{
if (status == 1)
Clipboard.SetText(textBox1.SelectedText);
textBox1.SelectedText = string.Empty;
if (status == 2)
Clipboard.SetText(textBox2.SelectedText);
textBox2.SelectedText = string.Empty;
}
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
System.Diagnostics.Process.Start("Chrome", "http://gekanews.blogspot.com/");
}
}
}
Komentar
Posting Komentar