c# - Edit a button by its given name -
i generating x amount of buttons , give of them unique name.
after generated, want edit 1 of them without regenerating them wondering if component name?
i using winforms
you can use controls
property of form (or container control on form). linq can select buttons , find first button required name:
var button1 = controls.oftype<button>().firstordefault(b => b.name == "button1");
or if want search child controls recursively
var button1 = controls.find("button1", true) .oftype<button>() .firstordefault();
without linq can use method find(string key, bool searchallchildren) of controlcollection:
control[] controls = controls.find("button1", true); if (controls.length > 0) { button button1 = controls[0] button; }
Comments
Post a Comment