Get value from NumericUpDown

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

Get value from NumericUpDown

Postby Jeffsg605 » Fri Jan 11, 2019 5:23 pm

I'm writing a macro with a user interface in C#. How can I get the value of a NumericUpDown? In C#, its "double x = (double)NumericUpDown1.Value;" but this doesn't seem to work in UCCNC. Any advice would be appreciated, thanks!
Jeffsg605
 
Posts: 16
Joined: Fri Jan 11, 2019 5:20 pm

Re: Get value from NumericUpDown

Postby Robertspark » Fri Jan 11, 2019 6:20 pm

Is it not a field that is defined as type updn?

Does it have a field number associated with it.

What field are you trying to grab?
Robertspark
 
Posts: 1892
Joined: Sat Sep 03, 2016 4:27 pm

Re: Get value from NumericUpDown

Postby Jeffsg605 » Fri Jan 11, 2019 6:30 pm

So I think I'm going about this a different way than is conventional. I'm not using the Screen Editor. Per the UCCNC Macros Manual (Page 9 here: https://cnctar.hobbycnc.hu/UCCNC/UCCNC% ... 1-2022.pdf) I am creating a windows form. In Winforms, they are called NumericUpDown boxes, not updn. There is no field number.

I just need a quick proof of concept to show a customer what I intend to do so this seemed easier than developing a whole screen.
Jeffsg605
 
Posts: 16
Joined: Fri Jan 11, 2019 5:20 pm

Re: Get value from NumericUpDown

Postby Robertspark » Fri Jan 11, 2019 6:37 pm

A wizard?

Macro form??

(Note that is an old macro manual... I've updated it since, check the link in my signature)
Robertspark
 
Posts: 1892
Joined: Sat Sep 03, 2016 4:27 pm

Re: Get value from NumericUpDown

Postby Jeffsg605 » Fri Jan 11, 2019 6:59 pm

Macro form.

Sorry, first time using UCCNC so I apologize if I'm lacking important details.

So per your manual, I want to do something like:

NumericUpDown nud1 = new NumericUpDown();
nud1.Size = new System.Drawing.Size(65, 20);
nud1.Location = new System.Drawing.Point(20, 60);
nud1.DecimalPlaces = 2;
nud1.Value = 3.25; // This is what is giving me trouble.
MyForm.Controls.Add(nud1);

Thanks again.
Jeffsg605
 
Posts: 16
Joined: Fri Jan 11, 2019 5:20 pm

Re: Get value from NumericUpDown

Postby Robertspark » Fri Jan 11, 2019 7:04 pm

Give me a moment see what I can do
Robertspark
 
Posts: 1892
Joined: Sat Sep 03, 2016 4:27 pm

Re: Get value from NumericUpDown

Postby Jeffsg605 » Fri Jan 11, 2019 7:16 pm

Thank you!
Jeffsg605
 
Posts: 16
Joined: Fri Jan 11, 2019 5:20 pm

Re: Get value from NumericUpDown

Postby Robertspark » Fri Jan 11, 2019 7:33 pm

Try this

Save it as a *.txt file within your profile and call it as a macro and your numericupdown control will popup

Code: Select all
// ##  , M10000

//Set up the form for Wizard

MyForm = new Form();
MyForm.Size = new System.Drawing.Size(1200, 750);
MyForm.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
MyForm.Text = " UCCNC xxxxx Wizard vx.xxxxx ";
//((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();


//Define the objects on the form

   //
        // numericUpDown1
        //
            numericUpDown1.DecimalPlaces = 2;
            numericUpDown1.Location = new System.Drawing.Point(20, 60);
            numericUpDown1.Name = "numericUpDown1";
            numericUpDown1.Size = new System.Drawing.Size(65, 20);
            numericUpDown1.TabIndex = 0;
            numericUpDown1.Value = new decimal(new int[] {
            325,
            0,
            0,
            131072});
            //
         //
           // Wizard Form
           //
           MyForm.Controls.Add(numericUpDown1); // numericUpDown1
         
MyForm.ShowDialog();
       

      //*************** Starting of the Events Section *****************************

#Events   

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

// DEFINE all of the elements of the Form HERE (VERY IMPORTANT)

      
      NumericUpDown numericUpDown1= new NumericUpDown();

Robertspark
 
Posts: 1892
Joined: Sat Sep 03, 2016 4:27 pm

Re: Get value from NumericUpDown

Postby Jeffsg605 » Fri Jan 11, 2019 7:39 pm

Well I was always able to get it to pop up. I just wasn't able to set its value which you did with "nud1.Value = new deimcal(...)" so thank you!

But now how do I store that value in a variable. Say the user changed it from 3.25 to 5.25. I would like to do:
double x = (double)nud1.Value;

But this also gives me an error when I try to run the macro. Any thoughts?

Thanks so far!
Jeffsg605
 
Posts: 16
Joined: Fri Jan 11, 2019 5:20 pm

Re: Get value from NumericUpDown

Postby Robertspark » Fri Jan 11, 2019 7:48 pm

Thinking about it I may create some Macro Form / Wizard templates for controls....

Any suggestions of what other controls you (or anyone else) would like?

Current list:

  1. Checkbox
  2. ComboBox
  3. Label
  4. ListBox
  5. NumericUPDown
  6. PictureBox
  7. RadioButton
  8. TextBox
  9. ToolTip
  10. GroupBox
  11. TabControl
Robertspark
 
Posts: 1892
Joined: Sat Sep 03, 2016 4:27 pm

Next

Return to Macros

Who is online

Users browsing this forum: No registered users and 6 guests

cron