Ejemplo n.º 1
0
    private void btnAddWindow_Click(object sender, System.EventArgs e)
    {
        // Are any text fields blank?
        if (txtLeft.Text.Length == 0 || txtTop.Text.Length == 0 ||
            txtWidth.Text.Length == 0 || txtHeight.Text.Length == 0)
        {
            MessageBox.Show("Please fill in all text boxes",
                            "Error",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Error);
            return;
        }

        ChildForm aChildForm = new ChildForm();

        aChildForm.Owner         = this;
        aChildForm.DesktopBounds = new Rectangle(
            Int32.Parse(txtLeft.Text),
            Int32.Parse(txtTop.Text),
            Int32.Parse(txtWidth.Text),
            Int32.Parse(txtHeight.Text));
        aChildForm.Show();

        // Create a new delegate for the child form's Repaint method
        ChangeColorDelegate newDelegate = new ChangeColorDelegate(aChildForm.Repaint);


        // Combine new delegate into the multicast delegate
        mAllRepaintMethods = (ChangeColorDelegate)System.Delegate.Combine(mAllRepaintMethods,
                                                                          newDelegate);

        // Use multicast delegate to count the child forms
        sbStatus.Text = "Created child form " +
                        mAllRepaintMethods.GetInvocationList().Length + ".";
    }
 private void ChangeColorThreadSafe(Color c)
 {
     if (button1.InvokeRequired)
     {
         ChangeColorDelegate delgate = new ChangeColorDelegate(ChangeColorThreadSafe);
         button1.Invoke(delgate, new object[] { c });
     }
     else
     {
         this.BackColor = c;
     }
 }
Ejemplo n.º 3
0
        // Constructor
        public MainForm()
        {
            InitializeComponent();
            alphabet.Add(0, "hello");
            alphabet.Add(1, "world");
            alphabet.Add(2, "I am");
            alphabet.Add(3, "student");
            alphabet.Add(4, "good");
            alphabet.Add(5, "bye");
            alphabet.Add(10, " ");

            comboCalculateNewColor.SelectedIndex = 0;
            _changeColorDelegate = this.ChangeColor;
        }
Ejemplo n.º 4
0
    public void ChildFormClosing(ChildForm aChildForm)
    {
        // Create a delegate for the ChildForm that is closing
        ChangeColorDelegate unneededDelegate = new ChangeColorDelegate(aChildForm.Repaint);

        // Remove the delegate from the multicast delegate
        mAllRepaintMethods = (ChangeColorDelegate)System.Delegate.Remove(mAllRepaintMethods, unneededDelegate);

        // If multicast delegate is Nothing, there are no child forms left
        if (mAllRepaintMethods == null)
        {
            sbStatus.Text = "Final child form has been closed.";
        }
        else
        {
            // Use multicast delegate to count the child forms
            sbStatus.Text = "Child form closed, " + mAllRepaintMethods.GetInvocationList().Length + " form(s) remaining.";
        }
    }