Click here to Skip to main content
15,914,481 members
Home / Discussions / C#
   

C#

 
GeneralRe: Problems with streamwriter output to.csv..........help needed Pin
robustm13-Mar-08 4:00
robustm13-Mar-08 4:00 
GeneralCollections in c# Pin
Rachel888s12-Mar-08 6:41
Rachel888s12-Mar-08 6:41 
GeneralRe: Collections in c# Pin
Not Active12-Mar-08 6:50
mentorNot Active12-Mar-08 6:50 
JokeRe: Collections in c# Pin
Anthony Mushrow12-Mar-08 7:28
professionalAnthony Mushrow12-Mar-08 7:28 
GeneralControl C# Pin
paulhighstreet12-Mar-08 5:35
paulhighstreet12-Mar-08 5:35 
GeneralRe: Control C# Pin
Colin Angus Mackay12-Mar-08 5:39
Colin Angus Mackay12-Mar-08 5:39 
GeneralRe: Control C# Pin
paulhighstreet12-Mar-08 6:01
paulhighstreet12-Mar-08 6:01 
GeneralRe: Control C# Pin
DaveyM6912-Mar-08 6:03
professionalDaveyM6912-Mar-08 6:03 
GeneralRe: Control C# Pin
paulhighstreet12-Mar-08 7:23
paulhighstreet12-Mar-08 7:23 
General[Message Deleted] Pin
arkiboys12-Mar-08 5:04
arkiboys12-Mar-08 5:04 
GeneralRe: datagridview dynamic build Pin
Justin Perez12-Mar-08 5:12
Justin Perez12-Mar-08 5:12 
GeneralRe: [Message Deleted] Pin
Paul Conrad12-Mar-08 5:20
professionalPaul Conrad12-Mar-08 5:20 
Generaldatagridview .net 2.0 Pin
arkiboys12-Mar-08 4:53
arkiboys12-Mar-08 4:53 
General[Message Deleted] Pin
arkiboys12-Mar-08 4:21
arkiboys12-Mar-08 4:21 
GeneralRe: datagridview Pin
Justin Perez12-Mar-08 4:33
Justin Perez12-Mar-08 4:33 
GeneralPDF resize Pin
R.Myers12-Mar-08 4:03
R.Myers12-Mar-08 4:03 
GeneralFile sending problem in chat server Pin
Ranjan Kumar Mallick12-Mar-08 3:52
Ranjan Kumar Mallick12-Mar-08 3:52 
GeneralRe: File sending problem in chat server Pin
Not Active12-Mar-08 4:22
mentorNot Active12-Mar-08 4:22 
GeneralC# Command Line Argument Pin
Navneet Hegde12-Mar-08 3:44
Navneet Hegde12-Mar-08 3:44 
GeneralRe: C# Command Line Argument Pin
Not Active12-Mar-08 4:19
mentorNot Active12-Mar-08 4:19 
GeneralCsharp ADO change data in datagridview Pin
baranils12-Mar-08 3:37
baranils12-Mar-08 3:37 
GeneralRe: Csharp ADO change data in datagridview Pin
LongRange.Shooter13-Mar-08 4:57
LongRange.Shooter13-Mar-08 4:57 
GeneralRe: Csharp ADO change data in datagridview Pin
baranils13-Mar-08 7:06
baranils13-Mar-08 7:06 
Generalevent Issue Pin
Harvey Saayman12-Mar-08 2:37
Harvey Saayman12-Mar-08 2:37 
GeneralRe: event Issue Pin
Martin#12-Mar-08 3:33
Martin#12-Mar-08 3:33 
Hello Harvey!

My basic concept would be:
1) Creating an event in your ParentForm, which should be handled from the Child Forms
[CategoryAttribute("Harveys Events")]
[DescriptionAttribute("Happens when I want it!")]		
public event EventHandler HarveysParentEvent;

2)Creating an Basis MDIChild Form where all the ChildForms of your ParentForm inherit from!
//Basis Child
public class MDIBaseChild : System.Windows.Forms.Form

//Inherited Child
public class MDIChild1 : MDIBaseChild

3)This Base Form overrides the OnParentChanged as following and handles the "HarveysParentEvent" there!
private MDIParent mdiParent=null; //holds the reference to the parent form
 
protected override void OnParentChanged(EventArgs e)
{
    //MDIChild is added to the MDIParent
    if(Parent!=null)
    {
        if(mdiParent==null)
        {
            if(Parent is MdiClient)
            {
                mdiParent = Parent.TopLevelControl as MDIParent;
                if(mdiParent!=null)
                {
                    //Handles the event
                    mdiParent.HarveysParentEvent+=new EventHandler(mdiParent_HarveysParentEvent);
                }
            }
        }
    }
    //MDIChild has Closed and/or was removed from MDIParent
    else
    {
        if(mdiParent!=null)
        {
            //clears the reference to the parent Form
            mdiParent.Activated-=new EventHandler(mdiParent_HarveysParentEvent);
            mdiParent.HarveysParentEvent-=new EventHandler(mdiParent_HarveysParentEvent); //Edited
            mdiParent = null;
        }
    }
 
    base.OnParentChanged (e);
}

4) The "mdiParent_HarveysParentEvent" is declared as "protected virtual" and can now be overriden from the inherited Child Forms.
//Base Child code
protected virtual void mdiParent_HarveysParentEvent(object sender, EventArgs e)
{
}
 
//Inherited Child code
protected override void mdiParent_HarveysParentEvent(object sender, EventArgs e)
{
    //Implement your code here
 
    base.mdiParent_HarveysParentEvent(sender, e);
}

Hope it helps!

All the best,

Martin

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.