zoukankan      html  css  js  c++  java
  • How to change the property of a control from a flowlayoutpanel?

    Well, the easiest way would be to retain an explicit reference to the buttons you're adding. Otherwise you could add a tag to distinguish them (to be robust against i18n issues). E.g. you can set the tag of "button2" to "button2" and then you can use:

    foreach(Control ctl in flp.Controls){if("button2".Equals(ctl.Tag)){
            ctl.BackColor=Color.Red;}

    }

    I am assuming your problem is to find the actual button again and not setting the background color. You could likewise check for the control being a button and its text being "button2" but if the text can change depending on the UI language that's probably not a good idea.

    ETA: Totally forgot that you can use the control's Name property for this as well.

    If you just want to change the background color of the button in a response to an event from the button you can just use the sender argument of the event handler, though.

    //////

    You can try Control.ControlCollection.Find.

    flowLayoutPanel1.Controls.Add(newButton(){Text="button 1",Name="btn1"});
    Button btn1 = flowLayoutPanel1.Controls.Find("btn1",true).FirstOrDefault()asButton; btn1.Text="found!";
  • 相关阅读:
    实验二
    实验一
    网络对抗技术 实验四 恶意代码技术
    网络对抗技术 实验三 密码破解技术
    网络对抗技术 实验二 网络嗅探与欺骗
    网络对抗技术 实验一 网络侦查与网络扫描
    实验6
    实验5
    caogao
    实验四
  • 原文地址:https://www.cnblogs.com/zeroone/p/3621966.html
Copyright © 2011-2022 走看看