Tombol Kejadian Pada Perintah “MessageBox” dengan C#.NET 2010
Contoh sederhana menampilkan jenis-jenis tombol kejadian pada kotak pesan dengan menggunakan perintah MessageBox dengan Visual C#.NET 2010.
1. Tombol AbortRetryIgnore
1: using System;
2: using System.Collections.Generic;
3: using System.ComponentModel;
4: using System.Data;
5: using System.Drawing;
6: using System.Linq;
7: using System.Text;
8: using System.Windows.Forms;
9: 10: namespace WindowsFormsApplication1
11: {12: public partial class Form1 : Form
13: {14: public Form1()
15: { 16: InitializeComponent(); 17: } 18: 19: private void button1_Click(object sender, EventArgs e)
20: {21: var Pilih = MessageBox.Show("Halo, Dunia!",
22: "Tombol AbortRetryIgnore",
23: MessageBoxButtons.AbortRetryIgnore, 24: MessageBoxIcon.Information);25: if (Pilih == DialogResult.Abort)
26: {27: MessageBox.Show("Tombol Abort di pilih");
28: }29: if (Pilih == DialogResult.Retry)
30: {31: MessageBox.Show("Tombol Retry di pilih");
32: }33: if (Pilih == DialogResult.Ignore)
34: {35: MessageBox.Show("Tombol Ignore di pilih");
36: } 37: } 38: } 39: }2. Tombol OK
1: using System;
2: using System.Collections.Generic;
3: using System.ComponentModel;
4: using System.Data;
5: using System.Drawing;
6: using System.Linq;
7: using System.Text;
8: using System.Windows.Forms;
9: 10: namespace WindowsFormsApplication1
11: {12: public partial class Form1 : Form
13: {14: public Form1()
15: { 16: InitializeComponent(); 17: } 18: 19: private void button1_Click(object sender, EventArgs e)
20: {21: MessageBox.Show("Halo, Dunia!",
22: "Tombol OK",
23: MessageBoxButtons.OK, 24: MessageBoxIcon.Information); 25: } 26: } 27: }3. Tombol OKCancel
1: using System;
2: using System.Collections.Generic;
3: using System.ComponentModel;
4: using System.Data;
5: using System.Drawing;
6: using System.Linq;
7: using System.Text;
8: using System.Windows.Forms;
9: 10: namespace WindowsFormsApplication1
11: {12: public partial class Form1 : Form
13: {14: public Form1()
15: { 16: InitializeComponent(); 17: } 18: 19: private void button1_Click(object sender, EventArgs e)
20: {21: var Pilih = MessageBox.Show("Halo, Dunia!", "Tombol OKCancel", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
22: if (Pilih == DialogResult.OK)
23: {24: MessageBox.Show("Tombol OK di pilih");
25: }26: if (Pilih == DialogResult.Cancel)
27: {28: MessageBox.Show("Tombol Cancel di pilih");
29: } 30: } 31: } 32: }atau
1: using System;
2: using System.Collections.Generic;
3: using System.ComponentModel;
4: using System.Data;
5: using System.Drawing;
6: using System.Linq;
7: using System.Text;
8: using System.Windows.Forms;
9: 10: namespace WindowsFormsApplication1
11: {12: public partial class Form1 : Form
13: {14: public Form1()
15: { 16: InitializeComponent(); 17: } 18: 19: private void button1_Click(object sender, EventArgs e)
20: {21: var Pilih = MessageBox.Show("Halo, Dunia!", "Tombol OKCancel", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
22: if (Pilih == DialogResult.OK)
23: {24: MessageBox.Show("Tombol OK di pilih");
25: }26: else
27: {28: MessageBox.Show("Tombol Cancel di pilih");
29: } 30: } 31: } 32: }4. Tombol RetryCancel
1: using System;
2: using System.Collections.Generic;
3: using System.ComponentModel;
4: using System.Data;
5: using System.Drawing;
6: using System.Linq;
7: using System.Text;
8: using System.Windows.Forms;
9: 10: namespace WindowsFormsApplication1
11: {12: public partial class Form1 : Form
13: {14: public Form1()
15: { 16: InitializeComponent(); 17: } 18: 19: private void button1_Click(object sender, EventArgs e)
20: {21: var Pilih = MessageBox.Show("Halo, Dunia!", "Tombol RetryCancel", MessageBoxButtons.RetryCancel, MessageBoxIcon.Information);
22: if (Pilih == DialogResult.Retry)
23: {24: MessageBox.Show("Tombol Retry di pilih");
25: }26: if (Pilih == DialogResult.Cancel)
27: {28: MessageBox.Show("Tombol Cancel di pilih");
29: } 30: } 31: } 32: }atau
1: using System;
2: using System.Collections.Generic;
3: using System.ComponentModel;
4: using System.Data;
5: using System.Drawing;
6: using System.Linq;
7: using System.Text;
8: using System.Windows.Forms;
9: 10: namespace WindowsFormsApplication1
11: {12: public partial class Form1 : Form
13: {14: public Form1()
15: { 16: InitializeComponent(); 17: } 18: 19: private void button1_Click(object sender, EventArgs e)
20: {21: var Pilih = MessageBox.Show("Halo, Dunia!", "Tombol RetryCancel", MessageBoxButtons.RetryCancel, MessageBoxIcon.Information);
22: if (Pilih == DialogResult.Retry)
23: {24: MessageBox.Show("Tombol Retry di pilih");
25: }26: else
27: {28: MessageBox.Show("Tombol Cancel di pilih");
29: } 30: } 31: } 32: }5. Tombol YesNo
1: using System;
2: using System.Collections.Generic;
3: using System.ComponentModel;
4: using System.Data;
5: using System.Drawing;
6: using System.Linq;
7: using System.Text;
8: using System.Windows.Forms;
9: 10: namespace WindowsFormsApplication1
11: {12: public partial class Form1 : Form
13: {14: public Form1()
15: { 16: InitializeComponent(); 17: } 18: 19: private void button1_Click(object sender, EventArgs e)
20: {21: var Pilih = MessageBox.Show("Halo, Dunia!",
22: "Tombol YesNo",
23: MessageBoxButtons.YesNo, 24: MessageBoxIcon.Information);25: if (Pilih == DialogResult.Yes)
26: {27: MessageBox.Show("Tombol Yes di pilih");
28: }29: if (Pilih == DialogResult.No)
30: {31: MessageBox.Show("Tombol No di pilih");
32: } 33: } 34: } 35: }atau
1: using System;
2: using System.Collections.Generic;
3: using System.ComponentModel;
4: using System.Data;
5: using System.Drawing;
6: using System.Linq;
7: using System.Text;
8: using System.Windows.Forms;
9: 10: namespace WindowsFormsApplication1
11: {12: public partial class Form1 : Form
13: {14: public Form1()
15: { 16: InitializeComponent(); 17: } 18: 19: private void button1_Click(object sender, EventArgs e)
20: {21: var Pilih = MessageBox.Show("Halo, Dunia!",
22: "Tombol YesNo",
23: MessageBoxButtons.YesNo, 24: MessageBoxIcon.Information, 25: MessageBoxDefaultButton.Button1,26: MessageBoxOptions.RightAlign, true);
27: if (Pilih == DialogResult.Yes)
28: {29: MessageBox.Show("Tombol Yes di pilih");
30: }31: else
32: {33: MessageBox.Show("Tombol No di pilih");
34: } 35: } 36: } 37: }6. Tombol YesNoCancel
1: using System;
2: using System.Collections.Generic;
3: using System.ComponentModel;
4: using System.Data;
5: using System.Drawing;
6: using System.Linq;
7: using System.Text;
8: using System.Windows.Forms;
9: 10: namespace WindowsFormsApplication1
11: {12: public partial class Form1 : Form
13: {14: public Form1()
15: { 16: InitializeComponent(); 17: } 18: 19: private void button1_Click(object sender, EventArgs e)
20: {21: var Pilih = MessageBox.Show("Halo, Dunia!", "Tombol YesNoCancel", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information);
22: if (Pilih == DialogResult.Yes)
23: {24: MessageBox.Show("Tombol Yes di pilih");
25: }26: if (Pilih == DialogResult.No)
27: {28: MessageBox.Show("Tombol No di pilih");
29: }30: if (Pilih == DialogResult.Cancel)
31: {32: MessageBox.Show("Tombol Cancel di pilih");
33: } 34: } 35: } 36: }atau
1: using System;
2: using System.Collections.Generic;
3: using System.ComponentModel;
4: using System.Data;
5: using System.Drawing;
6: using System.Linq;
7: using System.Text;
8: using System.Windows.Forms;
9: 10: namespace WindowsFormsApplication1
11: {12: public partial class Form1 : Form
13: {14: public Form1()
15: { 16: InitializeComponent(); 17: } 18: 19: private void button1_Click(object sender, EventArgs e)
20: {21: const string message = "Halo, Dunia!";
22: const string caption = "Tombol YesNoCancel";
23: var Pilih = MessageBox.Show(message, 24: caption, 25: MessageBoxButtons.YesNoCancel, 26: MessageBoxIcon.Information, 27: MessageBoxDefaultButton.Button2, 28: MessageBoxOptions.RightAlign,29: true);
30: if (Pilih == DialogResult.Yes)
31: {32: MessageBox.Show("Tombol Yes di pilih");
33: }34: if (Pilih == DialogResult.No)
35: {36: MessageBox.Show("Tombol No di pilih");
37: }38: if (Pilih == DialogResult.Cancel)
39: {40: MessageBox.Show("Tombol Cancel di pilih");
41: } 42: } 43: } 44: }Label: C#.NET

0 Komentar:
Posting Komentar
Berlangganan Posting Komentar [Atom]
<< Beranda