C#-da 1 neçə button üçün yazılmış button

Bir neçə button eyni işi görür her defe click`lerine onu yazdıqda çox uzun olur buttonların sayı artıdqca. necə bir metod yaza bilerem ki, hər button klik olunduqda özünəməxsus yerinə yetirsin metodu.

sadə misalla izah edim fikrimiki aydın olsun: məsələn adicə calculator yazsaq reqemlere gore deyishir button`lar, amma toplamada çıxmada eyni funksiyanı yerində yetirir. bir metod yazıb hər rəqəm üçün onu çağırmaq olar?


Yadda saxlama
Kateqoriya: Sual . , . Qısa keçid.

Verilmiş cavablar və yazılan şərhlər (4 cavab var)

(17:12, 27/11/2012 ) #23174

Əgər sualıvı düzgün başa düşdümsə bu cür edə bilərsən.
Bu cür aydın olmadısa kodları upload edə bilərəm.

1using System;
2using System.Windows.Forms;
3 
4namespace cavablarNet
5{
6    public partial class Form1 : Form
7    {
8        public Form1()
9        {
10            InitializeComponent();
11            this.button1 = new System.Windows.Forms.Button();
12            this.button2 = new System.Windows.Forms.Button();
13            //
14            // button1
15            //
16            this.button1.Location = new System.Drawing.Point(29, 121);
17            this.button1.Name = "button1";
18            this.button1.Size = new System.Drawing.Size(75, 23);
19            this.button1.TabIndex = 0;
20            this.button1.Text = "button1";
21            this.button1.UseVisualStyleBackColor = true;
22            this.button1.Click += new System.EventHandler(this.button1_Click);
23            //
24            // button2
25            //
26            this.button2.Location = new System.Drawing.Point(156, 121);
27            this.button2.Name = "button2";
28            this.button2.Size = new System.Drawing.Size(75, 23);
29            this.button2.TabIndex = 1;
30            this.button2.Text = "button2";
31            this.button2.UseVisualStyleBackColor = true;
32             
33            //  button1`dən başqa klik olunarsa
34            /***/
35            this.button2.Click += new System.EventHandler(this.button1_Click);
36            /****/
37            this.Controls.Add(this.button2);
38            this.Controls.Add(this.button1);
39        }
40 
41        private void button1_Click(object sender, EventArgs e)
42        {
43            Button btn = sender as Button; //get the button that was clicked
44            MessageBox.Show("Bu button klikləndi" + " " + btn.Text);
45        }
46 
47       
48 
49        public Button button1 { get; set; }
50 
51        public Button button2 { get; set; }
52    }
53}
Cavablamaq üçün sağ sütundan hesaba daxil olmaq lazımdır

