Çözüldü C# Kodlama hatası

Bu konu çözüldü olarak işaretlenmiştir. Çözülmediğini düşünüyorsanız konuyu rapor edebilirsiniz.

kodlayamadikabi

Femtopat
Katılım
28 Ekim 2020
Mesajlar
38
Merhaba arkadaşlar, kodlarım aşağıdaki gibi görünürde bir hata yok. Çalıştırdığım zaman ad soyad veya diğer kısımları boş bırakıyorum ve hata veriyor nasıl düzeltebilirim. Hatam tam olarak nerde?

Kod:
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;
using System.IO;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
string[] dersler = { "NESNE TABANLI PROGRAMLAMA", "GÖRSEL PROGRAMLAMA", "YAZILIM MİMARİLERİ", "MULTİMEDYA UYGULAMALARI", "BİLGİSAYAR DONANIMI" };
comboBox1.Items.AddRange(dersler);
}
Int32 vize;
Int32 final;
DialogResult kayit;
private void button1_Click(object sender, EventArgs e)
{

if (textBox1.Text == "")
{
MessageBox.Show("LÜTFEN ADINIZI GİRİNİZ ! ");
textBox1.Focus();
textBox1.BackColor = Color.Yellow;
}

if (textBox2.Text == "")
{
MessageBox.Show("LÜTFEN SOYADINIZI GİRİNİZ ! ");
textBox2.Focus();
textBox2.BackColor = Color.Yellow;
}

if (comboBox1.SelectedIndex == -1)
{
MessageBox.Show("LÜTFEN DERS SEÇİMİ YAPINIZ ! ");
}

vize = Convert.ToInt32(textBox3.Text);
final = Convert.ToInt32(textBox4.Text);
Int32 ort = Convert.ToInt32(vize * 0.4 + final * 0.6);

if (textBox3.Text == "")
{
MessageBox.Show("LÜTFEN VİZE NOTUNUZU GİRİNİZ ! ");
textBox3.Focus();
textBox3.BackColor = Color.Yellow;
}


if (textBox4.Text == "")
{
MessageBox.Show("LÜTFEN FİNAL NOTUNUZU GİRİNİZ ! ");
textBox4.Focus();
textBox4.BackColor = Color.Yellow;
}



if (vize+final < 0 || vize+final > 100)
{
MessageBox.Show("VİZE VEYA FİNAL NOTUNUZU YANLIŞ GİRDİNİZ!! \n LÜTFEN 0-100 ARASINDA BİR DEĞER GİRİNİZ!");
textBox3.Clear();
textBox4.Clear();
textBox3.Focus();
}
else
{
label6.Text = "ORTALAMA = " + ort;
}


kayit = MessageBox.Show(textBox1.Text + " " + textBox2.Text + " İSİMLİ ÖĞRENCİNİN BİLGİLERİ KAYDEDİLSİN Mİ ?", "KAYIT",
MessageBoxButtons.YesNo);

if (kayit == DialogResult.Yes)
{

StreamWriter yazdir;
yazdir = File.AppendText("bilgiler.txt");
yazdir.Write(textBox1.Text + " ");
yazdir.Write(textBox2.Text + " ");
yazdir.Write(comboBox1.SelectedItem + " ");
yazdir.Write(textBox3.Text + " ");
yazdir.Write(textBox4.Text + " ");
yazdir.WriteLine(label6.Text);

yazdir.Close();
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
textBox4.Clear();
label6.Text = "";
comboBox1.SelectedItem =null;
}
else
{
MessageBox.Show("KAYIT İŞLEMİNDEN VAZGEÇİLDİ");
}

}


private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar > 65 || e.KeyChar < 90 && e.KeyChar == 8)
{
e.Handled = false;
}
else
{
e.Handled = true;
}


if (e.KeyChar == 13)
textBox2.Focus();
}

private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar > 65 || e.KeyChar < 90 && e.KeyChar == 8)
{
e.Handled = false;
}
else
{
e.Handled = true;
}

if (e.KeyChar == 13)
comboBox1.Focus();
}

private void comboBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == 13)
textBox3.Focus();
}

private void textBox3_KeyPress(object sender, KeyPressEventArgs e)
{

if (e.KeyChar >= 45 && e.KeyChar <= 57 || e.KeyChar == 8)
{
e.Handled = false;
}
else
{
e.Handled = true;
}

if (e.KeyChar == 13)
textBox4.Focus();
}

