I have an issue where the compiler doesn't appear be be seeing the interface class correctly. I have a base class, called Ctrl, and a number of derived classes, Ctrl_BUTTON
, Ctrl_CHECKBOX
, etc. Some but not all of them need to have a Font property, so that I can test easily at runtime as to whether the class supports a Font
property. Hence I have an interface class, ICtrl_Font
. However, I'm getting the designtime error:
'AppData.Ctrl_CHECKBOX' does not contain a definition for 'Font' and no extension method 'Font' accepting a first argument of type 'AppData.Ctrl_CHECKBOX' could be found (are you missing a using directive or an assembly reference?)
The code structure I have.
class ICtrl_Font
:
namespace AppData
{
public interface ICtrl_Font
{
Font Font { get; set; }
}
}
Ctrl_CHECKBOX
uses ICtrl_Font
thus (I've chopped out irrelevant code for clarity):
namespace AppData
{
public class Ctrl_CHECKBOX : Ctrl, ICtrl_Font
{
private Font _font = new Font("Microsoft Sans Serif", (float)8.25, FontStyle.Regular, GraphicsUnit.Point);
public override Ctrl Clone()
{
Ctrl_CHECKBOX oCopy;
try
{
oCopy = new Ctrl_CHECKBOX(base.Globals, base.Server, base.App, base.Frm);
if (!base.Copy(oCopy)) throw new Exception(string.Format("Could not clone Ctrl class for {0} copy.", base.CtrlTypeCode));
oCopy.DesignTimeValue = _designTimeValue;
oCopy.Enabled = (_enabled.GetType() == typeof(Expression)) ? ((Expression)_enabled).Clone() : _enabled;
oCopy.Font = new Font(_font.Name, _font.Size, _font.Style, GraphicsUnit.Point);
oCopy.Text = (_text.GetType() == typeof(Expression)) ? ((Expression)_text).Clone() : _text;
oCopy.Value = (_value.GetType() == typeof(Expression)) ? ((Expression)_value).Clone() : _value;
return (Ctrl)oCopy;
}
catch (Exception ex)
{
throw ex;
}
}
Font ICtrl_Font.Font
{
get { return _font; }
set
{
_font = value;
Console.WriteLine("CHECKBOX: Font.Name -> " + _font.Name);
base.OnPropertyValueChanged(this, new AppData.PropertyValueChangeEventArgs(this, "Font"));
}
}
}
}
I'm getting the error from within Ctrl_CHECKBOX
in the Clone
method at the line oCopy.Font = ...
but also elsewhere in the code where the Ctrl_CHECKBOX.Font
is referenced.
How do I resolve this? Thanks.