Ejemplo n.º 1
0
 public void CreateControl(object sender, EventArgs e, Panel Parent, string typeControl, int OX, int OY)
 {
     if (typeControl == "Button")
     {
         //Button ctrl = new Button();
         UsersButton ctrl = new UsersButton();
         model.GetParametersButton(ctrl, Parent, OX, OY);
         Parent.Controls.Add(ctrl);
         ctrl.MouseDown += new System.Windows.Forms.MouseEventHandler(this.ControlMouseDown);
         ctrl.MouseUp   += new System.Windows.Forms.MouseEventHandler(this.ControlMouseUp);
         ctrl.MouseMove += new System.Windows.Forms.MouseEventHandler(this.ControlMouseMove);
         view.AddControl(ctrl);
     }
     if (typeControl == "Switcher")
     {
         //Label ctrl = new Label();
         UserSwitcher ctrl = new UserSwitcher();
         model.GetParametersSwitcher(ctrl, Parent, OX, OY);
         Parent.Controls.Add(ctrl);
         ctrl.MouseDown += new System.Windows.Forms.MouseEventHandler(this.ControlMouseDown);
         ctrl.MouseUp   += new System.Windows.Forms.MouseEventHandler(this.ControlMouseUp);
         ctrl.MouseMove += new System.Windows.Forms.MouseEventHandler(this.ControlMouseMove);
         view.AddControl(ctrl);
     }
     if (typeControl == "CheckBox")
     {
         //CheckBox ctrl = new CheckBox();
         CheckButton ctrl = new CheckButton();
         model.GetParametersCheckBox(ctrl, Parent, OX, OY);
         Parent.Controls.Add(ctrl);
         ctrl.MouseDown += new System.Windows.Forms.MouseEventHandler(this.ControlMouseDown);
         ctrl.MouseUp   += new System.Windows.Forms.MouseEventHandler(this.ControlMouseUp);
         ctrl.MouseMove += new System.Windows.Forms.MouseEventHandler(this.ControlMouseMove);
         view.AddControl(ctrl);
     }
     if (typeControl == "TextBox")
     {
         //Label ctrl = new Label();
         UserText ctrl = new UserText();
         model.GetParametersTextBox(ctrl, Parent, OX, OY);
         Parent.Controls.Add(ctrl);
         ctrl.MouseDown += new System.Windows.Forms.MouseEventHandler(this.ControlMouseDown);
         ctrl.MouseUp   += new System.Windows.Forms.MouseEventHandler(this.ControlMouseUp);
         ctrl.MouseMove += new System.Windows.Forms.MouseEventHandler(this.ControlMouseMove);
         view.AddControl(ctrl);
     }
     if (typeControl == "PictureBox")
     {
         //PictureBox ctrl = new PictureBox();
         UserImage ctrl = new UserImage();
         model.GetParametersPictureBox(ctrl, Parent, OX, OY);
         Parent.Controls.Add(ctrl);
         ctrl.MouseDown += new System.Windows.Forms.MouseEventHandler(this.ControlMouseDown);
         ctrl.MouseUp   += new System.Windows.Forms.MouseEventHandler(this.ControlMouseUp);
         ctrl.MouseMove += new System.Windows.Forms.MouseEventHandler(this.ControlMouseMove);
         view.AddControl(ctrl);
     }
     if (typeControl == "ValueBox")
     {
         ValueBox ctrl = new ValueBox();
         model.GetParametersValueBox(ctrl, Parent, OX, OY);
         Parent.Controls.Add(ctrl);
         ctrl.MouseDown += new System.Windows.Forms.MouseEventHandler(this.ControlMouseDown);
         ctrl.MouseUp   += new System.Windows.Forms.MouseEventHandler(this.ControlMouseUp);
         ctrl.MouseMove += new System.Windows.Forms.MouseEventHandler(this.ControlMouseMove);
         view.AddControl(ctrl);
     }
     ParentForMouseActivity = Parent;
 }
