Eto.forms - close on button click and get values from text box

Hi to everyone,

I am developing a simple plugin in rhino with few commands. I started to learn how to use Eto.Forms for inserting data to rhino. My question is, how can I close the form on button click event. I looked all over this forum, GitHub and others. Found some examples, but it does not work for me. I have similar Eto.forms written in Python and it does work. When I try to convert python code to C# (I am C# beginner) I cannot make my form close.

Thanks for any kind of help

Ondřej

My code:

using Rhino;
using Rhino.Commands;
using Rhino.Input.Custom;
using Eto.Forms;
using Eto.Drawing;

namespace SampleCsEto.Commands
{
    public class EtoSample1 : Rhino.Commands.Command
    {
        public override string EnglishName => "EtoSample1";

        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var f = new SampleCsViewportForm();
            f.Show();
            GetPoint GetPnt3D = new GetPoint();
            GetPnt3D.SetCommandPrompt("Select reference point on 3D curve where axis will be positioned");
            GetPnt3D.Get();
                return Result.Success;
        }
    }

    internal class SampleCsViewportForm : Form
    {
        TextBox TB1 = new TextBox();
        TextBox TB2 = new TextBox();

        string X = "";
        string Y = "";

        public SampleCsViewportForm()
        {
            Title = "Hokus pokus";
            Resizable = true;

            Label L1 = new Label();
            Label L2 = new Label();



            Button B1 = new Button();
            Button B2 = new Button();



            L1.Text = "X move";
            L1.TextAlignment = TextAlignment.Left;
            L2.Text = "Y Move";
            L2.TextAlignment = TextAlignment.Left;

            B1.Text = "Ok";
            B1.Click += OnOkButtonClick;
            B2.Text = "Cancel";
            B2.Click += OnCloseButtonClick;

            TableRow TR1 = new TableRow();
            TR1.Cells.Add(L1);
            TR1.Cells.Add(TB1);

            TableRow TR2 = new TableRow();
            TR2.Cells.Add(L2);
            TR2.Cells.Add(TB2);

            TableRow TR3 = new TableRow();
            TR3.Cells.Add(B1);
            TR3.Cells.Add(B2);


            this.Content = new TableLayout
            {
                Padding = new Padding(20),
                Spacing = new Size(10, 10),

                         
                Rows = {TR1,TR2,TR3}
            };               
        }



        public void OnCloseButtonClick (object sender, System.EventArgs e)
        {
            Close();
        }
        public void OnOkButtonClick(object sender, System.EventArgs e)
        {
            X = this.TB1.Text;
            Y = this.TB1.Text;
            Close();
        }

    }
}

Hi Ondřej, have you tried this.Close() yet ?

_
c.

1 Like

Hi Clement. It does work with this.Close(). As VS told me that “this” is not needed I went without it. .

If I understand it well, without “this” Rhino does not know to which class Close method linked. Am I right?

Thanks a lot.

right.

_
c.