form buttons

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

form buttons

Postby Battwell » Tue Jul 30, 2019 12:07 pm

trying to make a pop up box with multiple buttons. (will be more than 2 when its completed)
so far it dispays the buttons and responds to clicks
however it runs both functions (of each button, not just the clicked button)
working from the pasted sample in documentation.




Button MyButton = new Button();
MyButton.Size = new System.Drawing.Size(80, 40);
MyButton.Location = new System.Drawing.Point(50, 130);
MyButton.Text = "button1";
MyButton.Click += new EventHandler(MyButton_Click);

Button MyButton2 = new Button();
MyButton2.Size = new System.Drawing.Size(80, 40);
MyButton2.Location = new System.Drawing.Point(200, 130);
MyButton2.Text = "button2";
MyButton2.Click += new EventHandler(MyButton2_Click);

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

MyForm.ShowDialog();

MyFunction();
MyFunction2();

#Events

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

void MyButton_Click(object sender, EventArgs e)
{
MessageBox.Show("button1");
MyForm.Close();
}

void MyFunction()
{
exec.Code("G0 X10");

}



void MyButton2_Click(object sender, EventArgs e)
{
MessageBox.Show("button2 !");
MyForm.Close();

}

void MyFunction2()
{
exec.Code("G0 X20");
}
Uc300eth on router and mill.
UK uccnc powered machine sales. https://cncrouter.uk/atc-cnc-routers.htm
Automateanything/duzzit cnc/mercury cnc
Battwell
 
Posts: 827
Joined: Sun Sep 25, 2016 7:39 pm
Location: South Wales. Uk

Re: form buttons

Postby Dan911 » Tue Jul 30, 2019 12:45 pm

Button MyButton = new Button();
MyButton.Size = new System.Drawing.Size(80, 40);
MyButton.Location = new System.Drawing.Point(50, 130);
MyButton.Text = "button1";
MyButton.Click += new EventHandler(MyButton_Click);

Button MyButton2 = new Button();
MyButton2.Size = new System.Drawing.Size(80, 40);
MyButton2.Location = new System.Drawing.Point(200, 130);
MyButton2.Text = "button2";
MyButton2.Click += new EventHandler(MyButton2_Click);

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

MyForm.ShowDialog();


#Events

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

void MyButton_Click(object sender, EventArgs e)
{
exec.Code("G0 X10");
MyForm.Close();
}



void MyButton2_Click(object sender, EventArgs e)
{
exec.Code("G0 X20");
MyForm.Close();
}
Dan911
 
Posts: 613
Joined: Mon Oct 31, 2016 1:22 am
Location: USA

Re: form buttons

Postby Battwell » Tue Jul 30, 2019 1:06 pm

thanks dan- thats simpler- and works!
Uc300eth on router and mill.
UK uccnc powered machine sales. https://cncrouter.uk/atc-cnc-routers.htm
Automateanything/duzzit cnc/mercury cnc
Battwell
 
Posts: 827
Joined: Sun Sep 25, 2016 7:39 pm
Location: South Wales. Uk

Re: form buttons

Postby Battwell » Tue Jul 30, 2019 2:43 pm



Code: Select all
 // brendons 6 extra button script for uccnc

Button MyButton = new Button();
MyButton.Size = new System.Drawing.Size(80, 40);
MyButton.Location = new System.Drawing.Point(10, 10);
MyButton.Text = "button1";
MyButton.Click += new EventHandler(MyButton_Click);

Button MyButton2 = new Button();
MyButton2.Size = new System.Drawing.Size(80, 40);
MyButton2.Location = new System.Drawing.Point(110, 10);
MyButton2.Text = "button2";
MyButton2.Click += new EventHandler(MyButton2_Click);

Button MyButton3 = new Button();
MyButton3.Size = new System.Drawing.Size(80, 40);
MyButton3.Location = new System.Drawing.Point(210, 10);
MyButton3.Text = "button3";
MyButton3.Click += new EventHandler(MyButton3_Click);

Button MyButton4 = new Button();
MyButton4.Size = new System.Drawing.Size(80, 40);
MyButton4.Location = new System.Drawing.Point(10, 100);
MyButton4.Text = "button4";
MyButton4.Click += new EventHandler(MyButton4_Click);

Button MyButton5 = new Button();
MyButton5.Size = new System.Drawing.Size(80, 40);
MyButton5.Location = new System.Drawing.Point(110, 100);
MyButton5.Text = "button5";
MyButton5.Click += new EventHandler(MyButton5_Click);

Button MyButton6 = new Button();
MyButton6.Size = new System.Drawing.Size(80, 40);
MyButton6.Location = new System.Drawing.Point(210, 100);
MyButton6.Text = "button6";
MyButton6.Click += new EventHandler(MyButton6_Click);

MyForm = new Form();
MyForm.Size = new System.Drawing.Size(310, 200);
MyForm.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
MyForm.Controls.Add(MyButton);
MyForm.Controls.Add(MyButton2);
MyForm.Controls.Add(MyButton3);
MyForm.Controls.Add(MyButton4);
MyForm.Controls.Add(MyButton5);
MyForm.Controls.Add(MyButton6);


MyForm.ShowDialog();


#Events

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

void MyButton_Click(object sender, EventArgs e)
{
exec.Code("G0 X10");
MyForm.Close();
}


void MyButton2_Click(object sender, EventArgs e)
{
exec.Code("G0 X20");
MyForm.Close();
}


void MyButton3_Click(object sender, EventArgs e)
{
exec.Code("G0 X50");
MyForm.Close();
}

void MyButton4_Click(object sender, EventArgs e)
{
exec.Code("G0 X100");
MyForm.Close();
}


void MyButton5_Click(object sender, EventArgs e)
{
exec.Code("G0 X150");
MyForm.Close();
}

void MyButton6_Click(object sender, EventArgs e)
{
exec.Code("G0 X200");
MyForm.Close();
}


// Send beer if found useful :-)  brendon@mercuryleisure.co.uk
Uc300eth on router and mill.
UK uccnc powered machine sales. https://cncrouter.uk/atc-cnc-routers.htm
Automateanything/duzzit cnc/mercury cnc
Battwell
 
Posts: 827
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 4 guests