Ejemplo n.º 2
0
        public void Load(string filename, Panel Parent, ListBox ListOfFigures)
        {
            XmlSerializer formatter = new XmlSerializer(typeof(XMLLayout));

            using (FileStream fileStream = new FileStream(filename, FileMode.Open, FileAccess.Read))
            {
                XMLLayout layout = (XMLLayout)formatter.Deserialize(fileStream);
                try
                {
                    //PropertyControls[] propertyControlsAll = (PropertyControls[])formatter.Deserialize(fileStream);
                    foreach (PropertyControls propertyControls in layout.PropertyControls)
                    {
                        if (propertyControls.type == "Button")
                        {
                            Button ctrl = new Button();
                            model.LoadButtonData(ctrl, propertyControls);
                            Parent.Controls.Add(ctrl);
                            ctrl.MouseDown += new System.Windows.Forms.MouseEventHandler(this.ControlMouseDown);
                            ctrl.MouseUp   += new System.Windows.Forms.MouseEventHandler(this.ControlMouseUp);
                            view.AddControl(ctrl);
                        }
                        if (propertyControls.type == "CheckBox")
                        {
                            CheckBox ctrl = new CheckBox();
                            model.LoadCheckBoxData(ctrl, propertyControls);
                            Parent.Controls.Add(ctrl);
                            ctrl.MouseDown += new System.Windows.Forms.MouseEventHandler(this.ControlMouseDown);
                            ctrl.MouseUp   += new System.Windows.Forms.MouseEventHandler(this.ControlMouseUp);
                            view.AddControl(ctrl);
                        }
                        if (propertyControls.type == "PictureBox")
                        {
                            PictureBox ctrl = new PictureBox();
                            model.LoadPictureBoxData(ctrl, propertyControls);
                            Parent.Controls.Add(ctrl);
                            ctrl.MouseDown += new System.Windows.Forms.MouseEventHandler(this.ControlMouseDown);
                            ctrl.MouseUp   += new System.Windows.Forms.MouseEventHandler(this.ControlMouseUp);
                            view.AddControl(ctrl);
                        }
                        if (propertyControls.type == "ValueBox")
                        {
                            ValueBox ctrl = new ValueBox();
                            model.LoadValueBoxData(ctrl, propertyControls);
                            Parent.Controls.Add(ctrl);
                            ctrl.MouseDown += new System.Windows.Forms.MouseEventHandler(this.ControlMouseDown);
                            ctrl.MouseUp   += new System.Windows.Forms.MouseEventHandler(this.ControlMouseUp);
                            view.AddControl(ctrl);
                        }
                        if (propertyControls.type == "UserText")
                        {
                            UserText ctrl = new UserText();
                            model.LoadTextBoxData(ctrl, propertyControls);
                            Parent.Controls.Add(ctrl);
                            ctrl.MouseDown += new System.Windows.Forms.MouseEventHandler(this.ControlMouseDown);
                            ctrl.MouseUp   += new System.Windows.Forms.MouseEventHandler(this.ControlMouseUp);
                            view.AddControl(ctrl);
                        }
                        if (propertyControls.type == "UserImage")
                        {
                            UserImage ctrl = new UserImage();
                            model.LoadImageBoxData(ctrl, propertyControls);
                            Parent.Controls.Add(ctrl);
                            ctrl.MouseDown += new System.Windows.Forms.MouseEventHandler(this.ControlMouseDown);
                            ctrl.MouseUp   += new System.Windows.Forms.MouseEventHandler(this.ControlMouseUp);
                            view.AddControl(ctrl);
                        }
                        if (propertyControls.type == "Label")
                        {
                            if (propertyControls.name.Contains("Switcher"))
                            {
                                Label ctrl = new Label();
                                model.LoadSwitcherData(ctrl, propertyControls);
                                Parent.Controls.Add(ctrl);
                                ctrl.MouseDown += new System.Windows.Forms.MouseEventHandler(this.ControlMouseDown);
                                ctrl.MouseUp   += new System.Windows.Forms.MouseEventHandler(this.ControlMouseUp);
                                view.AddControl(ctrl);
                            }
                            if (propertyControls.name.Contains("TextBox"))
                            {
                                Label ctrl = new Label();
                                model.LoadTextBoxData(ctrl, propertyControls);
                                Parent.Controls.Add(ctrl);
                                ctrl.MouseDown += new System.Windows.Forms.MouseEventHandler(this.ControlMouseDown);
                                ctrl.MouseUp   += new System.Windows.Forms.MouseEventHandler(this.ControlMouseUp);
                                view.AddControl(ctrl);
                            }
                        }
                        if (propertyControls.type == "UserSwitcher")
                        {
                            UserSwitcher userSwitcher = new UserSwitcher();
                            model.LoadUserSwitcherData(userSwitcher, propertyControls);
                            Parent.Controls.Add(userSwitcher);
                            userSwitcher.MouseDown += new System.Windows.Forms.MouseEventHandler(this.ControlMouseDown);
                            userSwitcher.MouseUp   += new System.Windows.Forms.MouseEventHandler(this.ControlMouseUp);
                            view.AddControl(userSwitcher);
                        }
                        if (propertyControls.type == "CheckButton")
                        {
                            CheckButton checkButton = new CheckButton();
                            model.LoadCheckButtonData(checkButton, propertyControls);
                            Parent.Controls.Add(checkButton);
                            checkButton.MouseDown += new System.Windows.Forms.MouseEventHandler(this.ControlMouseDown);
                            checkButton.MouseUp   += new System.Windows.Forms.MouseEventHandler(this.ControlMouseUp);
                            view.AddControl(checkButton);
                        }
                        if (propertyControls.type == "UsersButton")
                        {
                            UsersButton usersButton = new UsersButton();
                            model.LoadUsersButtonData(usersButton, propertyControls);
                            Parent.Controls.Add(usersButton);
                            usersButton.MouseDown += new System.Windows.Forms.MouseEventHandler(this.ControlMouseDown);
                            usersButton.MouseUp   += new System.Windows.Forms.MouseEventHandler(this.ControlMouseUp);
                            view.AddControl(usersButton);
                        }
                    }
                }
                catch (SerializationException e)
                {
                    Console.WriteLine("Failed to deserialize figures. Reason: " + e.Message);
                }
                try
                {
                    //Figures[] figuresList = (Figures[])formatter.Deserialize(fileStream);
                    foreach (Figures figures in layout.Figures)
                    {
                        Image    img            = Parent.BackgroundImage ?? new Bitmap(Parent.Width, Parent.Height);
                        Graphics g              = Graphics.FromImage(img);
                        Pen      BlackPen       = new Pen(Color.Black, 2);
                        string[] NamesOfFigures = model.LoadFigures(g, BlackPen, figures);
                        for (int i = 0; i < NamesOfFigures.Length; i++)
                        {
                            ListOfFigures.Items.Add(NamesOfFigures[i]);
                        }
                        g.Flush();
                        Parent.BackgroundImage = img;
                        Parent.Refresh();
                        g.Dispose();
                    }
                }
                catch (SerializationException e)
                {
                    Console.WriteLine("Failed to deserialize figures. Reason: " + e.Message);
                }
                try
                {
                    foreach (string[] scripts in layout.Scripts)
                    {
                        view.AddToScriptList(scripts);
                    }
                }
                catch (SerializationException e)
                {
                    Console.WriteLine("Failed to deserialize figures. Reason: " + e.Message);
                }
                if (fileStream.Position == fileStream.Length)
                {
                    fileStream.Close();
                }
            }
            ParentForMouseActivity = Parent;
        }