private void textBox4_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar >= 45 && e.KeyChar <= 57 || e.KeyChar == 8)
{
e.Handled = false;
}
else
{
e.Handled = true;
}

if (e.KeyChar == 13)
button1.Focus();
}

private void textBox3_TextChanged(object sender, EventArgs e)
{

}

private void textBox4_TextChanged(object sender, EventArgs e)
{

}


}
}
 

Dosya Ekleri

  • form.png
    form.png
    3,9 KB · Görüntüleme: 192
Son düzenleyen: Moderatör:
Çözüm
Textler boşken elbette hata verecektir, hatalı olduğunuz kısım şu;

Textbox'ların kontrolünü formun load yordamında yapıyorsunuz. Load yordamı sadece form yüklenirken bir kere çalışır. Devamında textboxu boşaltır ya da uyarıyı dikkate almadan boş geçerseniz yine boş olan bir değeri atamaya çalışırsınız. Değer atamalarını kontrol bloklarının altına yapmanız gerekiyor.
Şöyle ki, butona bastığınızda kaydediyorsa eğer değerleri kontrolleri de oraya alın.
Bu size şunu kazandırır, kontrolü form açılışında yapmak yerine kontrolü kayıt yaparken sağlarsınız. Böylelikle kontrol blokları bir sefer değil, her kayıt esnasında çalışarak gerçek bir kontrol sağlar.

  1. TextBox kontrollerini, butonun click yordamı altında yapın, click yordamı altında kontrolleri sağladıktan sonra değer atamalarını yapın. Yani textbox boş değil ise ilgili texboxtaki veriyi ilgili değişkene atayın.
  2. Kontrolleri bir metod içerisinde tanımlayıp metodu farklı yerlerde farklı işlemlerde tekrar tekrar çağırabilirsiniz, metod tanımlaması yapıp metodu butonun click yordamında çağırın.
  3. Dönüştürme metodunu değiştirin, direk olarak dönüştürme kodu kullanmak her zaman çalışmaz, TryParse metodunu araştırın ve o şekilde dönüşüm yapın, hataları düzeltecektir.
