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.EventArgs e)
{
this.SelectAll();
}
private void ClassNum_KeyPress(object sender,
System.Windows.Forms.KeyPressEventArgs e)
{
if (!Char.IsDigit(e.KeyChar))
{
if (!Char.IsControl(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.txtDealerNum = new LicenseDealerSales.ClassNum();
this.grpSearchDealerNum.Controls.Add(this.txtDeale rNum);
//
// txtDealerNum
//
this.txtDealerNum.Font = new System.Drawing.Font("Arial", 9F,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point,
((System.Byte)(0)));
this.txtDealerNum.Location = new System.Drawing.Point(112, 24);
this.txtDealerNum.MaxLength = 6;
this.txtDealerNum.Name = "txtDealerNum";
this.txtDealerNum.Size = new System.Drawing.Size(88, 21);
this.txtDealerNum.TabIndex = 0;
this.txtDealerNum.Text = "";
this.txtDealerNum.Leave += new
System.EventHandler(this.txtDealerNum_Leave);
this.txtDealerNum.TextChanged += new
System.EventHandler(this.txtDealerNum_TextChanged) ;
"Nicholas Paldino [.NET/C# MVP]" wrote:
Mike,
When you say:
ClassNum.SelectAll();
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.com
"Mike L" <Ca***@nospam.nospam> wrote in message
news:9C**********************************@microsof t.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.EventArgs
e)
{
ClassNum.SelectAll();
}
}
Error: An object reference is required for the nonstatic field, method, or
property 'System.Windows.Forms.TextBoxBase.SelectAll()'