• Web sitemizin içeriğine ve tüm hizmetlerimize erişim sağlamak için Web sitemize kayıt olmalı ya da giriş yapmalısınız. Web sitemize üye olmak tamamen ücretsizdir.
  • Sohbetokey.com ile canlı okey oynamaya ne dersin? Hem sohbet et, hem mobil okey oyna!
  • Soru mu? Sorun mu? ''Bir Sorum Var?'' sistemimiz aktiftir. Paylaşın beraber çözüm üretelim.

Arası Kontrollerin Yönetimi ve Formlar Arası TextBox Kontrolü

Üyelik Tarihi
7 Ocak 2015
Konular
4,091
Mesajlar
4,274
MFC Puanı
40
Kod:
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 formlar_arasinda_islemler_form_kontrolleri
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        public static TextBox textbox = null;

        private **** button_formu_ac_Click(object sender, EventArgs e)
        {
            FormNumaralar formnumaralar = new FormNumaralar();
            formnumaralar.ShowDialog();
        }

        private **** Form1_Load(object sender, EventArgs e)
        {
            textbox = new TextBox();
            textbox.TextChanged += new EventHandler(textbox_TextChanged);
        }

        public **** textbox_TextChanged(object sender, EventArgs e)
        {
            textBox_girilen_numaralar.Text = (sender as TextBox).Text;
        }

 

    }
}

Form1 programı çalıştırdığımızda açılacak formdur. Bu form üzerinde numaraları aç butonuna tıklandığında ikinci formumuz açılacak. Bu formun ismi de FormNumaralar olsun. Bu form 0 ile 9 arasındaki rakamları gösteren 10 tane buton, bir tane sil butonu ve bir tane de kapat butonundan oluşmakta. FormNumaralar formunda yapılan işlemler yani her basılan butonun text değerini ana formumuz (Form1) üzerindeki textbox da gösterebilmek için ana formumuzdaki Textbox Nesnesini statik ve public olarak tanımladık.


 public static TextBox textbox = null;

Böylece FormNumaralar formunda bu textbox aşağıdaki gibi yazarak ulaşmış olacağız.


Form1.textbox.Text += (sender as Button).Text;

Yaptığımız bütün değişikleri anında ana formdaki private olarak sürükle bırak şeklinde yerleştirdiğimiz textbox (bu textbox ın ismini textBox_girilen_numaralar olarak atadım) da görmüş olacağız. Bunu da static textbox ın textbox_TextChanged olayında bütün değişikliği aynen ana formdaki textbox ın Text özelliğine eşitliyoruz. Böylece farklı iki form arasındaki buton kontrollerinin Text değerlerini diğer formdaki textbox değerine atamış oluyoruz.



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 formlar_arasinda_islemler_form_kontrolleri
{

    public partial class FormNumaralar : Form
    {
        public FormNumaralar()
        {
            InitializeComponent();
        }

        private **** button_kapat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private **** butonlar_click(object sender, EventArgs e)
        {
            if (!(sender as Button).Text.Equals("Sil"))
                Form1.textbox.Text += (sender as Button).Text;
            else
                if (Form1.textbox.Text.Length > 0)
                    Form1.textbox.Text = Form1.textbox.Text.Substring(0, Form1.textbox.Text.Length - 1);
        }

    }
}
 
Üst