Thanks that fixed the errors, but the code in the class does not run.
BTW this is for a win form.
Here is my class.
class ClassNum : System.Windows. Forms.TextBox
{
private void ClassNum_Enter( object sender, System.EventArg s e)
{
this.SelectAll( );
}
private void ClassNum_KeyPre ss(object sender,
System.Windows. Forms.KeyPressE ventArgs e)
{
if (!Char.IsDigit( e.KeyChar))
{
if (!Char.IsContro l(e.KeyChar))
e.Handled = true;
}
}
}
Here is the call to the class from the form class. I'm only showing code
that is relevate to the problem.
public class frmDataEntry : System.Windows. Forms.Form
{
internal ClassNum txtDealerNum;
this.txtDealerN um = new LicenseDealerSa les.ClassNum();
this.grpSearchD ealerNum.Contro ls.Add(this.txt DealerNum);
//
// txtDealerNum
//
this.txtDealerN um.Font = new System.Drawing. Font("Arial", 9F,
System.Drawing. FontStyle.Bold, System.Drawing. GraphicsUnit.Po int,
((System.Byte)( 0)));
this.txtDealerN um.Location = new System.Drawing. Point(112, 24);
this.txtDealerN um.MaxLength = 6;
this.txtDealerN um.Name = "txtDealerN um";
this.txtDealerN um.Size = new System.Drawing. Size(88, 21);
this.txtDealerN um.TabIndex = 0;
this.txtDealerN um.Text = "";
this.txtDealerN um.Leave += new
System.EventHan dler(this.txtDe alerNum_Leave);
this.txtDealerN um.TextChanged += new
System.EventHan dler(this.txtDe alerNum_TextCha nged);
"Nicholas Paldino [.NET/C# MVP]" wrote:
Mike,
When you say:
ClassNum.Select All();
It is assuming you want to call the static method, not the instance
method. Instead, use "this":
this.SelectAll( );
This will call SelectAll on the instance.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"Mike L" <Ca***@nospam.n ospam> wrote in message
news:9C******** *************** ***********@mic rosoft.com...
This is my first attempt at inheriting a class. I want to inherit textbox
class to my derived class ClassNum.
ClassNum will override the TextChanged, Leave, KeyPress and Enter
methods.
So, far I was able to inherit the textbox class to ClassNum, but I get
errors when I try to override the methods.
class ClassNum : System.Windows. Forms.TextBox
{
private void ClassNum_Enter( object sender, System.EventArg s
e)
{
ClassNum.Select All();
}
}
Error: An object reference is required for the nonstatic field, method, or
property 'System.Windows .Forms.TextBoxB ase.SelectAll() '