Ejemplo n.º 3
0
        public void ControlMouseUp(object sender, MouseEventArgs e)
        {
            Control control = sender as Control;

            MousePositionUp = Cursor.Position;
            if (MousePositionUp == MousePositionDown)
            {
                if (IsCtrlPressed == false)
                {
                    foreach (Control cnt in ParentForMouseActivity.Controls)
                    {
                        Button tb = cnt as Button;
                        if (tb != null)
                        {
                            tb.FlatStyle = System.Windows.Forms.FlatStyle.Standard;
                        }
                        Label label1 = cnt as Label;
                        if (label1 != null)
                        {
                            label1.BorderStyle = System.Windows.Forms.BorderStyle.None;
                        }
                        CheckBox ckb1 = cnt as CheckBox;
                        if (ckb1 != null)
                        {
                            ckb1.BackColor = System.Drawing.Color.Transparent;
                        }
                        PictureBox pic1 = cnt as PictureBox;
                        if (pic1 != null)
                        {
                            pic1.BorderStyle = System.Windows.Forms.BorderStyle.None;
                        }
                        UserSwitcher usersw = cnt as UserSwitcher;
                        if (usersw != null)
                        {
                            usersw.BorderStyle = System.Windows.Forms.BorderStyle.None;
                        }
                        CheckButton usercb = cnt as CheckButton;
                        if (usercb != null)
                        {
                            usercb.BorderStyle = System.Windows.Forms.BorderStyle.None;
                        }
                        UsersButton userbtn = cnt as UsersButton;
                        if (userbtn != null)
                        {
                            userbtn.BorderStyle = System.Windows.Forms.BorderStyle.None;
                        }
                        ValueBox valueBox = cnt as ValueBox;
                        if (valueBox != null)
                        {
                            valueBox.BorderStyle = System.Windows.Forms.BorderStyle.None;
                        }
                        UserText textBox = cnt as UserText;
                        if (textBox != null)
                        {
                            textBox.BorderStyle = System.Windows.Forms.BorderStyle.None;
                        }
                        UserImage userImage = cnt as UserImage;
                        if (userImage != null)
                        {
                            userImage.BorderStyle = System.Windows.Forms.BorderStyle.None;
                        }
                    }
                    view.SelectControl(sender, null, true);
                    if (sender as Button != null)
                    {
                        Button button = sender as Button; button.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
                    }
                    if (sender as Label != null)
                    {
                        Label label = sender as Label; label.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
                    }
                    if (sender as CheckBox != null)
                    {
                        CheckBox checkbox = sender as CheckBox; checkbox.BackColor = System.Drawing.Color.LightGray;
                    }
                    if (sender as PictureBox != null)
                    {
                        PictureBox picturebox = sender as PictureBox; picturebox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
                    }
                    if (sender as UserSwitcher != null)
                    {
                        UserSwitcher userSwitcher = sender as UserSwitcher; userSwitcher.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
                    }
                    if (sender as CheckButton != null)
                    {
                        CheckButton checkButton = sender as CheckButton; checkButton.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
                    }
                    if (sender as UsersButton != null)
                    {
                        UsersButton usersButton = sender as UsersButton; usersButton.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
                    }
                    if (sender as ValueBox != null)
                    {
                        ValueBox valueBox = sender as ValueBox; valueBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
                    }
                    if (sender as UserText != null)
                    {
                        UserText userText = sender as UserText; userText.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
                    }
                    if (sender as UserImage != null)
                    {
                        UserImage userImage = sender as UserImage; userImage.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
                    }
                    view.AddToListOfControl(ParentForMouseActivity.Controls[ParentForMouseActivity.Controls.IndexOf(control)].Name, true);
                }
                else
                {
                    if (control.GetType() == typeof(Button))
                    {
                        Button controlbutton = control as Button;
                        controlbutton.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
                    }
                    if (control.GetType() == typeof(Label))
                    {
                        Label controllabel = control as Label;
                        controllabel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
                    }
                    if (control.GetType() == typeof(CheckBox))
                    {
                        CheckBox controlcheckbox = control as CheckBox;
                        controlcheckbox.BackColor = System.Drawing.Color.LightGray;
                    }
                    if (control.GetType() == typeof(PictureBox))
                    {
                        PictureBox controlpicturebox = control as PictureBox;
                        controlpicturebox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
                    }
                    if (control.GetType() == typeof(UserSwitcher))
                    {
                        UserSwitcher userSwitcher = control as UserSwitcher;
                        userSwitcher.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
                    }
                    if (control.GetType() == typeof(CheckButton))
                    {
                        CheckButton checkButton = control as CheckButton;
                        checkButton.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
                    }
                    if (control.GetType() == typeof(UsersButton))
                    {
                        UsersButton usersButton = control as UsersButton;
                        usersButton.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
                    }
                    if (control.GetType() == typeof(ValueBox))
                    {
                        ValueBox valueBox = control as ValueBox;
                        valueBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
                    }
                    if (control.GetType() == typeof(UserText))
                    {
                        UserText textBox = control as UserText;
                        textBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
                    }
                    if (control.GetType() == typeof(UserImage))
                    {
                        UserImage userImage = control as UserImage;
                        userImage.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
                    }
                    controls.Add(control);
                    object[] arrayControls = controls.ToArray();
                    view.SelectControl(sender, arrayControls, false);
                    foreach (Control ind in arrayControls)
                    {
                        int inde = ParentForMouseActivity.Controls.IndexOf(ind);
                        if (inde >= 0)
                        {
                            view.AddToListOfControl(ParentForMouseActivity.Controls[inde].Name, false);
                        }
                    }
                }
            }
            else
            {
                if (resize)
                {
                    if (east && (MousePositionUp.X - MousePositionDown.X) > -control.Width)
                    {
                        control.Width = control.Width + (MousePositionUp.X - MousePositionDown.X);
                    }
                    if (south && (MousePositionUp.Y - MousePositionDown.Y) > -control.Height)
                    {
                        control.Height = control.Height + (MousePositionUp.Y - MousePositionDown.Y);
                    }
                    if (north && (MousePositionUp.Y - MousePositionDown.Y) < control.Height)
                    {
                        control.Location = new Point(control.Location.X, control.Location.Y + (MousePositionUp.Y - MousePositionDown.Y));
                        control.Height   = control.Height - (MousePositionUp.Y - MousePositionDown.Y);
                    }
                    if (west && (MousePositionUp.X - MousePositionDown.X) < control.Width)
                    {
                        control.Location = new Point(control.Location.X + (MousePositionUp.X - MousePositionDown.X), control.Location.Y);
                        control.Width    = control.Width - (MousePositionUp.X - MousePositionDown.X);
                    }
                    east   = false;
                    south  = false;
                    north  = false;
                    west   = false;
                    resize = false;
                }
                else
                {
                    control.DoDragDrop(sender, DragDropEffects.Move);
                }
            }
        }