(09:30, 03/12/2012 ) #23381
1using System;
2using System.Windows.Forms;
3 
4namespace winOwn
5{
6    public partial class Form1 : Form
7    {
8        public Form1()
9        {
10            InitializeComponent();
11        }
12 
13        private void Form1_Load(object sender, EventArgs e)
14       {
15            b1.Text = "A.A";
16            b2.Text = "A.A";
17          }
18        int s = 0 ;
19 int k = 1;
20        private void b1_Click(object sender, EventArgs e)
21        {
22            if(k==1)
23            {
24            b1.Text="E";
25            }
26            else if (k == 2)
27            {
28                b1.Text = "S";
29            }
30            else
31            { b1.Text = "X"; }
32        }
33        private void b2_Click(object sender, EventArgs e)
34        {
35            if (k == 1)
36            {
37                b2.Text = "E";
38            }
39            else if (k == 2)
40            {
41                b2.Text = "S";
42            }
43            else
44            { b2.Text = "X"; }
45        }
46}

burada iki button deyil 30 yaxın button olarsa necə?

Cavablamaq üçün sağ sütundan hesaba daxil olmaq lazımdır

    (10:22, 03/12/2012 ) #23383

    Siz hansı button`a clikc olunduğunu nəzərə alıb yuxarda yazdığıvız if-else bolkunu istifadə edə bilərsiz.
    Form`a 3 dənə button və 1 dənə textbox atdıq daha sonra aşağdakı kodları əlavə et

    1            public Form1()
    2        {
    3            InitializeComponent();
    4            this.button2.Click += new System.EventHandler(this.button1_Click);
    5            this.button3.Click += new System.EventHandler(this.button1_Click);
    6            this.button1.Click += new System.EventHandler(this.button1_Click);
    7           
    8        }
    9 
    10private void button1_Click(object sender, EventArgs e)
    11        {
    12            Button btn = sender as Button;
    13            textBox1.Text = btn.Text; // mən textbox`a mənimsətdim nəticə görünsün diyə
    14            
    15        }

    Button1 click etdikdə textbox.text`inə hansı buttona click`lənibsə onun adı gələcək.

    Əgər btn.Text=button1(button2,button3 və s.) onda hər buttona ait kodları işlət.

    Cavablamaq üçün sağ sütundan hesaba daxil olmaq lazımdır

(16:33, 03/12/2012 ) #23394

Təşəkkürlər, uzun uzadı kod hissəsini bir neçə sətirlə əvəz elədim 🙂

Cavablamaq üçün sağ sütundan hesaba daxil olmaq lazımdır

Bu suala aid öz sualım var:
Sual verin
Bu suala cavab vermək istəyirəm:
Cavab verin

Cavab verin


Cavab yazmaq üçün lütfən sağ sütundan və ya buradan hesaba daxil olun.

Üzvlər üçün giriş

Qeydiyyat

Elan qutusu

Son cavablar və şərhlər

E. Hacı cavab verdi - Elektron servis xidmətləri (10 gün əvvəl)

cavaninsan cavab verdi - Amerika səhmləri (19 gün əvvəl)

Software Developer cavab verdi - Amerika səhmləri (19 gün əvvəl)

SN cavab verdi - Kripto vergi (28 gün əvvəl)

Nicat97 cavab verdi - ilkaddimlar.com-a nə oldu? (35 gün əvvəl)

nicatmemmedli cavab verdi - Proqramlaşdırma - fəlsəfə (39 gün əvvəl)

nicatmemmedli cavab verdi - ilkaddimlar.com-a nə oldu? (39 gün əvvəl)

Software Developer cavab verdi - ilkaddimlar.com-a nə oldu? (49 gün əvvəl)

E. Hacı cavab verdi - Adsense ya görə VÖEN gəlir vergisi 20% istəyirlər (58 gün əvvəl)

Triste cavab verdi - Adsense ya görə VÖEN gəlir vergisi 20% istəyirlər (60 gün əvvəl)

E. Hacı cavab verdi - Adsense ya görə VÖEN gəlir vergisi 20% istəyirlər (60 gün əvvəl)

Triste cavab verdi - Adsense ya görə VÖEN gəlir vergisi 20% istəyirlər (60 gün əvvəl)

E. Hacı cavab verdi - Telefon almışam kamerasında ləkə var qaytarmaq istəyirəm, mağaza qaytarmır (60 gün əvvəl)

Software Developer cavab verdi - Rus dili yatırımı (61 gün əvvəl)

Cənab cavab verdi - Rus dili yatırımı (61 gün əvvəl)

Software Developer - 615 xal

E. Hacı - 608 xal

Onar Alili - 526 xal

Dilsuz - 448 xal

Cabbarov Sübhan - 434 xal

Maqa - 346 xal

Ruslan Butdayev - 328 xal

Namiq Bəndəli - 297 xal

U.Tarlan - 244 xal

Meherremoff - 234 xal

Sistemə daxil olmuş 23309 sualdan 92%-dən çoxu cavablandırılmışdır.

Proyekt haqqında

E-Haci.net istehsalı. © 2010-2025