C# Custom Event Question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • deviantseev
    New Member
    • Sep 2008
    • 3

    C# Custom Event Question

    Hi I am writing a custom tab control. I am capturing a caption property in a page which then changes the caption of the associated tab. (Similar to window's tab control).

    I am using a delegate to capture the event of the change of the property and then I am changing the text value of the associated tab. The problem is that after I added the delegate code, I am unable to render the form in the designer. It's telling me that the 'Object reference not set to an instance of an object.'

    The error is traced back to the InitializeCompo nent() where the user control attempts to set the default value on the caption property.

    Here is the code snippets.

    Error happens here:
    Code:
    this.tabPanelPageContainer1.Caption = "";
    Property code:
    Code:
    public string Caption
            {
                get
                {
                    return _caption;
                }
                set
                {
                    _caption = value;
                    OnCaptionChange(new PageEventArgs(_caption));
                }
            }
    Delegate Class
    Code:
    /// <summary>
        /// Event arguments class for the page events
        /// </summary>
        public class PageEventArgs : EventArgs
        {
            private string _caption;
    
            public PageEventArgs(string caption)
            {
                _caption = caption;
            }
    
            public string CaptionValue
            {
                get
                {
                    return _caption;
                }
            }
        }
    Any idea why it's doing this?
    Last edited by deviantseev; Sep 17 '08, 06:50 PM. Reason: Code correction
  • balabaster
    Recognized Expert Contributor
    • Mar 2007
    • 798

    #2
    I would hazard a guess that it's trying to assign a value to an object that technically doesn't exist yet. For instance - when you try and set the value in the initialize, it will fail because the object doesn't exist until the initialize phase is completed. Usually you would do stuff like this in the PreRender phase where you know the object exists...

    Comment

    • deviantseev
      New Member
      • Sep 2008
      • 3

      #3
      Originally posted by balabaster
      I would hazard a guess that it's trying to assign a value to an object that technically doesn't exist yet. For instance - when you try and set the value in the initialize, it will fail because the object doesn't exist until the initialize phase is completed. Usually you would do stuff like this in the PreRender phase where you know the object exists...
      Yeah, I am trying to get to the bottom of why the object is not being initialized but when I attach visual studio to the debugger and launch, it does not seem to be hitting the breakpoint set within the parent's InitializeCompo nent(). Any ideas on how else I can debug this issue?

      Comment

      Working...