I have found that there is no base class that directly underneath:
Textbox, Label and Button
These are their definitions:
public class TextBox : TextBoxBase
public abstract class TextBoxBase : Control
public class Button : ButtonBase, IButtonControl
public abstract class ButtonBase : Control
public class Label : Control
in .net #region Assembly System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 // C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.5\System.Windows.Forms.dll
I needed to override the refresh button and also add some custom properties and some custom event handlers for every control. Therefore I decided to create a custom Control. But that was before I realized that not every class is directly extended from Control. I know I can use an Interface to at least enforce that the methods/properties are in the contract but I want to be able to write the code for these 'custom' methods once not every time I extend the interface.
Is there another way?
This is the custom Control class and the desired functionality I want inherited. The fantasy is that I would do something like this:
public class TextBox : Sgctrl (of course fantasy as it is not possible my way as shown below)
public class SGctrl : Control
{
public String MySystem_SourceField { get; set; }
protected Core ctrlCore { get; set; }
protected MyForm.Forms.Location.FormLoc callingForm;
// the delegate
public delegate void Published_DELEGATE_TYPE_MySysConnectedControlRefresh(object aSGctrl, SGRefreshHandler sgr);
// This event instance of the delegate provides a hook for .NET as it makes it show up in the properties->events
// and by doubleclicking it allows other specific (textbox/label) visibility;enabled properties to be set
//
public event Published_DELEGATE_TYPE_MySysConnectedControlRefresh MySysConnectedControlRefresh_handler;
//protected virtual void OnMySysSGcontrolRefresh(SGRefreshHandler e)
protected virtual void OnMySysSGcontrolRefresh(SGRefreshHandler e)
{
if (MySysConnectedControlRefresh_handler != null)
//signature SGctrl , eventhandler object
{ MySysConnectedControlRefresh_handler(this, e); }
}
//public SGctrl(bool refreshable,Form SGcallingForm)
public SGctrl()
{
}
// will do it in the refresh method
public override void Refresh()
{
base.Refresh();
// if calling from and core reference are not yet initialized do so
if (this.callingForm == null)
this.callingForm = (MyForm.Forms.Location.FormLoc)this.TopLevelControl;
if (this.ctrlCore == null)
this.ctrlCore = this.callingForm.getCoreRef();
// pass to suscriber
//core.getField("cllabloc1");
//sgctrl.Text = sgctrl.core.getField(sgctrl.MySystem_SourceField) // get MySys data
if (this.GetType()==typeof(TextBox)) // if need to know type of control
{ }
this.Text=this.ctrlCore.getField(this.MySystem_SourceField);
SGRefreshHandler SGRefrshrobj = new SGRefreshHandler(this);
OnMySysSGcontrolRefresh(SGRefrshrobj);
}
}