Пример #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (image == null)
            {
                stringError.Text = "Please select an image";
            }
            else
            {
                var selectedButton    = groupBox1.Controls.OfType <RadioButton>().FirstOrDefault(r => r.Checked);
                int selectedAlgorithm = selectedButton.TabIndex;

                try
                {
                    // Noktaları alma
                    int startPointX  = int.Parse(startXText.Text);
                    int startPointY  = int.Parse(startYText.Text);
                    int finishPointX = int.Parse(finishXText.Text);
                    int finishPointY = int.Parse(finishYText.Text);

                    // Doğrulama
                    if (startPointX < 0 || startPointY < 0 || finishPointX < 0 || finishPointY < 0)
                    {
                        throw (new ImageBoundException("The number you entered exceeds the image size."));
                    }
                    if (startPointX >= image.Width || finishPointX >= image.Width)
                    {
                        throw (new ImageBoundException("The number you entered exceeds the image size."));
                    }
                    if (startPointY >= image.Height || finishPointY >= image.Height)
                    {
                        throw (new ImageBoundException("The number you entered exceeds the image size."));
                    }

                    int[] startPoints  = { startPointX, startPointY };
                    int[] finishPoints = { finishPointX, finishPointY };
                    //Algoritmayı çağırma
                    PathFindingController pfc = new PathFindingController(selectedAlgorithm, startPoints, finishPoints, image, this);
                    stringError.Text = "";
                }
                catch (FormatException)
                {
                    stringError.Text = "Points you entered are not valid.";
                }
                catch (ImageBoundException ie)
                {
                    stringError.Text = ie.Message;
                }
            }
        }
Пример #2
0
        private void diagnosticsButton_Click(object sender, EventArgs e)
        {
            if (image == null)
            {
                stringError.Text = "Please select an image";
            }
            else
            {
                try
                {
                    // Noktaları alma
                    int startPointX  = int.Parse(startXText.Text);
                    int startPointY  = int.Parse(startYText.Text);
                    int finishPointX = int.Parse(finishXText.Text);
                    int finishPointY = int.Parse(finishYText.Text);

                    // Doğrulama
                    if (startPointX < 0 || startPointY < 0 || finishPointX < 0 || finishPointY < 0)
                    {
                        throw (new ImageBoundException("The number you entered exceeds the image size."));
                    }
                    if (startPointX >= image.Width || finishPointX >= image.Width)
                    {
                        throw (new ImageBoundException("The number you entered exceeds the image size."));
                    }
                    if (startPointY >= image.Height || finishPointY >= image.Height)
                    {
                        throw (new ImageBoundException("The number you entered exceeds the image size."));
                    }

                    int[] startPoints  = { startPointX, startPointY };
                    int[] finishPoints = { finishPointX, finishPointY };
                    //Algoritmayı çağırma
                    PathFindingController pfc = new PathFindingController(true, startPoints, finishPoints, image);
                    stringError.Text = "";
                }
                catch (FormatException)
                {
                    stringError.Text = "Points you entered are not valid.";
                }
                catch (ImageBoundException ie)
                {
                    stringError.Text = ie.Message;
                }
            }
        }