windows form help.

This is where you talk about Macros, show examples of your macro scripting and SHARE handy segments of script code as examples.

windows form help.

Postby Battwell » Tue May 04, 2021 12:10 pm

making a pop up form for touch screen use.

what am i missing to get the "pocket1" result to work on the button press..
CS0103 | in line: 39 | error text: The name 'pocket1' does not exist in the current context
the first bit works fine and populates my button text with the right number taken from a screen text field.

string content1 = AS3.Getfield(20401);
double pocket1 = Convert.ToDouble(content1);
pocket1 = (int)pocket1;

Button MyButton = new Button();
MyButton.Size = new System.Drawing.Size(80, 40);
MyButton.Location = new System.Drawing.Point(10, 100);
MyButton.Text = ("POCKET 1 T "+pocket1);
MyButton.Click += new EventHandler (MyButton_Click);

MyForm = new Form();
MyForm.Size = new System.Drawing.Size(430, 400);
MyForm.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
MyForm.Controls.Add(MyButton);


MyForm.ShowDialog(exec.mainform);


#Events

Form MyForm; //This is a global variable, a Windows Form



void MyButton_Click(object sender, EventArgs e)
{
//exec.Code("M6 T"+pocket1);// *************************************************************************** errors here.!
exec.Code("M6 T"+1);//********** but this works
MyForm.Close();
}
Uc300eth on router and mill
If they say it can't be done- I find a way!
Battwell
 
Posts: 614
Joined: Sun Sep 25, 2016 7:39 pm
Location: South Wales. Uk

Re: windows form help.

Postby dezsoe » Tue May 04, 2021 1:58 pm

Change "double pocket1 = Convert.ToDouble(content1);" to "pocket1 = Convert.ToDouble(content1);" and write "double pocket1;" after the #Events line. This way the pocket1 variable will be global in this macro, so you'll see it everywhere (as the MyForm).
dezsoe
 
Posts: 1508
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: windows form help.

Postby Battwell » Tue May 04, 2021 2:11 pm

that works- thank you!
i need to learn programming!
Uc300eth on router and mill
If they say it can't be done- I find a way!
Battwell
 
Posts: 614
Joined: Sun Sep 25, 2016 7:39 pm
Location: South Wales. Uk

Re: windows form help.

Postby Battwell » Tue May 04, 2021 2:51 pm

Uc300eth on router and mill
If they say it can't be done- I find a way!
Battwell
 
Posts: 614
Joined: Sun Sep 25, 2016 7:39 pm
Location: South Wales. Uk

Re: windows form help.

Postby Battwell » Wed May 05, 2021 3:27 pm

I added some colour. green for non active pocket and red for active (tool already loaded and active shows in red)
couldnt get this to work with a for loop- so all written longhand.
https://www.youtube.com/watch?v=eBAlPXsjuZg


Uc300eth on router and mill
If they say it can't be done- I find a way!
Battwell
 
Posts: 614
Joined: Sun Sep 25, 2016 7:39 pm
Location: South Wales. Uk

Re: windows form help.

Postby Battwell » Mon May 17, 2021 9:03 am

the windows form works very well.
is there a way to pass focus straight back to the uccnc main screen after a button press?
at the moment- the form stays active while the macro is not completed- but this stops any button press required . ie stop button
Uc300eth on router and mill
If they say it can't be done- I find a way!
Battwell
 
Posts: 614
Joined: Sun Sep 25, 2016 7:39 pm
Location: South Wales. Uk

Re: windows form help.

Postby dezsoe » Mon May 17, 2021 9:36 pm

Do you want the form to stay there while the code you started is running? If not then simply call this.Close() before you start the tool change.
dezsoe
 
Posts: 1508
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: windows form help.

Postby Battwell » Tue May 18, 2021 10:50 am

Tried
This.close (); throws scripts error
MyForm.close(); only closes after macro completes
Even if before the m6 command
Uc300eth on router and mill
If they say it can't be done- I find a way!
Battwell
 
Posts: 614
Joined: Sun Sep 25, 2016 7:39 pm
Location: South Wales. Uk


Return to Macros

Who is online

Users browsing this forum: No registered users and 2 guests