Eğer sorunu hala çözemezseniz projeyi yükleyin biz bakalım ya da benimle [email protected] mail adresimden iletişime geçin.
Yazdığın kodu atabilir misin?
şu an düzelttim hata vermiyor görünürde ama hala aynı bos bırakıyorum textleri hata veriyor
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; using System.IO; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { string[] dersler = { "NESNE TABANLI PROGRAMLAMA", "GÖRSEL PROGRAMLAMA", "YAZILIM MİMARİLERİ", "MULTİMEDYA UYGULAMALARI", "BİLGİSAYAR DONANIMI" }; comboBox1.Items.AddRange(dersler); } Int32 vize; Int32 final; DialogResult kayit; private void button1_Click(object sender, EventArgs e) { if (textBox1.Text == "") { MessageBox.Show("LÜTFEN ADINIZI GİRİNİZ ! "); textBox1.Focus(); textBox1.BackColor = Color.Yellow; } if (textBox2.Text == "") { MessageBox.Show("LÜTFEN SOYADINIZI GİRİNİZ ! "); textBox2.Focus(); textBox2.BackColor = Color.Yellow; } if (comboBox1.SelectedIndex == -1) { MessageBox.Show("LÜTFEN DERS SEÇİMİ YAPINIZ ! "); } if (textBox3.Text == "") { MessageBox.Show("LÜTFEN VİZE NOTUNUZU GİRİNİZ ! "); textBox3.Focus(); textBox3.BackColor = Color.Yellow; } if (textBox4.Text == "") { MessageBox.Show("LÜTFEN FİNAL NOTUNUZU GİRİNİZ ! "); textBox4.Focus(); textBox4.BackColor = Color.Yellow; } vize = Int32.Parse(textBox3.Text); final = Int32.Parse(textBox4.Text); Int32 ort = Convert.ToInt32(vize * 0.4 + final * 0.6); if (vize + final < 0 || vize + final > 100) { MessageBox.Show("VİZE VEYA FİNAL NOTUNUZU YANLIŞ GİRDİNİZ!! \n LÜTFEN 0-100 ARASINDA BİR DEĞER GİRİNİZ!"); textBox3.Clear(); textBox4.Clear(); textBox3.Focus(); } else { label6.Text = "ORTALAMA = " + ort; } kayit = MessageBox.Show(textBox1.Text + " " + textBox2.Text + " İSİMLİ ÖĞRENCİNİN BİLGİLERİ KAYDEDİLSİN Mİ ?", "KAYIT", MessageBoxButtons.YesNo); if (kayit == DialogResult.Yes) { StreamWriter yazdir; yazdir = File.AppendText("bilgiler.txt"); yazdir.Write(textBox1.Text + " "); yazdir.Write(textBox2.Text + " "); yazdir.Write(comboBox1.SelectedItem + " "); yazdir.Write(textBox3.Text + " "); yazdir.Write(textBox4.Text + " "); yazdir.WriteLine(label6.Text); yazdir.Close(); textBox1.Clear(); textBox2.Clear(); textBox3.Clear(); textBox4.Clear(); label6.Text = ""; comboBox1.SelectedItem = null; } else { MessageBox.Show("KAYIT İŞLEMİNDEN VAZGEÇİLDİ"); } } private void textBox1_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar > 65 || e.KeyChar < 90 && e.KeyChar == 8) { e.Handled = false; } else { e.Handled = true; } if (e.KeyChar == 13) textBox2.Focus(); } private void textBox2_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar > 65 || e.KeyChar < 90 && e.KeyChar == 8) { e.Handled = false; } else { e.Handled = true; } if (e.KeyChar == 13) comboBox1.Focus(); } private void comboBox1_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == 13) textBox3.Focus(); } private void textBox3_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar >= 45 && e.KeyChar <= 57 || e.KeyChar == 8) { e.Handled = false; } else { e.Handled = true; } if (e.KeyChar == 13) textBox4.Focus(); } private void textBox4_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar >= 45 && e.KeyChar <= 57 || e.KeyChar == 8) { e.Handled = false; } else { e.Handled = true; } if (e.KeyChar == 13) button1.Focus(); } } } [QUOTE="battaniye, post: 7698531, member: 290025"] Yazdığın kodu atabilir misin? [/QUOTE] az once verdiği hatayı düzelttim ama şimdi calıstırdıgımda textleri bos bırakıyorum hala aynı hatayı veriyor 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; using System.IO; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { string[] dersler = { "NESNE TABANLI PROGRAMLAMA", "GÖRSEL PROGRAMLAMA", "YAZILIM MİMARİLERİ", "MULTİMEDYA UYGULAMALARI", "BİLGİSAYAR DONANIMI" }; comboBox1.Items.AddRange(dersler); } Int32 vize; Int32 final; DialogResult kayit; private void button1_Click(object sender, EventArgs e) { if (textBox1.Text == "") { MessageBox.Show("LÜTFEN ADINIZI GİRİNİZ ! "); textBox1.Focus(); textBox1.BackColor = Color.Yellow; } if (textBox2.Text == "") { MessageBox.Show("LÜTFEN SOYADINIZI GİRİNİZ ! "); textBox2.Focus(); textBox2.BackColor = Color.Yellow; } if (comboBox1.SelectedIndex == -1) { MessageBox.Show("LÜTFEN DERS SEÇİMİ YAPINIZ ! "); } if (textBox3.Text == "") { MessageBox.Show("LÜTFEN VİZE NOTUNUZU GİRİNİZ ! "); textBox3.Focus(); textBox3.BackColor = Color.Yellow; } if (textBox4.Text == "") { MessageBox.Show("LÜTFEN FİNAL NOTUNUZU GİRİNİZ ! "); textBox4.Focus(); textBox4.BackColor = Color.Yellow; } vize = Int32.Parse(textBox3.Text); final = Int32.Parse(textBox4.Text); Int32 ort = Convert.ToInt32(vize * 0.4 + final * 0.6); if (vize + final < 0 || vize + final > 100) { MessageBox.Show("VİZE VEYA FİNAL NOTUNUZU YANLIŞ GİRDİNİZ!! \n LÜTFEN 0-100 ARASINDA BİR DEĞER GİRİNİZ!"); textBox3.Clear(); textBox4.Clear(); textBox3.Focus(); } else { label6.Text = "ORTALAMA = " + ort; } kayit = MessageBox.Show(textBox1.Text + " " + textBox2.Text + " İSİMLİ ÖĞRENCİNİN BİLGİLERİ KAYDEDİLSİN Mİ ?", "KAYIT", MessageBoxButtons.YesNo); if (kayit == DialogResult.Yes) { StreamWriter yazdir; yazdir = File.AppendText("bilgiler.txt"); yazdir.Write(textBox1.Text + " "); yazdir.Write(textBox2.Text + " "); yazdir.Write(comboBox1.SelectedItem + " "); yazdir.Write(textBox3.Text + " "); yazdir.Write(textBox4.Text + " "); yazdir.WriteLine(label6.Text); yazdir.Close(); textBox1.Clear(); textBox2.Clear(); textBox3.Clear(); textBox4.Clear(); label6.Text = ""; comboBox1.SelectedItem = null; } else { MessageBox.Show("KAYIT İŞLEMİNDEN VAZGEÇİLDİ"); } } private void textBox1_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar > 65 || e.KeyChar < 90 && e.KeyChar == 8) { e.Handled = false; } else { e.Handled = true; } if (e.KeyChar == 13) textBox2.Focus(); } private void textBox2_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar > 65 || e.KeyChar < 90 && e.KeyChar == 8) { e.Handled = false; } else { e.Handled = true; } if (e.KeyChar == 13) comboBox1.Focus(); } private void comboBox1_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == 13) textBox3.Focus(); } private void textBox3_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar >= 45 && e.KeyChar <= 57 || e.KeyChar == 8) { e.Handled = false; } else { e.Handled = true; } if (e.KeyChar == 13) textBox4.Focus(); } private void textBox4_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar >= 45 && e.KeyChar <= 57 || e.KeyChar == 8) { e.Handled = false; } else { e.Handled = true; } if (e.KeyChar == 13) button1.Focus(); } } [CODE]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; using System.IO; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { string[] dersler = { "NESNE TABANLI PROGRAMLAMA", "GÖRSEL PROGRAMLAMA", "YAZILIM MİMARİLERİ", "MULTİMEDYA UYGULAMALARI", "BİLGİSAYAR DONANIMI" }; comboBox1.Items.AddRange(dersler); } Int32 vize; Int32 final; DialogResult kayit; private void button1_Click(object sender, EventArgs e) { if (textBox1.Text == "") { MessageBox.Show("LÜTFEN ADINIZI GİRİNİZ ! "); textBox1.Focus(); textBox1.BackColor = Color.Yellow; } if (textBox2.Text == "") { MessageBox.Show("LÜTFEN SOYADINIZI GİRİNİZ ! "); textBox2.Focus(); textBox2.BackColor = Color.Yellow; } if (comboBox1.SelectedIndex == -1) { MessageBox.Show("LÜTFEN DERS SEÇİMİ YAPINIZ ! "); } if (textBox3.Text == "") { MessageBox.Show("LÜTFEN VİZE NOTUNUZU GİRİNİZ ! "); textBox3.Focus(); textBox3.BackColor = Color.Yellow; } if (textBox4.Text == "") { MessageBox.Show("LÜTFEN FİNAL NOTUNUZU GİRİNİZ ! "); textBox4.Focus(); textBox4.BackColor = Color.Yellow; } vize = Int32.Parse(textBox3.Text); final = Int32.Parse(textBox4.Text); Int32 ort = Convert.ToInt32(vize * 0.4 + final * 0.6); if (vize + final < 0 || vize + final > 100) { MessageBox.Show("VİZE VEYA FİNAL NOTUNUZU YANLIŞ GİRDİNİZ!! \n LÜTFEN 0-100 ARASINDA BİR DEĞER GİRİNİZ!"); textBox3.Clear(); textBox4.Clear(); textBox3.Focus(); } else { label6.Text = "ORTALAMA = " + ort; } kayit = MessageBox.Show(textBox1.Text + " " + textBox2.Text + " İSİMLİ ÖĞRENCİNİN BİLGİLERİ KAYDEDİLSİN Mİ ?", "KAYIT", MessageBoxButtons.YesNo); if (kayit == DialogResult.Yes) { StreamWriter yazdir; yazdir = File.AppendText("bilgiler.txt"); yazdir.Write(textBox1.Text + " "); yazdir.Write(textBox2.Text + " "); yazdir.Write(comboBox1.SelectedItem + " "); yazdir.Write(textBox3.Text + " "); yazdir.Write(textBox4.Text + " "); yazdir.WriteLine(label6.Text); yazdir.Close(); textBox1.Clear(); textBox2.Clear(); textBox3.Clear(); textBox4.Clear(); label6.Text = ""; comboBox1.SelectedItem = null; } else { MessageBox.Show("KAYIT İŞLEMİNDEN VAZGEÇİLDİ"); } } private void textBox1_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar > 65 || e.KeyChar < 90 && e.KeyChar == 8) { e.Handled = false; } else { e.Handled = true; } if (e.KeyChar == 13) textBox2.Focus(); } private void textBox2_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar > 65 || e.KeyChar < 90 && e.KeyChar == 8) { e.Handled = false; } else { e.Handled = true; } if (e.KeyChar == 13) comboBox1.Focus(); } private void comboBox1_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == 13) textBox3.Focus(); } private void textBox3_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar >= 45 && e.KeyChar <= 57 || e.KeyChar == 8) { e.Handled = false; } else { e.Handled = true; } if (e.KeyChar == 13) textBox4.Focus(); } private void textBox4_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar >= 45 && e.KeyChar <= 57 || e.KeyChar == 8) { e.Handled = false; } else { e.Handled = true; } if (e.KeyChar == 13) button1.Focus(); } } } Yazdığın kodu atabilir misin? az once verdiği hatayı düzelttim ama şimdi calıstırdıgımda textleri bos bırakıyorum hala aynı hatayı veriyor 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; using System.IO; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { string[] dersler = { "NESNE TABANLI PROGRAMLAMA", "GÖRSEL PROGRAMLAMA", "YAZILIM MİMARİLERİ", "MULTİMEDYA UYGULAMALARI", "BİLGİSAYAR DONANIMI" }; comboBox1.Items.AddRange(dersler); } Int32 vize; Int32 final; DialogResult kayit; private void button1_Click(object sender, EventArgs e) { if (textBox1.Text == "") { MessageBox.Show("LÜTFEN ADINIZI GİRİNİZ ! "); textBox1.Focus(); textBox1.BackColor = Color.Yellow; } if (textBox2.Text == "") { MessageBox.Show("LÜTFEN SOYADINIZI GİRİNİZ ! "); textBox2.Focus(); textBox2.BackColor = Color.Yellow; } if (comboBox1.SelectedIndex == -1) { MessageBox.Show("LÜTFEN DERS SEÇİMİ YAPINIZ ! "); } if (textBox3.Text == "") { MessageBox.Show("LÜTFEN VİZE NOTUNUZU GİRİNİZ ! "); textBox3.Focus(); textBox3.BackColor = Color.Yellow; } if (textBox4.Text == "") { MessageBox.Show("LÜTFEN FİNAL NOTUNUZU GİRİNİZ ! "); textBox4.Focus(); textBox4.BackColor = Color.Yellow; } vize = Int32.Parse(textBox3.Text); final = Int32.Parse(textBox4.Text); Int32 ort = Convert.ToInt32(vize * 0.4 + final * 0.6); if (vize + final < 0 || vize + final > 100) { MessageBox.Show("VİZE VEYA FİNAL NOTUNUZU YANLIŞ GİRDİNİZ!! \n LÜTFEN 0-100 ARASINDA BİR DEĞER GİRİNİZ!"); textBox3.Clear(); textBox4.Clear(); textBox3.Focus(); } else { label6.Text = "ORTALAMA = " + ort; } kayit = MessageBox.Show(textBox1.Text + " " + textBox2.Text + " İSİMLİ ÖĞRENCİNİN BİLGİLERİ KAYDEDİLSİN Mİ ?", "KAYIT", MessageBoxButtons.YesNo); if (kayit == DialogResult.Yes) { StreamWriter yazdir; yazdir = File.AppendText("bilgiler.txt"); yazdir.Write(textBox1.Text + " "); yazdir.Write(textBox2.Text + " "); yazdir.Write(comboBox1.SelectedItem + " "); yazdir.Write(textBox3.Text + " "); yazdir.Write(textBox4.Text + " "); yazdir.WriteLine(label6.Text); yazdir.Close(); textBox1.Clear(); textBox2.Clear(); textBox3.Clear(); textBox4.Clear(); label6.Text = ""; comboBox1.SelectedItem = null; } else { MessageBox.Show("KAYIT İŞLEMİNDEN VAZGEÇİLDİ"); } } private void textBox1_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar > 65 || e.KeyChar < 90 && e.KeyChar == 8) { e.Handled = false; } else { e.Handled = true; } if (e.KeyChar == 13) textBox2.Focus(); } private void textBox2_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar > 65 || e.KeyChar < 90 && e.KeyChar == 8) { e.Handled = false; } else { e.Handled = true; } if (e.KeyChar == 13) comboBox1.Focus(); } private void comboBox1_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == 13) textBox3.Focus(); } private void textBox3_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar >= 45 && e.KeyChar <= 57 || e.KeyChar == 8) { e.Handled = false; } else { e.Handled = true; } if (e.KeyChar == 13) textBox4.Focus(); } private void textBox4_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar >= 45 && e.KeyChar <= 57 || e.KeyChar == 8) { e.Handled = false; } else { e.Handled = true; } if (e.KeyChar == 13) button1.Focus(); } } }[/CODE]
 
