Page 1 of 2

adding led and text field to pop up form

PostPosted: Thu Dec 31, 2020 4:49 pm
by Battwell
i have been working on a spindle warm up timer which is now fully working.
id like to have it pop up a form (like the extra button form) but with a few leds and text fields on it which i can then populate from my macroloop.
is this possible?

Re: adding led and text field to pop up form

PostPosted: Thu Dec 31, 2020 4:59 pm
by Robertspark
you'll need to create a form like this one (or sort of.... just along the same lines of one of these)

viewtopic.php?f=15&t=987

Re: adding led and text field to pop up form

PostPosted: Fri Jan 01, 2021 2:43 pm
by Battwell
ok. ive managed to create a form with a label, textbox and buttons.

buttons and labels working fine.
trying to work out how to display a var from uccnc into the form text box. any help?
ps. happy new year

Re: adding led and text field to pop up form

PostPosted: Fri Jan 01, 2021 3:33 pm
by Battwell
was thinking. is what i want to do even possible?
the text box showing a var ? if the var changes while its being updated by a macro loop- will it change in the form textfield as thats only run once.

Re: adding led and text field to pop up form

PostPosted: Fri Jan 01, 2021 3:39 pm
by dezsoe
You can add a Timer to the form which updates with a set time the data on the form. The data can be a field, a label, a picturebox with an LED, etc.

Re: adding led and text field to pop up form

PostPosted: Fri Jan 01, 2021 4:33 pm
by Battwell
thank you dezoe.
is there any references to code required i can read up on doing this?
im still having difficulty just getting the var to populate the text box :-(

Re: adding led and text field to pop up form

PostPosted: Fri Jan 01, 2021 4:45 pm
by Battwell
found this. looks like i have a few more hours head scratching to do.
Examples
The following example implements a simple interval timer, which sets off an alarm every five seconds. When the alarm occurs, a MessageBox displays a count of the number of times the alarm has started and prompts the user as to whether the timer should continue to run.

C#

Copy
public class Class1 {
static System.Windows.Forms.Timer myTimer = new System.Windows.Forms.Timer();
static int alarmCounter = 1;
static bool exitFlag = false;

// This is the method to run when the timer is raised.
private static void TimerEventProcessor(Object myObject,
EventArgs myEventArgs) {
myTimer.Stop();

// Displays a message box asking whether to continue running the timer.
if(MessageBox.Show("Continue running?", "Count is: " + alarmCounter,
MessageBoxButtons.YesNo) == DialogResult.Yes) {
// Restarts the timer and increments the counter.
alarmCounter +=1;
myTimer.Enabled = true;
}
else {
// Stops the timer.
exitFlag = true;
}
}

public static int Main() {
/* Adds the event and the event handler for the method that will
process the timer event to the timer. */
myTimer.Tick += new EventHandler(TimerEventProcessor);

// Sets the timer interval to 5 seconds.
myTimer.Interval = 5000;
myTimer.Start();

// Runs the timer, and raises the event.
while(exitFlag == false) {
// Processes all the events in the queue.
Application.DoEvents();
}
return 0;
}
}

Re: adding led and text field to pop up form

PostPosted: Fri Jan 01, 2021 5:40 pm
by dezsoe
Here is a macro, which uses the Timer and sets an LED:

Code: Select all
// Path is relative to UCCNC.EXE
path = Application.StartupPath + @"\Flashscreen\BMP\";

ledON = path + "LEDon.png";
ledOFF = path + "LEDoff.png";

myForm = new Form();
myForm.SuspendLayout();

myForm.ClientSize = new System.Drawing.Size(400, 200); // Min width: 140!
myForm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
myForm.ControlBox = false;
myForm.MaximizeBox = false;
myForm.MinimizeBox = false;
myForm.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;

myLabel = new Label();
myLabel.Font = new System.Drawing.Font("Arial", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, (byte)238);
myLabel.Location = new System.Drawing.Point(12, 20);
myLabel.Size = new System.Drawing.Size((int)(myForm.ClientSize.Width - 24), 22);
myLabel.Text = "Activate the probe input at least once!";
myLabel.TextAlign = System.Drawing.ContentAlignment.TopCenter;

myPBox = new PictureBox();
myPBox.Size = new System.Drawing.Size(40, 40);
myPBox.Location = new System.Drawing.Point((int)(myForm.ClientSize.Width / 2 - myPBox.Size.Width / 2), myForm.ClientSize.Height - myPBox.Size.Height - 100);
myPBox.ImageLocation = ledOFF;
myPBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;

myButton1 = new Button();
myButton1.Size = new System.Drawing.Size(90, 23);
myButton1.Location = new System.Drawing.Point((int)(myForm.ClientSize.Width / 2 - myButton1.Size.Width / 2), myForm.ClientSize.Height - 80);
myButton1.TabIndex = 0;
myButton1.Text = "Proceed";
myButton1.Enabled = false;
myButton1.Click += new System.EventHandler(myButton1_Click);

myButton2 = new Button();
myButton2.Size = new System.Drawing.Size(90, 23);
myButton2.Location = new System.Drawing.Point((int)(myForm.ClientSize.Width / 2 - myButton2.Size.Width / 2), myForm.ClientSize.Height - 40);
myButton2.TabIndex = 0;
myButton2.Text = "Cancel";
myButton2.Click += new System.EventHandler(myButton2_Click);

myTimer = new System.Windows.Forms.Timer();
myTimer.Enabled = true;
myTimer.Interval = 50;
myTimer.Tick += new System.EventHandler(myTimer_Tick);

myForm.Controls.Add(myLabel);
myForm.Controls.Add(myPBox);
myForm.Controls.Add(myButton1);
myForm.Controls.Add(myButton2);

myForm.ResumeLayout(false);

myForm.BringToFront();
myForm.ShowDialog(exec.mainform);

if (proceed)
{
  // Proceed was pressed, your code here!
  exec.AddStatusmessage("Test completed.")
}

#Events

string path;
string ledON;
string ledOFF;

Form myForm;
Label myLabel;
PictureBox myPBox;
Button myButton1;
Button myButton2;
System.Windows.Forms.Timer myTimer;

bool lastProbeLEDState = false;
bool wasActive = false;

bool proceed = false;

private void myTimer_Tick(object sender, EventArgs e)
{
  bool probeState = exec.GetLED(37); // Probe LED
  if (probeState != lastProbeLEDState)
  {
    if (probeState)
      wasActive = true;
    else
      if (wasActive) myButton1.Enabled = true;
    lastProbeLEDState = probeState;
    if (probeState)
      myPBox.ImageLocation = ledON;
    else
      myPBox.ImageLocation = ledOFF;
  }
}

private void myButton1_Click(object sender, EventArgs e)
{
  proceed = true;
  myForm.Close();
}

private void myButton2_Click(object sender, EventArgs e)
{
  proceed = false;
  exec.Callbutton(130);
  myForm.Close();
}

Re: adding led and text field to pop up form

PostPosted: Sun Jan 03, 2021 11:26 am
by Battwell
Still having trouble trying to get the variable to read into my form
Does it have to be declared as public static in the feeding macroloop?

Re: adding led and text field to pop up form

PostPosted: Sun Jan 03, 2021 2:27 pm
by dezsoe
Add the following line to myTimer_Tick and it will show you the current Z:
Code: Select all
  myLabel.Text = "Z = " + AS3.Getfield(228);