Macro Wizard Code Snippet >> Checkboxes

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

Macro Wizard Code Snippet >> Checkboxes

Postby Robertspark » Wed Jan 16, 2019 10:17 pm

One of a group of example components that was going to put together as Macro Wizard Code Snippets

This one is for checkboxes.

Basically save it as a macronumber file of your choosing (such as M10001.txt) and run it via the mdi.

Two checkboxes will popup on a form, with a "Post G-Code" button.

tick box 1 and it will enable box 2....
you can run any code and it will post the gcode to the Codeview window.

I'm going to add a series of these to the Macro manual, hopefull with some useful events (such as mousehover etc)

Code: Select all
// ##  CheckBox Wizard Example, M10001

//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

   //
         // checkBox1
            //
            checkBox1.AutoSize = true;
       checkBox1.Font = new System.Drawing.Font("Arial Narrow", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            checkBox1.Location = new System.Drawing.Point(61, 25);
            checkBox1.Name = "checkBox1";
            checkBox1.Size = new System.Drawing.Size(80, 17);
            checkBox1.TabIndex = 0;
            checkBox1.Text = "checkBox1";
            checkBox1.UseVisualStyleBackColor = true;
            checkBox1.CheckedChanged += new System.EventHandler(checkBox1_CheckedChanged);
            //
            // checkBox2
            //
            checkBox2.AutoSize = true;
            checkBox2.Enabled = false;
       checkBox2.Font = new System.Drawing.Font("Arial Narrow", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            checkBox2.Location = new System.Drawing.Point(61, 60);
            checkBox2.Name = "checkBox2";
            checkBox2.Size = new System.Drawing.Size(80, 17);
            checkBox2.TabIndex = 1;
            checkBox2.Text = "checkBox2";
            checkBox2.UseVisualStyleBackColor = true;
            //
         // postGcode - BUTTON
           //
         postGcode.Location = new System.Drawing.Point(222, 653);
           postGcode.Name = "postGcode";
           postGcode.Size = new System.Drawing.Size(302, 37);
           postGcode.TabIndex = 20;
           postGcode.Text = "Post Gcode";
           postGcode.UseVisualStyleBackColor = true;
           postGcode.Click += new EventHandler(postGcode_Click);   
           //
         //
         
         
         
// Define the Event Handler  (VERY IMPORTANT)
           // Wizard Form
           //
         MyForm.Controls.Add(postGcode);

         MyForm.Controls.Add(checkBox1); //Checkbox 1
            MyForm.Controls.Add(checkBox2); //Checkbox 2
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)


      CheckBox checkBox1= new CheckBox();
      CheckBox checkBox2= new CheckBox();
      
      Button postGcode= new Button();
      
// ADD EVENTS BELOW HERE:

   void checkBox1_CheckedChanged(object sender, EventArgs e)
   {
   checkBox2.Enabled = (checkBox1.CheckState == CheckState.Checked);
   }


      
 void postGcode_Click(object sender, EventArgs e)
       {
      
      string Gcode = "";
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
 // STARTUP / LINITIALISATION SECTION       
      Gcode = (Gcode +  " ( TEST CODE ) " ) + Environment.NewLine;
      Gcode = (Gcode +  "  " ) + Environment.NewLine;

//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>   
 // BODY  SECTION      
      
      Gcode = (Gcode +  " ( " + checkBox1.CheckState  + " ) ") + Environment.NewLine;
      Gcode = (Gcode +  " ( " + checkBox2.CheckState  + " ) ") + Environment.NewLine;      
      
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 
 //FINISHING SECTION

       Gcode = (Gcode +  ("M30")) + Environment.NewLine;

       
       System.IO.File.WriteAllText(Application.StartupPath + @"/Example_codes/Test.tap" , Gcode );
     
     // Load and Run File

       exec.Loadfile(Application.StartupPath + @"/Example_codes/Test.tap");
    exec.Callbutton(402);
     
// Close the Wizard
MyForm.Close();
      
}


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

Return to Macros

Who is online

Users browsing this forum: No registered users and 1 guest