Herkes için C#Programlama Eğitimi 23: DialogResult kullanımı

C# programlama dilinde ekrana bastırmak istediğimiz diyalog türüne göre işlem yaptırabiliriz. Bu kullanım türü DialogResult şeklinde karşımıza çıkmaktadır.
DialogResult kullanımında esas olan nokta önce yeni bir diyalog result nesnesi oluşturulması gerekliliğidir. Aşağıdaki örnekte hem nesnemizi hem de mesaj diyaloğumuzu diyalog isminde bir değişkene atadık.
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 WindowsFormsApp1
{
public partial class Form1 : Form
{
private Button dugme;
private TextBox metinKutusu;
public Form1()
{
InitializeComponent();
metinKutusu = new TextBox();
metinKutusu.AccessibleName = “İçerik yazın”;
metinKutusu.Size = new Size(120, 120);
metinKutusu.Location = new Point(60, 60);
this.Controls.Add(metinKutusu);

dugme = new Button();
dugme.Size = new Size(30, 30);
dugme.Location = new Point(40, 40);
dugme.AccessibleName = “Mesaj göster”;
dugme.Text = “Mesaj Göster”;
this.Controls.Add(dugme);
dugme.Click += new EventHandler(dugme_click);
}
private void dugme_click(object Sender, EventArgs e)
{
if (metinKutusu.Text.Contains(“merhaba”))
{
MessageBox.Show(“sisteme hoşgeldiniz”);
}

else
{
DialogResult dialog = new DialogResult();
dialog = MessageBox.Show(“Yanlış veri girişi”, “uyarı”, MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (dialog == DialogResult.Yes)
{
this.Close();
}

}
}
}
}


Uygulama Akademisi sitesinden daha fazla şey keşfedin

Subscribe to get the latest posts sent to your email.

Bir yanıt yazın