如何一键更改属性

发布于 2025-01-10 06:24:05 字数 848 浏览 1 评论 0原文

嘿, 我有多个按钮。我想减少代码,以便可以设置按钮的属性,但只有我单击的按钮会更改。这样我就不会单击button_1并更改所有其他按钮

 public static void SetProp()
        {
            for (int i = 0; i < buttons.Count; i++)
            {
                buttons[i].Image = Properties.Resources.test;
                buttons[i].Width = buttons[i].Image.Width;
                buttons[i].Height = buttons[i].Image.Height;
                buttons[i].ImageAlign = ContentAlignment.MiddleCenter;
                buttons[i].Text = null;
                GraphicsPath gp = new GraphicsPath();
                gp.AddEllipse(0, 0, buttons[i].Width, buttons[i].Height);
                buttons[i].Region = new Region(gp);
                gp.Dispose();
            }
        }
   private void button1_Click(object sender, EventArgs e)
        {
            SetProp();
          

        }

Hey,
I have multiple buttons.I want to reduce the code so that I can set the properties of a button, but only the one I click on will change.So that I don't click on button_1 and change all the others

 public static void SetProp()
        {
            for (int i = 0; i < buttons.Count; i++)
            {
                buttons[i].Image = Properties.Resources.test;
                buttons[i].Width = buttons[i].Image.Width;
                buttons[i].Height = buttons[i].Image.Height;
                buttons[i].ImageAlign = ContentAlignment.MiddleCenter;
                buttons[i].Text = null;
                GraphicsPath gp = new GraphicsPath();
                gp.AddEllipse(0, 0, buttons[i].Width, buttons[i].Height);
                buttons[i].Region = new Region(gp);
                gp.Dispose();
            }
        }
   private void button1_Click(object sender, EventArgs e)
        {
            SetProp();
          

        }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

隱形的亼 2025-01-17 06:24:05
 public static void SetProp(Button button)
        {
            for (int i = 0; i < buttons.Count; i++)
            {
                button.Image = Properties.Resources.test;
                button.Width = buttons[i].Image.Width;
                button.Height = buttons[i].Image.Height;
                button.ImageAlign = ContentAlignment.MiddleCenter;
                button.Text = null;
                GraphicsPath gp = new GraphicsPath();
                gp.AddEllipse(0, 0, button.Width, button.Height);
                button.Region = new Region(gp);
                gp.Dispose();
            }
        }
 private void button1_Click(object sender, EventArgs e)
        {
            SetProp(sender as Button);
           
          
        }
 public static void SetProp(Button button)
        {
            for (int i = 0; i < buttons.Count; i++)
            {
                button.Image = Properties.Resources.test;
                button.Width = buttons[i].Image.Width;
                button.Height = buttons[i].Image.Height;
                button.ImageAlign = ContentAlignment.MiddleCenter;
                button.Text = null;
                GraphicsPath gp = new GraphicsPath();
                gp.AddEllipse(0, 0, button.Width, button.Height);
                button.Region = new Region(gp);
                gp.Dispose();
            }
        }
 private void button1_Click(object sender, EventArgs e)
        {
            SetProp(sender as Button);
           
          
        }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文