Page 1 of 3

Get value from NumericUpDown

PostPosted: Fri Jan 11, 2019 5:23 pm
by Jeffsg605
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!

Re: Get value from NumericUpDown

PostPosted: Fri Jan 11, 2019 6:20 pm
by Robertspark
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?

Re: Get value from NumericUpDown

PostPosted: Fri Jan 11, 2019 6:30 pm
by Jeffsg605
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.

Re: Get value from NumericUpDown

PostPosted: Fri Jan 11, 2019 6:37 pm
by Robertspark
A wizard?

Macro form??

(Note that is an old macro manual... I've updated it since, check the link in my signature)

Re: Get value from NumericUpDown

PostPosted: Fri Jan 11, 2019 6:59 pm
by Jeffsg605
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.

Re: Get value from NumericUpDown

PostPosted: Fri Jan 11, 2019 7:04 pm
by Robertspark
Give me a moment see what I can do

Re: Get value from NumericUpDown

PostPosted: Fri Jan 11, 2019 7:16 pm
by Jeffsg605
Thank you!

Re: Get value from NumericUpDown

PostPosted: Fri Jan 11, 2019 7:33 pm
by Robertspark
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();


Re: Get value from NumericUpDown

PostPosted: Fri Jan 11, 2019 7:39 pm
by Jeffsg605
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!

Re: Get value from NumericUpDown

PostPosted: Fri Jan 11, 2019 7:48 pm
by Robertspark
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