paulwhelan
asked on
this.shown not allowed?
Hi
Im trying to add an event handler to show a message box when a property page is first opened.
But the Shown Event Hanlder doesnt appear in the property pages.
//
// ElementLabelControlPropert yPage
//
this.BackColor = System.Drawing.Color.Trans parent;
this.Controls.Add(this._oE lementLabe lDescripti onRadioBut ton);
this.Controls.Add(this._oE lementLabe lNameRadio Button);
this.Controls.Add(this.lab el4);
this.Controls.Add(this.lab el2);
this.Controls.Add(this._oE lementLabe lNameTextB ox);
this.Controls.Add(this._cI nsertEleme ntReferenc eButton);
this.Controls.Add(this.lab el5);
this.Controls.Add(this.lab el1);
this.Controls.Add(this.lab el7);
this.Location = new System.Drawing.Point(13, 13);
this.Name = "ElementLabelControlProper tyPage";
this.Size = new System.Drawing.Size(380, 291);
//this.shown
//only this.show comes up with intellisense
this.Enter += new System.EventHandler(this.E lementLabe lControlPr opertyPage _Enter);
this.VisibleChanged += new System.EventHandler(this.E lementLabe lControlPr opertyPage _VisibleCh anged);
this.Load += new System.EventHandler(this.E lementLabe lControlPr opertyPage _Load);
this.ResumeLayout(false);
this.PerformLayout();
Thanks
Paul
More info here.
https://www.experts-exchange.com/questions/21829411/this-ParentForm-Shown.html
Im trying to add an event handler to show a message box when a property page is first opened.
But the Shown Event Hanlder doesnt appear in the property pages.
//
// ElementLabelControlPropert
//
this.BackColor = System.Drawing.Color.Trans
this.Controls.Add(this._oE
this.Controls.Add(this._oE
this.Controls.Add(this.lab
this.Controls.Add(this.lab
this.Controls.Add(this._oE
this.Controls.Add(this._cI
this.Controls.Add(this.lab
this.Controls.Add(this.lab
this.Controls.Add(this.lab
this.Location = new System.Drawing.Point(13, 13);
this.Name = "ElementLabelControlProper
this.Size = new System.Drawing.Size(380, 291);
//this.shown
//only this.show comes up with intellisense
this.Enter += new System.EventHandler(this.E
this.VisibleChanged += new System.EventHandler(this.E
this.Load += new System.EventHandler(this.E
this.ResumeLayout(false);
this.PerformLayout();
Thanks
Paul
More info here.
https://www.experts-exchange.com/questions/21829411/this-ParentForm-Shown.html
ASKER
angel
when I do
this.VisibleChanged += new System.EventHandler(this.E lementLabe lControlPr opertyPage _VisibleCh anged);
and
private void ElementLabelControlPropert yPage_Visi bleChanged (object sender, EventArgs e)
{
MessageBox.Show("test");
}
It shows the messagebox twice!
Then the Property Page.
Thsi might help too (Im trying to do this within ElementLabelControlPropert yPage)
public class ElementLabelControlPropert yPage : PropertyPage
and
public class PropertyPage : UserControl
(UserControl is System.Windows.Forms.UserC ontrol)
Thanks
when I do
this.VisibleChanged += new System.EventHandler(this.E
and
private void ElementLabelControlPropert
{
MessageBox.Show("test");
}
It shows the messagebox twice!
Then the Property Page.
Thsi might help too (Im trying to do this within ElementLabelControlPropert
public class ElementLabelControlPropert
and
public class PropertyPage : UserControl
(UserControl is System.Windows.Forms.UserC
Thanks
ASKER
If anyone is listening ;)
I added the Shown Event Handler to my Property Page
-------
public class PropertyPage : UserControl
{
...
#region EVENT HANDLERS
//
// Summary:
// Occurs whenever the form is first displayed.
public event EventHandler Shown;
#endregion
#region METHODS
public virtual void OnApply() { }
...
-------
Now within
public class ElementLabelControlPropert yPage : PropertyPage
I can do
this.Shown += new System.EventHandler(this.E lementLabe lControlPr opertyPage _Shown);
and
private void ElementLabelControlPropert yPage_Show n(object sender, EventArgs e)
{
MessageBox.Show("Shown");
}
But it doesn't show the messagebox at all.
I added the Shown Event Handler to my Property Page
-------
public class PropertyPage : UserControl
{
...
#region EVENT HANDLERS
//
// Summary:
// Occurs whenever the form is first displayed.
public event EventHandler Shown;
#endregion
#region METHODS
public virtual void OnApply() { }
...
-------
Now within
public class ElementLabelControlPropert
I can do
this.Shown += new System.EventHandler(this.E
and
private void ElementLabelControlPropert
{
MessageBox.Show("Shown");
}
But it doesn't show the messagebox at all.
Paul,
As this is your own custom event, where is the code that fires it? I take it somewhere you are calling something like:
if (this.Shown != null)
this.Shown(this, new System.EventArgs());
Andy
As this is your own custom event, where is the code that fires it? I take it somewhere you are calling something like:
if (this.Shown != null)
this.Shown(this, new System.EventArgs());
Andy
Aren't you dropping your ElementLabelControlPropert yPage UserControl onto a Form? If you are the Form will have the Shown event which is also when the UserControl is shown. I'm not absolutely sure what you are trying to do. Do you want your UserControl to realize when the main form it's on is shown?
Paul,
I think you may have been through a fair number of thought processes with this, so I'll just walk through what I would do to add a Shown event to the PropertyPage control and consume it from a form:
1) Add the Shown event to the PropertyPage control, as you have done
2) Create a private OnShown method to raise that event inside the PropertyPage control:
private void OnShown()
{
if (this.Shown != null)
this.Shown(this, new System.EventArgs());
}
3) Call OnShown from inside the PropertyPage control, as you were trying to do initially with the Shown event. However, I wouldn't do this inside InitializeComponent. Instead I would do it inside the Load event handler (double click on the usercontrol IDE surface to create an eventhandler for Load):
private void ElementLabelControlPropert yPage_Load (object sender, EventArgs e)
{
...
this.OnShown();
...
}
4) Consume the event from inside the form. You can use the property pane on the IDE to do this once you have dropped the control onto the form surface, or just add the appropriate "this.myElementLabelContro lPropertyP age.Shown += blah" into your code.
As pauljk1619 says, I'm not exactly sure what you are trying to do with this, but that would be how I would do it. If you can tell us more about what you want to do we can probably comment further.
Andy
I think you may have been through a fair number of thought processes with this, so I'll just walk through what I would do to add a Shown event to the PropertyPage control and consume it from a form:
1) Add the Shown event to the PropertyPage control, as you have done
2) Create a private OnShown method to raise that event inside the PropertyPage control:
private void OnShown()
{
if (this.Shown != null)
this.Shown(this, new System.EventArgs());
}
3) Call OnShown from inside the PropertyPage control, as you were trying to do initially with the Shown event. However, I wouldn't do this inside InitializeComponent. Instead I would do it inside the Load event handler (double click on the usercontrol IDE surface to create an eventhandler for Load):
private void ElementLabelControlPropert
{
...
this.OnShown();
...
}
4) Consume the event from inside the form. You can use the property pane on the IDE to do this once you have dropped the control onto the form surface, or just add the appropriate "this.myElementLabelContro
As pauljk1619 says, I'm not exactly sure what you are trying to do with this, but that would be how I would do it. If you can tell us more about what you want to do we can probably comment further.
Andy
//Put this above your class declaration...
public delegate void PropertyGridShownEventHand ler(System .Object sender, PropertyPage.PropertyGridS hownEventA rgs e);
//In you PropertyPageClass...
public event PropertyGridShownEventHand ler PropertyGridShown;
public class PropertyGridShownEventArgs : System.EventArgs
{
// Any properties you want to show up in the event args.
public string ShownOn;
}
protected virtual void OnShown()
{
if(PropertyGridShown != null)
{
PropertyGridShownEventArgs e = PropertyGridShownEventArgs ();
e.ShownOn = System.DateTime.Now;
PropertyGridShown(this,e);
}
}
//Then you call OnShown in your control where ever you want the event raised.
public delegate void PropertyGridShownEventHand
//In you PropertyPageClass...
public event PropertyGridShownEventHand
public class PropertyGridShownEventArgs
{
// Any properties you want to show up in the event args.
public string ShownOn;
}
protected virtual void OnShown()
{
if(PropertyGridShown != null)
{
PropertyGridShownEventArgs
e.ShownOn = System.DateTime.Now;
PropertyGridShown(this,e);
}
}
//Then you call OnShown in your control where ever you want the event raised.
ASKER
Thanks guys. Some good points and Ill work through them now.
I was wondering what made each of the Event Handlers unique.
I mean apart from the name not much seems to differentiate them
If I do
private void InitializeComponent()
etc etc
this.Enter += new System.EventHandler(this.E lementLabe lControlPr opertyPage _Enter);
this.VisibleChanged += new System.EventHandler(this.E lementLabe lControlPr opertyPage _VisibleCh anged);
this.Load += new System.EventHandler(this.E lementLabe lControlPr opertyPage _Load);
this.Shown += new EventHandler(this.ElementL abelContro lPropertyP age_Shown) ;
and then
private void ElementLabelControlPropert yPage_Ente r(object sender, EventArgs e)
{
MessageBox.Show("Enter");
}
private void ElementLabelControlPropert yPage_Visi bleChanged (object sender, EventArgs e)
{
MessageBox.Show("VisibleCh anged");
}
etc etc
Where is the actual difference?
Thanks
Paul
I was wondering what made each of the Event Handlers unique.
I mean apart from the name not much seems to differentiate them
If I do
private void InitializeComponent()
etc etc
this.Enter += new System.EventHandler(this.E
this.VisibleChanged += new System.EventHandler(this.E
this.Load += new System.EventHandler(this.E
this.Shown += new EventHandler(this.ElementL
and then
private void ElementLabelControlPropert
{
MessageBox.Show("Enter");
}
private void ElementLabelControlPropert
{
MessageBox.Show("VisibleCh
}
etc etc
Where is the actual difference?
Thanks
Paul
ASKER
AGBrown
In PropertyPage I added
public event EventHandler Shown;
and
private void OnShown()
{
if (this.Shown != null)
this.Shown(this, new EventArgs());
}
Then in ElementLabelControlPropert yPage I did
this.Shown += new System.EventHandler(this.E lementLabe lControlPr opertyPage _Shown);
private void ElementLabelControlPropert yPage_Show n(object sender, EventArgs e)
{
MessageBox.Show("Shown");
}
But it never loads up the messagebox?
Any ideas?
I'm working through the other suggestions
Thanks
Paul
In PropertyPage I added
public event EventHandler Shown;
and
private void OnShown()
{
if (this.Shown != null)
this.Shown(this, new EventArgs());
}
Then in ElementLabelControlPropert
this.Shown += new System.EventHandler(this.E
private void ElementLabelControlPropert
{
MessageBox.Show("Shown");
}
But it never loads up the messagebox?
Any ideas?
I'm working through the other suggestions
Thanks
Paul
ASKER
Ok sorry for numerous post but ...
Now it goes into
private void ElementLabelControlPropert yPage_Load (object sender, EventArgs e)
{
MessageBox.Show("Load");
this.OnShown();
}
and into
protected void OnShown()
{
if (this.Shown != null)
this.Shown(this, new EventArgs());
}
where this.Shown is null.
Is that correct?
It still doesn't show the messagebox after the page is drawn.
Thanks
Paul
Now it goes into
private void ElementLabelControlPropert
{
MessageBox.Show("Load");
this.OnShown();
}
and into
protected void OnShown()
{
if (this.Shown != null)
this.Shown(this, new EventArgs());
}
where this.Shown is null.
Is that correct?
It still doesn't show the messagebox after the page is drawn.
Thanks
Paul
ASKER
AGBrown
I didnt understand this part
4) Consume the event from inside the form. You can use the property pane on the IDE to do this once you have dropped the control onto the form surface, or just add the appropriate "this.myElementLabelContro lPropertyP age.Shown += blah" into your code.
I didnt understand this part
4) Consume the event from inside the form. You can use the property pane on the IDE to do this once you have dropped the control onto the form surface, or just add the appropriate "this.myElementLabelContro
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi AGBrown,
I really want to create an eventhandler just for the
ElementLabelControlPropert yPage
The odd thing is is that if I put an Onload EventHandler into the page ElementLabelControlPropert yPage it shows before the page loads. I don't think thats correct.
The problem is that ElementLabelControlPropert yPage inherits from PropertyPage and not Form.
When I inherit from Form it allows me to add a Shown EventHandler.
So then I added a shown to the PropertyPage and tried to use that but to no avail.
Thanks
Paul
I really want to create an eventhandler just for the
ElementLabelControlPropert
The odd thing is is that if I put an Onload EventHandler into the page ElementLabelControlPropert
The problem is that ElementLabelControlPropert
When I inherit from Form it allows me to add a Shown EventHandler.
So then I added a shown to the PropertyPage and tried to use that but to no avail.
Thanks
Paul
this.VisibleChanged += new System.EventHandler(this.E
and once you got into that event, you could remove the event handler...