Son düzenleyen: Moderatör:
Textler boşken elbette hata verecektir, hatalı olduğunuz kısım şu;

Textbox'ların kontrolünü formun load yordamında yapıyorsunuz. Load yordamı sadece form yüklenirken bir kere çalışır. Devamında textboxu boşaltır ya da uyarıyı dikkate almadan boş geçerseniz yine boş olan bir değeri atamaya çalışırsınız. Değer atamalarını kontrol bloklarının altına yapmanız gerekiyor.
Şöyle ki, butona bastığınızda kaydediyorsa eğer değerleri kontrolleri de oraya alın.
Bu size şunu kazandırır, kontrolü form açılışında yapmak yerine kontrolü kayıt yaparken sağlarsınız. Böylelikle kontrol blokları bir sefer değil, her kayıt esnasında çalışarak gerçek bir kontrol sağlar.

  1. TextBox kontrollerini, butonun click yordamı altında yapın, click yordamı altında kontrolleri sağladıktan sonra değer atamalarını yapın. Yani textbox boş değil ise ilgili texboxtaki veriyi ilgili değişkene atayın.
  2. Kontrolleri bir metod içerisinde tanımlayıp metodu farklı yerlerde farklı işlemlerde tekrar tekrar çağırabilirsiniz, metod tanımlaması yapıp metodu butonun click yordamında çağırın.
  3. Dönüştürme metodunu değiştirin, direk olarak dönüştürme kodu kullanmak her zaman çalışmaz, TryParse metodunu araştırın ve o şekilde dönüşüm yapın, hataları düzeltecektir.
