コード例 #1
0
        bool isAnyWindowSelected = false;   //if true: an existing window will be resized; if false: a new window will be created


        private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
        {
            if (pictureBox1.Image == null)
            {
                return;
            }

            // all existing boxes are checked if any handle node is selected
            isAnyWindowSelected = false;
            foreach (ResizableRectangle item in displayedResizableRectangleList)
            {
                if (item.nodeSelected != ResizableRectangle.PosSizableRect.None)
                {
                    isAnyWindowSelected            = true;
                    selectedResizableRectangle     = item;
                    toolStripTextBoxTruncated.Text = selectedResizableRectangle.truncated.ToString();
                }
            }

            //mouse down coordinates are remembered
            draw = true;
            mouseDownCoordinates.X = e.X;
            mouseDownCoordinates.Y = e.Y;

            // if no box is selected, a new one is created
            if (!isAnyWindowSelected)
            {
                CurrentObjectClass selectedObjectClass = currentObjectClassList.Find(objectToFind => objectToFind.radioButton.Checked == true);

                currentResizableRectangle                    = new ResizableRectangle(new Rectangle(e.X, e.Y, 0, 0));
                currentResizableRectangle.className          = selectedObjectClass.className;
                currentResizableRectangle.boxColor           = selectedObjectClass.color;
                currentResizableRectangle.currentObjectClass = selectedObjectClass;
                currentResizableRectangle.sizeNodeRect       = sizeNodeRect;
                currentResizableRectangle.SetPictureBox(this.pictureBox1);

                selectedResizableRectangle     = currentResizableRectangle;
                toolStripTextBoxTruncated.Text = selectedResizableRectangle.truncated.ToString();

                // makes sure that this mouseButton-Event is executed last, after all ResizableRectangles are checked for selected nodes
                pictureBox1.MouseDown -= new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseDown);
                pictureBox1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseDown);
            }
        }
コード例 #2
0
        public void addannewButton()
        {
            // a new object class ist instantiated
            CurrentObjectClass newCurrentObjectClass = new CurrentObjectClass();

            // name of the new object class is given by the class number
            newCurrentObjectClass.className = "Class" + currentObjectClassList.Count;

            // a random color is chosen for the new button
            Random randomGen = new Random();

            KnownColor[] names           = (KnownColor[])Enum.GetValues(typeof(KnownColor));
            KnownColor   randomColorName = names[randomGen.Next(names.Length)];

            newCurrentObjectClass.color = Color.FromKnownColor(randomColorName);

            // new UI elelments are added to the groupBoxObjectClasses
            addNewGroupBoxObjectClasse(newCurrentObjectClass);
            // new ObjectClass is added to the List
            currentObjectClassList.Add(newCurrentObjectClass);
        }
コード例 #3
0
        public void addNewGroupBoxObjectClasse(CurrentObjectClass newCurrentObjectClass)
        {
            //groupBoxObjectClassesS.Height += 30; //more space for new UI elements

            // new ColorButton is added to the groupBox
            Button newClassColorButton = new Button();

            newClassColorButton.Text          = String.Empty;
            newClassColorButton.Name          = "ColorButton";
            newClassColorButton.Size          = new Size(20, 20);
            newClassColorButton.Location      = new Point(185, 15 + currentObjectClassList.Count * 30);
            newClassColorButton.BackColor     = newCurrentObjectClass.color;
            newClassColorButton.Click        += new System.EventHandler(button1_Click); //Click-Event for color changing
            newCurrentObjectClass.colorButton = newClassColorButton;                    // reference to this colorButton is connected to the currentObjectClass
            // Tooltip is added to the button
            this.toolTipUlabeledButton.SetToolTip(newClassColorButton, "Set the color of the bounding box for this class.");


            // new TextBox with the name of the Class is added to the groupBox
            TextBox newClassTextBox = new TextBox();

            newCurrentObjectClass.textBox = newClassTextBox;
            newClassTextBox.Location      = new Point(25, 15 + currentObjectClassList.Count * 30);
            newClassTextBox.Size          = new Size(140, 25);
            newClassTextBox.Text          = newCurrentObjectClass.className;
            newClassTextBox.ReadOnly      = false;
            newClassTextBox.TextChanged  += new EventHandler(newClassTextBox_TextChanged);
            // Tooltip is added to the button
            this.toolTipUlabeledButton.SetToolTip(newClassTextBox, "Enter the name for this class. This name will be save into the label file.");

            // new bulletButton is added to the groupBox
            RadioButton newClassRadioButton = new RadioButton();

            newCurrentObjectClass.radioButton = newClassRadioButton;
            newClassRadioButton.Name          = "RadioButton";
            newClassRadioButton.Text          = String.Empty;
            newClassRadioButton.Location      = new Point(5, 13 + currentObjectClassList.Count * 30);
            if (currentObjectClassList.Count == 0)
            {
                newClassRadioButton.Checked = true;                                    //the first bulletBox ist checked
            }
            // Tooltip is added to the button
            this.toolTipUlabeledButton.SetToolTip(newClassRadioButton, "Select an object class. This class name and color will be used when you draw a new bounding box onto the image.");

            // eventHandler for changes in the class names
            void newClassTextBox_TextChanged(object sender, EventArgs e)
            {
                TextBox            changedTextBox  = sender as TextBox;
                CurrentObjectClass findObjectClass = currentObjectClassList.Find(objectToFind => objectToFind.textBox == changedTextBox);

                findObjectClass.className = changedTextBox.Text;
                this.updateResizableBoxes();
            }

            // eventHandler for changes in the class color
            void button1_Click(object sender, System.EventArgs e)
            {
                Button klickedbutton = sender as Button;

                if (colorDialog1S.ShowDialog() == DialogResult.OK)
                {
                    newClassColorButton.BackColor = colorDialog1S.Color;
                    CurrentObjectClass findObjectClass = currentObjectClassList.Find(objectToFind => objectToFind.colorButton == klickedbutton);
                    findObjectClass.color = newClassColorButton.BackColor;
                    updateResizableBoxes();
                }
            }

            panelObjectClassesS.Controls.Add(newClassTextBox);
            panelObjectClassesS.Controls.Add(newClassRadioButton);
            panelObjectClassesS.Controls.Add(newClassColorButton);
        }