C# KOD İLE BUTTON VE TEXTBOX OLUŞTURMAK
C# kod ile button ve textbox oluşturan ve buttona tıklayınca textbox kutusuna değer giren örnek uygulama.
Öncelikle button ve textboxlar global olarak oluşturulur.
Button button1 = new Button();
TextBox kutu1 = new TextBox();
Daha sonra Form_Load eventinde bu kontrollere ilişkin özellik ve event bildirimleri yapılır.
button1.Top = 60;
button1.Left = 90;
button1.Text="MESAJ";
button1.Click += new EventHandler(ButtonOlay);
this.Controls.Add(button1);
kutu1.Top = 120;
kutu1.Left = 150;
this.Controls.Add(kutu1);
buttonun click eventini biz yazacağız.
protected void ButtonOlay(object sender, EventArgs e)
{
kutu1.Text = "SANATSAL BILGI";
}
Uygulamanın tamamı
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 Kod_Ile_Btn
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Button button1 = new Button();
TextBox kutu1 = new TextBox();
private void Form1_Load(object sender, EventArgs e)
{
button1.Top = 60;
button1.Left = 90;
button1.Text="MESAJ";
button1.Click += new EventHandler(ButtonOlay);
this.Controls.Add(button1);
kutu1.Top = 120;
kutu1.Left = 150;
this.Controls.Add(kutu1);
}
protected void ButtonOlay(object sender, EventArgs e)
{
kutu1.Text = "SANATSAL BILGI";
}
}
}
SANATSAL BİLGİ
25/08/2016