C#'da Class'a panel ekleme

GOFRET001

Femtopat
Katılım
27 Haziran 2022
Mesajlar
13
Daha fazla  
Cinsiyet
Erkek
Merhaba arkadaşlar, ben C# ile program yapıyorum ve sorum şu şimdi ben programımda çok fazla panel kullandığım için hepsini ayarlamak zor oluyor tek designer üzerinde o yüzden şöyle bir çözüm düşündüm;

Class oluşturucaz classın içine panelimiz ekliyeceğiz ve aynı form düzenler gibi panelimizide düzenleyeceğiz
Ve forma geldiğimizde butona basınca bize panleli görüntüleyecek.

Bunu nasıl yapabilirim?
 
Panelin kendisi bi sınıf zaten. Yine de şu aşağıda attığımı biraz incele. Panel değilde button olarak yapmıştım.
C#:
namespace WinFormsApp1
{

    public partial class Form1 : Form
    {

        working[] dnm = new working[200];
        bool b = false;
        Button[] bt = new Button[200];
        int[] removedIndex = new int[200];
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.Text = "";
            deneme();
            this.BackColor = Color.Black;
        }

        private void Btn(object sender, EventArgs e)
        {
            Button btn1 = (sender as Button);
            int index = bt.findIndex(btn1);
            switch (dnm[index].returnWorking())
            {
                case true:
                    dnm[index].setWorking(false);
                    bt[index].BackColor = Color.Red;
                    break;
                case false:
                    dnm[index].setWorking(true);
                    bt[index].BackColor = Color.Green;
                    break;
            }
          
            
        }
        private void deneme()
        {
            int i = 1;
           for (int l = 0, y = 0; l < 8; l++, y += 55)
            {
                for (int x = 0, j = 0; j < 10; x += 80, j++ ,i++)
                {
                    dnm[i] = new working(b, i);
                    bt[i] = new Button();
                    bt[i].BackColor = Color.Red;
                    bt[i].FlatStyle = FlatStyle.Flat;
                    bt[i].ForeColor = Color.White;
                    bt[i].Text = "button" + i;
                    bt[i].Size = new Size(75, 50);
                    bt[i].Location = new Point(12 + x, 12 + y);
                    bt[i].Click += new EventHandler(Btn);
                    this.Controls.Add(bt[i]);
                }
            }

        }

        private void button1_Click(object sender, EventArgs e)
        {
            for(int i = 1, j = 0; i <= 80; i++, j++)
            {
                dnm[i].setVisible(bt[i], button1);
            }
        }

        private void Form1_SizeChanged(object sender, EventArgs e)
        {
            this.Text = this.Size.Width.ToString() + "x" + this.Size.Height.ToString();
        }

      
    }
    public class working
    {
        bool b = false;
        bool visible = true;
        int i;
        public working(bool b, int i)
        {
            this.b = b;
            this.i = i;
        }

        public void setVisible(Button button, Button Changer)
        {
            if(!b && visible)
            {
                Changer.Text = "Show Reds";
                visible = false;
                button.Visible = false;
            }
            else
            {
                Changer.Text = "Hide Reds";
                visible = true;
                button.Visible = true;
            }
        }

        public void setWorking(bool b)
        {
            this.b = b;
        }

        public bool returnWorking()
        {
            return this.b;
        }
    }
    public static class Extensions
    {
        public static int findIndex<T>(this T[] array, T item)
        {
            return Array.IndexOf(array, item);
        }
    }
    
}
 

Technopat Haberler

Geri
Yukarı