Click here to Skip to main content
15,881,882 members
Home / Discussions / C#
   

C#

 
GeneralRe: Accessing mdiParent form menu from mdiChild form via code Pin
Dave Kreskowiak15-Jul-10 2:02
mveDave Kreskowiak15-Jul-10 2:02 
AnswerRe: Accessing mdiParent form menu from mdiChild form via code [modified] Pin
DaveyM6914-Jul-10 23:54
professionalDaveyM6914-Jul-10 23:54 
GeneralRe: Accessing mdiParent form menu from mdiChild form via code Pin
AussieLew15-Jul-10 23:11
AussieLew15-Jul-10 23:11 
GeneralRe: Accessing mdiParent form menu from mdiChild form via code Pin
DaveyM6917-Jul-10 0:35
professionalDaveyM6917-Jul-10 0:35 
GeneralRe: Accessing mdiParent form menu from mdiChild form via code Pin
AussieLew27-Jul-10 13:08
AussieLew27-Jul-10 13:08 
GeneralRe: Accessing mdiParent form menu from mdiChild form via code Pin
DaveyM6930-Jul-10 10:47
professionalDaveyM6930-Jul-10 10:47 
GeneralRe: Accessing mdiParent form menu from mdiChild form via code Pin
AussieLew30-Jul-10 22:51
AussieLew30-Jul-10 22:51 
GeneralRe: Accessing mdiParent form menu from mdiChild form via code Pin
DaveyM6931-Jul-10 0:13
professionalDaveyM6931-Jul-10 0:13 
Yep - you're getting there and thinking along the right lines now!

The next problem you may come across is getting the result of the action request back to the child. There are two good methods for this.

1. You can have a property in your event args that the main (parent) from sets. This is the normally recommended method.
2. Sometimes a more intuitive way is to forget about the standard event signature and create your own delegate that actually returns a result. I've knocked up this quick sample to demonstrate.

C#
using System.Windows.Forms;

namespace CpDelegateSample
{
    public partial class FormMain : Form
    {
        private bool toggle;

        public FormMain()
        {
            InitializeComponent();
            toggle = false;
            FormSub formSub = new FormSub();
            formSub.DeleteRequest += new FormSub.DeleteRequestEventHandler(formSub_DeleteRequest);
            formSub.Show();
        }

        private bool formSub_DeleteRequest(string data)
        {
            // If OK, do delete and return true; otherwise, return false
            bool result = toggle;
            string message = result ? "Allowing" : "Denying";
            MessageBox.Show(string.Format("{0} {1}", message, data));
            toggle = !toggle;
            return result;
        }
    }
}

C#
using System;
using System.Windows.Forms;

namespace CpDelegateSample
{
    public partial class FormSub : Form
    {
        public delegate bool DeleteRequestEventHandler(string data);

        public event DeleteRequestEventHandler DeleteRequest;

        public FormSub()
        {
            InitializeComponent();
            Click += new EventHandler(FormSub_Click);
        }

        void FormSub_Click(object sender, EventArgs e)
        {

            OnDeleteRequest("ABC");
            OnDeleteRequest("DEF");
        }

        protected virtual void OnDeleteRequest(string data)
        {
            DeleteRequestEventHandler eh = DeleteRequest;
            if (eh != null)
            {
                bool result = eh(data);
                string message = result ? "Allowed" : "Denied";
                MessageBox.Show(string.Format("{0} {1}", message, data));
            }
        }
    }
}

Dave

If this helped, please vote & accept answer!


Binging is like googling, it just feels dirtier.
Please take your VB.NET out of our nice case sensitive forum.(Pete O'Hanlon)

BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)

QuestionList.Sort() Stability? Reliability...? Pin
ely_bob14-Jul-10 14:41
professionalely_bob14-Jul-10 14:41 
AnswerRe: List.Sort() Stability? Reliability...? Pin
Luc Pattyn14-Jul-10 15:17
sitebuilderLuc Pattyn14-Jul-10 15:17 
GeneralRe: List.Sort() Stability? Reliability...? Pin
Ennis Ray Lynch, Jr.15-Jul-10 3:22
Ennis Ray Lynch, Jr.15-Jul-10 3:22 
GeneralRe: List.Sort() Stability? Reliability...? Pin
Richard Blythe15-Jul-10 6:37
Richard Blythe15-Jul-10 6:37 
GeneralRe: List.Sort() Stability? Reliability...? Pin
Richard Blythe15-Jul-10 6:39
Richard Blythe15-Jul-10 6:39 
AnswerRe: List.Sort() Stability? Reliability...? Pin
Luc Pattyn15-Jul-10 7:15
sitebuilderLuc Pattyn15-Jul-10 7:15 
AnswerRe: List.Sort() Stability? Reliability...? Pin
Pete O'Hanlon15-Jul-10 10:37
mvePete O'Hanlon15-Jul-10 10:37 
QuestionHow do I format Column when a Gridview loads? Pin
roman_s14-Jul-10 9:14
roman_s14-Jul-10 9:14 
AnswerRe: How do I format Column when a Gridview loads? Pin
Luc Pattyn14-Jul-10 9:35
sitebuilderLuc Pattyn14-Jul-10 9:35 
GeneralRe: How do I format Column when a Gridview loads? Pin
roman_s14-Jul-10 10:06
roman_s14-Jul-10 10:06 
GeneralRe: How do I format Column when a Gridview loads? Pin
Luc Pattyn14-Jul-10 10:18
sitebuilderLuc Pattyn14-Jul-10 10:18 
GeneralRe: How do I format Column when a Gridview loads? Pin
roman_s14-Jul-10 10:31
roman_s14-Jul-10 10:31 
AnswerRe: How do I format Column when a Gridview loads? Pin
T M Gray14-Jul-10 10:17
T M Gray14-Jul-10 10:17 
GeneralRe: How do I format Column when a Gridview loads? Pin
Luc Pattyn14-Jul-10 10:21
sitebuilderLuc Pattyn14-Jul-10 10:21 
GeneralRe: How do I format Column when a Gridview loads? Pin
T M Gray14-Jul-10 10:37
T M Gray14-Jul-10 10:37 
GeneralRe: How do I format Column when a Gridview loads? Pin
Luc Pattyn14-Jul-10 11:08
sitebuilderLuc Pattyn14-Jul-10 11:08 
QuestionSMF Forum login using webclient [modified] Pin
Skymir14-Jul-10 8:06
Skymir14-Jul-10 8:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.