Bahasa C# : Cara menambah form (Login)
ketika username dan password yang saya isikan benar di form1, lalu saya tekan "Login" maka akan muncul form2. seperti gambar dibawah ini
di form2 terdapat label, yang mana kata kata label tersebut sesuai dengan username pada form1.
tapi ketika username dan password yang dimasukkan salah, maka akan muncul peringatan di Massage Box. seperti gambar dibawah ini.
berikut code programnya :
1.) form1 :
using System;2.) form2 :
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 banyakform
{
public partial class Form1 : Form
{
public string data;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text == "cathra" && textBox2.Text == "cathra34")
{
data = textBox1.Text;
Form2 f2 = new Form2();
this.Visible = false;
f2.induk = this;
f2.ShowDialog();
this.Visible = true;
}
else
{
DialogResult dialog = MessageBox.Show("(username dan password anda salah!)", " ", MessageBoxButtons.OK, MessageBoxIcon.Stop);
}
}
}
}
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 banyakform
{
public partial class Form2 : Form
{
public Form1 induk = new Form1();
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
label2.Text = "Kak " + induk.data + "!" ;
}
}
}
Komentar
Posting Komentar