示例#1
0
        public void goTest_Click(object sender, EventArgs e)
        {
            sidePanelHide();
            // Otworz okno z scenariuszami testowymi
            TestForm testForm = new TestForm();

            // Otworz jako okno dialogowe (blokuj interakcje z tlem)
            testForm.ShowDialog();

            // Jesli wybrano jakis element
            if (testForm.objectReference is null)
            {
                // Wcisnieto przycisk Close w TestForm
                Debug.WriteLine("Nie wybrano nic.");
            }
            else
            {
                // Wybrano jakis obiekt
                Object objectSelected = testForm.objectReference;
                string objectName     = testForm.objectName;
                Debug.WriteLine($"Wybrano {objectName}, {objectSelected.ToString()}!");

                // Okresl typ obiektu wybranego
                if (objectSelected is System.Byte[])
                {
                    // Obiekt to System.Byte[] czyli lancuch znakow
                    // Konwertuj `Byte[]` do `string`
                    string objectSelectedToString = System.Text.Encoding.Default.GetString((Byte[])objectSelected);
                    // Konwertuj `string` do `List<string>`
                    List <string> objectSelectedToGCode = objectSelectedToString.Split(new char[] { '\n' }).ToList();
                    // Zamknij otwarty serialPort
                    CloseSerialPort();
                    // Wylacz kontrole panelu na MainForm
                    setControlPanelDisabled();
                    // Rozlacz laser
                    SetLaserDisconnected();
                    // Ustaw StatusBox na busy
                    setStatusBoxStatus(StatusBoxStatus.Busy, serialPort.PortName);

                    // Inicjalizacja procesu grawerowania, okno EngravingForm
                    try
                    {
                        EngravingForm engravingForm = new EngravingForm(
                            $"obrazu testowego {objectName}", objectSelectedToGCode
                            );
                        // Otworz jako okno dialogowe
                        engravingForm.ShowDialog();
                    }
                    catch
                    {
                        DialogResult messageBox = MessageBox.Show("Proces anulowano!",
                                                                  "Grawerowanie",
                                                                  MessageBoxButtons.OK,
                                                                  MessageBoxIcon.Warning
                                                                  );
                    }
                }
                else if (testForm.objectReference is System.Drawing.Bitmap)
                {
                    // :)
                }
            }
        }