<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#ffffff">
    Here's a snippet that may help a little if you really need to get at
    a control that has been added to a parent control:<br>
    <br>
    import clr<br>
    import System<br>
    clr.AddReference("System.Windows.Forms")<br>
    from System.Windows.Forms import Form, Button<br>
    <br>
    myBtnName = "button1"<br>
    <br>
    form1 = Form()<br>
    <br>
    def AddButton(form, btnName):<br>
        btn = Button()<br>
        btn.Name = btnName<br>
        btn.Text = "Click Me"<br>
        form.Controls.Add(btn)<br>
    <br>
    AddButton(form1, myBtnName)<br>
    <br>
    ctrls = form1.Controls.Find(myBtnName, False)<br>
    btn = ctrls[0]<br>
    if isinstance(btn, Button):<br>
        print repr(btn)<br>
        print btn.Name<br>
    <br>
    System.Windows.Forms.Application.EnableVisualStyles()<br>
    System.Windows.Forms.Application.Run(form1)<br>
    <br>
    <br>
    <br>
    On 9/2/2011 8:17 PM, Barton wrote:
    <blockquote cite="mid:4E619C4D.7080509@BCDesignsWell.com"
      type="cite">
      <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
      Very interesting;<br>
      Apparently, Microsoft doesn't think that it is a useful thing to
      index directly into a
      System.Windows.Forms.Control.ControlCollection Class.<br>
      The collection is still iterable in versions above 2.0, but the
      class no longer supports indexing. So:<br>
      <br>
      &gt;&gt;&gt; print form.Controls[0]         # works in
      pythondotnet built on .NET 2.0 on prior.<br>
      &lt;System.Windows.Forms.Button object at 0xaa8bc6c&gt;<br>
      &gt;&gt;&gt; <br>
      <br>
      for ctrl in form.Controls:<br>
          print ctrl    # works in .NET 3.0 and above.<br>
      <br>
      <br>
      Compare<br>
      <a moz-do-not-send="true" class="moz-txt-link-freetext"
href="http://msdn.microsoft.com/en-us/library/system.windows.forms.control.controlcollection_properties.aspx">http://msdn.microsoft.com/en-us/library/system.windows.forms.control.controlcollection_properties.aspx</a><br>
      with<br>
      <a moz-do-not-send="true" class="moz-txt-link-freetext"
href="http://msdn.microsoft.com/en-us/library/system.windows.forms.control.controlcollection_properties%28VS.80%29.aspx">http://msdn.microsoft.com/en-us/library/system.windows.forms.control.controlcollection_properties%28VS.80%29.aspx</a><br>
      and you'll see that all ICollection and IList properties have been
      removed.<br>
      <br>
      Reasons why are a good topic for future discussion.<br>
      <br>
      On 8/31/2011 10:30 PM, 刘振海 wrote:
      <blockquote
cite="mid:CAGZyxudoy0L5cdWr8zpLz9oSGicy3sm7S5u6O_pHWQwuPmQ6AA@mail.gmail.com"
        type="cite">Hi,
        <div><br>
          <div>here  is the code:</div>
          <div><br>
          </div>
          <div>import clr</div>
          <div>clr.AddReference("System.Windows.Forms")</div>
          <div>from System.Windows.Forms import Form,Application,Button</div>
          <div>form=Form()</div>
          <div>form.Controls.Add(Button())</div>
          <div>print form.Controls[0] #this code didnt work with an
            error say "not indexable object"</div>
          <div><br>
          </div>
          <div>but this worked in ironpython,it seems in ironpython it
            treats the "form.Controls" as an list like object </div>
          <div>I can only get the form.Controls value use the
            "form.Controls.get_Item(0)" in the python for .net</div>
          <div>So is there a chance to imprive Python for .net to have
            that characteristic?</div>
          <div><br>
          </div>
          <div> thanks</div>
          <div><br>
          </div>
        </div>
        <pre wrap=""><fieldset class="mimeAttachmentHeader"></fieldset>
_________________________________________________
Python.NET mailing list - <a moz-do-not-send="true" class="moz-txt-link-abbreviated" href="mailto:PythonDotNet@python.org">PythonDotNet@python.org</a>
<a moz-do-not-send="true" class="moz-txt-link-freetext" href="http://mail.python.org/mailman/listinfo/pythondotnet">http://mail.python.org/mailman/listinfo/pythondotnet</a></pre>
      </blockquote>
      <pre wrap="">
<fieldset class="mimeAttachmentHeader"></fieldset>
_________________________________________________
Python.NET mailing list - <a class="moz-txt-link-abbreviated" href="mailto:PythonDotNet@python.org">PythonDotNet@python.org</a>
<a class="moz-txt-link-freetext" href="http://mail.python.org/mailman/listinfo/pythondotnet">http://mail.python.org/mailman/listinfo/pythondotnet</a></pre>
    </blockquote>
  </body>
</html>