combobox-groupbox-try-catch örneği C#
[code lang=”csharp”]
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;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBox1.SelectedIndex==0)
{
groupBox1.Visible = true;
}
else groupBox1.Visible = false;
}
private void Form1_Load(object sender, EventArgs e)
{
groupBox1.Visible = false;
}
private void button1_Click(object sender, EventArgs e)
{
string ad_soyad,tc_nu,okul_durumu,cinsiyet;
tc_nu = Convert.ToString(textBox2.Text);
ad_soyad = (textBox1.Text);
okul_durumu = comboBox2.Text;
cinsiyet = comboBox1.Text;
if ((tc_nu == ""))
{
try
{
throw new Exception();
}
catch (Exception)
{
MessageBox.Show("T.C. Numarasını Giriniz", "Dikkat");
}
}
if((ad_soyad == ""))
{
try
{
throw new Exception();
}
catch (Exception)
{
MessageBox.Show("Ad,Soyad Alanının Doldurulması Zorunludur","Dikkat");
}
}
if ((radioButton1.Checked==false) && (radioButton2.Checked==false))
{
try
{
throw new Exception();
}
catch (Exception)
{
MessageBox.Show ("Askerlik Durumu İşaretlenmelidir","Dikkat");
}
}
if ((cinsiyet == ""))
{
try
{
throw new Exception();
}
catch (Exception)
{
MessageBox.Show("Cinsiyet Seçilmelidir", "Dikkat");
}
}
if ((okul_durumu == ""))
{
try
{
throw new Exception();
}
catch (Exception)
{
MessageBox.Show("Okul Durumu Seçilmelidir", "Dikkat");
}
}
if ((tc_nu.Length<11)||(tc_nu.Length>11))
{
try
{
throw new Exception();
}
catch (Exception)
{
MessageBox.Show("T.C. Kimlik Numarası 11 Haneden Küçük veya Büyük Olamaz", "Dikkat");
}
}
else
{
MessageBox.Show("Kaydınız Başarıyla Tamamlandı", "Bilgi");
}
}
private void button2_Click(object sender, EventArgs e)
{
textBox1.Clear();
textBox2.Clear();
groupBox1.Visible = false;
}
}
}
[/code]
