Layout-Resize-OnLoad

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John

    #1

    Layout-Resize-OnLoad

    Hi,
    This is my first experiment with C#, I'm trying to handle the resize
    event. According to the documentation I should handle the Layout event
    for this. My question is: how do I register this event? The following
    code does not work because I never recieve the OnLoad event. What am I
    doing wrong?

    public class frmMain : System.Windows. Forms.Form
    {
    protected virtual void OnLoad(EventArg s e)
    {
    frmMain.ActiveF orm.Layout += new
    System.Windows. Forms.LayoutEve ntHandler(this. frmMain_Layout) ;
    }

    private void frmMain_Layout( object sender,
    System.Windows. Forms.LayoutEve ntArgs e)
    {
    splMain.Left = pgTasks.Left + pgTasks.Width;
    splMain.Height = this.Height;
    }
    }

    Another question, while I'm here, the line:

    frmMain.ActiveF orm.Layout += new
    System.Windows. Forms.LayoutEve ntHandler(this. frmMain_Layout) ;

    does not make sense to me. I would think that the line should be:

    this.ActiveForm .Layout += new
    System.Windows. Forms.LayoutEve ntHandler(this. frmMain_Layout) ;

    replacing 'frmMain' with 'this' but the 'this' object reference has a
    very different set of intellisense attributes, of which ActiveForm is
    not one of them.

    Thanks

  • John

    #2
    Re: Layout-Resize-OnLoad

    John wrote:
    [color=blue]
    > protected virtual void OnLoad(EventArg s e)
    > {
    > frmMain.ActiveF orm.Layout += new
    > System.Windows. Forms.LayoutEve ntHandler(this. frmMain_Layout) ;
    > }[/color]

    Sorry for the, somewhat, quick post, replacing 'virtual' with 'override'
    solves the OnLoad problem, but it still doesn't solve the original
    question: How do I register the LayoutEventHand ler?

    Registering in the OnLoad event is incorrect because ActiveForm is null
    at that point.

    Thanks

    Comment

    • Daniel O'Connell

      #3
      Re: Layout-Resize-OnLoad

      I take it you are coming from VB6?

      frmMain.ActiveF orm is a static member, and is not what you should be doing.
      Instead
      this.Layout + = new
      System.Windows. Forms.LayoutEve ntHandle(this.f rmMain_Layout);
      should work.
      Also, you could simply override OnLayout in your form class, just make sure
      you call base.OnLayout.
      "John" <john@no_spam > wrote in message
      news:%23$y6Dmad DHA.2296@TK2MSF TNGP09.phx.gbl. ..[color=blue]
      > John wrote:
      >[color=green]
      > > protected virtual void OnLoad(EventArg s e)
      > > {
      > > frmMain.ActiveF orm.Layout += new
      > > System.Windows. Forms.LayoutEve ntHandler(this. frmMain_Layout) ;
      > > }[/color]
      >
      > Sorry for the, somewhat, quick post, replacing 'virtual' with 'override'
      > solves the OnLoad problem, but it still doesn't solve the original
      > question: How do I register the LayoutEventHand ler?
      >
      > Registering in the OnLoad event is incorrect because ActiveForm is null
      > at that point.
      >
      > Thanks
      >[/color]


      Comment

      • Jay B. Harlow [MVP - Outlook]

        #4
        Re: Layout-Resize-OnLoad

        John,
        Just like you can override the OnLoad method to handle the Load event, you
        can override the OnLayout method to handle the Layout event. In both cases
        remember to call your base.OnLoad or base.OnLayout method.

        Overriding the method is more efficient than handling the event for the
        current class.

        http://msdn.microsoft.com/library/de...ayoutTopic.asp

        Hope this helps
        Jay

        "John" <john@no_spam > wrote in message
        news:uA52LOadDH A.1932@TK2MSFTN GP10.phx.gbl...[color=blue]
        > Hi,
        > This is my first experiment with C#, I'm trying to handle the resize
        > event. According to the documentation I should handle the Layout event
        > for this. My question is: how do I register this event? The following
        > code does not work because I never recieve the OnLoad event. What am I
        > doing wrong?
        >
        > public class frmMain : System.Windows. Forms.Form
        > {
        > protected virtual void OnLoad(EventArg s e)
        > {
        > frmMain.ActiveF orm.Layout += new
        > System.Windows. Forms.LayoutEve ntHandler(this. frmMain_Layout) ;
        > }
        >
        > private void frmMain_Layout( object sender,
        > System.Windows. Forms.LayoutEve ntArgs e)
        > {
        > splMain.Left = pgTasks.Left + pgTasks.Width;
        > splMain.Height = this.Height;
        > }
        > }
        >
        > Another question, while I'm here, the line:
        >
        > frmMain.ActiveF orm.Layout += new
        > System.Windows. Forms.LayoutEve ntHandler(this. frmMain_Layout) ;
        >
        > does not make sense to me. I would think that the line should be:
        >
        > this.ActiveForm .Layout += new
        > System.Windows. Forms.LayoutEve ntHandler(this. frmMain_Layout) ;
        >
        > replacing 'frmMain' with 'this' but the 'this' object reference has a
        > very different set of intellisense attributes, of which ActiveForm is
        > not one of them.
        >
        > Thanks
        >[/color]


        Comment

        Working...