How cant I close the windows?

I am new in class and winforms, how cant I close the windows in this sample? and if I add many button in the windows, how cant I get the result of them to continue my script? For example: I add button “A” and button “B”, if I click in button “A”, I will cant add a line, if I click in button “B”, I will cant add a cricle.
Sorry for my english.Think you.

import rhinoscriptsyntax as rs
import Rhino
import System.Drawing
import System.Windows.Forms
from System.Drawing import *
from System.Windows.Forms import *

class CirForm(Form):

   def __init__(self):
     self.Name = "Form"
     self.ShowIcon = True
     self.Text = "Draw Circle Test"
     self.ClientSize = System.Drawing.Size(200, 90)
     self.BackColor = System.Drawing.SystemColors.Menu
     self._Label1 = System.Windows.Forms.Label()
     self._RadVal = System.Windows.Forms.NumericUpDown()
     self._Ok = System.Windows.Forms.Button()
     self._Cancel = System.Windows.Forms.Button()
     self.radius = 18
     # label1
     self._Label1.Location = System.Drawing.Point(6, 23)
     self._Label1.Name = "label1"
     self._Label1.Size = System.Drawing.Size(100, 17)
     self._Label1.TabIndex = 0
     self._Label1.Text = "Radius for Circle"
     # radius
     self._RadVal.Location = System.Drawing.Point(112, 20)
     self._RadVal.Name = "radius"
     self._RadVal.Size = System.Drawing.Size(41, 20)
     self._RadVal.TabIndex = 1
     self._RadVal.ReadOnly = False 
     self._RadVal.Value = 18
     self._RadVal.Increment = 3
     self._RadVal.Minimum = 9
     self._RadVal.Maximum = 48
     #self._RadVal.ValueChanged = self.Radius_OnValueChange
     # Ok
     self._Ok.DialogResult = System.Windows.Forms.DialogResult.OK
     self._Ok.Location = System.Drawing.Point(6, 56)
     self._Ok.Name = "Ok"
    self._Ok.Size = System.Drawing.Size(70, 26)
      self._Ok.TabIndex = 2
     self._Ok.Text = "OK"
     self._Ok.UseVisualStyleBackColor = True
     # Cancel
     self._Cancel.DialogResult = System.Windows.Forms.DialogResult.Cancel
     self._Cancel.Location = System.Drawing.Point(84, 56)
     self._Cancel.Name = "Cancel"
     self._Cancel.Size = System.Drawing.Size(70, 26)
     self._Cancel.TabIndex = 3
     self._Cancel.Text = "Cancel"
     self._Cancel.UseVisualStyleBackColor = True
     # Form1
     self.AcceptButton = self._Ok
     self.CancelButton = self._Cancel
  def Radius_OnValueChange(self, sender, e):
     self.radius = sender.Value

if __name__ == "__main__":
  form = CirForm()
  rs.AddCircle(rs.GetPoint(), form.radius)

Hi @pythonuser,

try the script below. (3 KB)

To add geometry, while keeping the dialog opened, see the how the on OnCloseFunction was connected to the button below. If you add an event handler to your button like this:

self._Cancel.Click += self.OnCloseFunction

…you can do anything you want in the function and access input values as shown at the end of the script.


Think you for your replay@clement :grinning: ;
If use result = form.ShowDialog(Rhino.RhinoApp.MainWindow()) I cant not do other thing outside the formwindown, so I change it to result = form.Show(Rhino.RhinoApp.MainWindow()), but by this, the button “OK” is not work, and I cant not add the circle is it way to solve it?
Sorry for my english.
Think you.

Hi @pythonuser,

you can just add your own function inside the form like this:

    def MyCircleFunction(self, sender, e):
        circle_center = rs.GetPoint()
        if circle_center:
            rs.AddCircle(circle_center, form._RadVal.Value)
            print "No center clicked"

then add this into your button section, so the event “Click” points to the function:

self._Ok.Click += self.MyCircleFunction

Below is the full script, which leaves the dialog open. To Close the dialog if it has been opened using:


i just call the “OnCloseFunction” linked to the Cancel button as shown in my previous post. (3.0 KB)


Think you @clement;
It is help for me :grinning: