如何一键更改属性
嘿, 我有多个按钮。我想减少代码,以便可以设置按钮的属性,但只有我单击的按钮会更改。这样我就不会单击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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)