Page 1 of 1

Form - LED object

PostPosted: Fri Jun 16, 2017 2:58 am
by Robertspark
Instead of reinventing the wheel...

Suggestion, how would you represent an LED object on a plugin form.

understand the label and button examples within the plugin example, any chance of providing an LED example (object that will change between two states).

thought I'd ask because I'm sure other chip makers (cnc non-programmers) may benefit from this too

Thanks,

Re: Form - LED object

PostPosted: Fri Jun 16, 2017 4:48 am
by cncdrive
Hi Rob,

I think the simples way is to:

1.) Place a PictureBox on your Form and it's location and size to the size you want your LED. This PictureBox will represent your LED.
2.) Place a timer on your Form from the toolbox in Visual Studio.
3.) Set the timer Enabled property to true or set the Enabled property of the timer in your plugin code.
4.) Double click on your Timer in the Form editor, so the Timer_click event will be automatically generated and assigned by Visual Studio.
5.) Add some code to the Timer_click event, something like:

Code: Select all
private void timer1_Tick(object sender, EventArgs e)
{
   bool MyLEDstate = UC.GetLED(54);
   if (MyLEDstate)
   {
      pictureBox1.BackColor = Color.Red;
   }
   else
   {
      pictureBox1.BackColor = Color.Gray;
   }
}


So, you read the LED's state, in this example LED 54. which is the Cycle Start LED and you set the background color of your picturebox based on if the LED is on or off in the UCCNC.

Re: Form - LED object

PostPosted: Fri Jun 16, 2017 5:34 am
by Robertspark
thanks very much, just what I was looking for, easy to implment + idiot proof + does the job.

Suggestion would be if you get the time to edit the plugin example and add such a button for anyone wondering in the future, they can just copy the code from within the example.

Thanks again,

Re: Form - LED object

PostPosted: Fri Jun 16, 2017 5:44 am
by shad
+1
Also I am check current state of the picture box before set new color like this:
Code: Select all
if(pictureBox1.BackColor != Color.Red) pictureBox1.BackColor = Color.Red;

And of course you can use any modern LED 16x16 size picture for this. Just change picture depend from LED state.
http://www.clker.com/clipart-red-led-2.html

Re: Form - LED object

PostPosted: Fri Jun 16, 2017 5:46 am
by Robertspark
Thanks Andrew, much appreciated for your input too

Re: Form - LED object

PostPosted: Fri Jun 16, 2017 8:57 am
by dezsoe
You can also use an LED with text: place a label with your text on the form, turn off autosize, set desired size, set border to single. Then you can change the backcolor property to turn the LED on or off. You can use Drawing.SystemColors.Control for off state and Drawing.Color.anything for on state. Changing the backcolor is also good for buttons to have LED in them.

Re: Form - LED object

PostPosted: Fri Jun 16, 2017 11:26 am
by ger21
You can also use images, and swap them out.