Eğer sorunu hala çözemezseniz projeyi yükleyin biz bakalım ya da benimle [email protected] mail adresimden iletişime geçin.
 
Çözüm
Textler boşken elbette hata verecektir, hatalı olduğunuz kısım şu;

Textbox'ların kontrolünü formun load yordamında yapıyorsunuz. Load yordamı sadece form yüklenirken bir kere çalışır. Devamında textboxu boşaltır ya da uyarıyı dikkate almadan boş geçerseniz yine boş olan bir değeri atamaya çalışırsınız. Değer atamalarını kontrol bloklarının altına yapmanız gerekiyor.
Şöyle ki, butona bastığınızda kaydediyorsa eğer değerleri kontrolleri de oraya alın.
Bu size şunu kazandırır, kontrolü form açılışında yapmak yerine kontrolü kayıt yaparken sağlarsınız. Böylelikle kontrol blokları bir sefer değil, her kayıt esnasında çalışarak gerçek bir kontrol sağlar.

  1. TextBox kontrollerini, butonun Click yordamı altında yapın, Click yordamı altında kontrolleri sağladıktan sonra değer atamalarını yapın. Yani textbox boş değil ise ilgili texboxtaki veriyi ilgili değişkene atayın.
  2. Kontrolleri bir metot içerisinde tanımlayıp metodu farklı yerlerde farklı işlemlerde tekrar tekrar çağırabilirsiniz, metot tanımlaması yapıp metodu butonun Click yordamında çağırın.
  3. Dönüştürme metodunu değiştirin, direk olarak dönüştürme kodu kullanmak her zaman çalışmaz, TryParse metodunu araştırın ve o şekilde dönüşüm yapın, hataları düzeltecektir.
Eğer sorunu hala çözemezseniz projeyi yükleyin biz bakalım ya da benimle [email protected] mail adresimden iletişime geçin.

Çok teşekkür ederim hallettim sorunu. :)
 
Uyarı! Bu konu 5 yıl önce açıldı.
Muhtemelen daha fazla tartışma gerekli değildir ki bu durumda yeni bir konu başlatmayı öneririz. Eğer yine de cevabınızın gerekli olduğunu düşünüyorsanız buna rağmen cevap verebilirsiniz.

Technopat Haberler

Geri
Yukarı