T
Tom
The included code block demonstrates programmatically clicking a
non-derived ToolStripButton in the OnShown() method.
When I derive a button from ToolStripButton and override the _private_
OnClick() method (also shown in the code block) ... the button works
as expected when it is manually clicked.
Please explain how I can programmatically click the derived button.
The fact that the derived button's OnClick() method is "private"
prevents me from directly calling it from within the OnShown() method.
My guess is this problem revolves around some sort of delegate/event
handler confusion I have yet to sort out. Hopefully soon another light
will start to glow.
Thank you in advance. This amazing group has never failed to sort out
the many learning hurdles this newb keeps straddling.
-- Tom
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
public class testForm : Form
{
[STAThread]
public static void Main()
{
Application.EnableVisualStyles();
Application.Run(new testForm());
}
testForm()
{
ToolStrip appToolStrip = new ToolStrip();
appToolStrip.Parent = this;
appToolStrip.Dock = DockStyle.Left;
ToolStripButton button_1 = new ToolStripButton();
button_1.Text = "Button #1";
appToolStrip.Items.Add(button_1);
button_1.Click += new EventHandler(button_1_Click);
DerivedButton derivedButton = new DerivedButton();
derivedButton.Text = "The Derived Button";
derivedButton.DisplayStyle = ToolStripItemDisplayStyle.Text;
appToolStrip.Items.Add(derivedButton);
}
protected override void OnShown(EventArgs e)
{
button_1_Click(this, EventArgs.Empty);
}
void button_1_Click(object sender, EventArgs e)
{
MessageBox.Show("Button #1 Has Been Clicked");
}
} // public class testForm : Form
// ####################################################
public class DerivedButton : ToolStripButton
{
protected override void OnClick(EventArgs e)
{
base.OnClick(e);
MessageBox.Show("The DerivedButton Has Been Clicked");
}
}
non-derived ToolStripButton in the OnShown() method.
When I derive a button from ToolStripButton and override the _private_
OnClick() method (also shown in the code block) ... the button works
as expected when it is manually clicked.
Please explain how I can programmatically click the derived button.
The fact that the derived button's OnClick() method is "private"
prevents me from directly calling it from within the OnShown() method.
My guess is this problem revolves around some sort of delegate/event
handler confusion I have yet to sort out. Hopefully soon another light
will start to glow.
Thank you in advance. This amazing group has never failed to sort out
the many learning hurdles this newb keeps straddling.
-- Tom
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
public class testForm : Form
{
[STAThread]
public static void Main()
{
Application.EnableVisualStyles();
Application.Run(new testForm());
}
testForm()
{
ToolStrip appToolStrip = new ToolStrip();
appToolStrip.Parent = this;
appToolStrip.Dock = DockStyle.Left;
ToolStripButton button_1 = new ToolStripButton();
button_1.Text = "Button #1";
appToolStrip.Items.Add(button_1);
button_1.Click += new EventHandler(button_1_Click);
DerivedButton derivedButton = new DerivedButton();
derivedButton.Text = "The Derived Button";
derivedButton.DisplayStyle = ToolStripItemDisplayStyle.Text;
appToolStrip.Items.Add(derivedButton);
}
protected override void OnShown(EventArgs e)
{
button_1_Click(this, EventArgs.Empty);
}
void button_1_Click(object sender, EventArgs e)
{
MessageBox.Show("Button #1 Has Been Clicked");
}
} // public class testForm : Form
// ####################################################
public class DerivedButton : ToolStripButton
{
protected override void OnClick(EventArgs e)
{
base.OnClick(e);
MessageBox.Show("The DerivedButton Has Been Clicked");
}
}