کار نکردن textchange در تکست باکس اختصاصی
سلام
من یه کلاس درست کردم که تکست باکسی دارم که فقط عدد میگیره و عدد را سه سه رقم رقم جدا میکنه
کلاس من به صورت زیر است:
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;
namespace WindowsFormsApplication1
{
public class Digit_Textbox : TextBox
{
string string_back4 = "";
protected override void OnTextChanged(EventArgs e)
{
int last_cur_textBox2 = this.SelectionStart;
int last_len = this.Text.Length;
if (this.Text.Length > 0)
{
try
{
if (this.Text.Equals("0"))
this.Text = "0";
else
{
this.Text = Convert.ToInt64(this.Text.Replace(",", "").ToString()).ToString("#,#");
Int64 a = Convert.ToInt64(this.Text.Replace(",", ""));
string_back4 = this.Text;
}
}
catch
{
this.Text = string_back4;
InputLanguage.CurrentInputLanguage = InputLanguage.FromCulture(System.Globalization.Cul tureInfo.CreateSpecificCulture("EN"));
}
}
try
{ this.SelectionStart = this.Text.Length - last_len + last_cur_textBox2; }
catch { this.SelectionStart = 0; }
}
protected override void OnKeyDown(KeyEventArgs e)
{
int ss = e.KeyValue;
bool blnf = true;
if ((ss == 3) || (ss == 8) || (ss == 22) || (ss == 35) || (ss == 36) || (ss == 37) || (ss == 39) || (ss == 46) || (ss == 190) || ((ss >= 96) && (ss <= 105)) || ((ss >= 48) && (ss <= 57))) blnf = false;
e.SuppressKeyPress = blnf;
try
{
if (e.KeyCode == Keys.Delete)
if ((this.SelectionLength == 0) && (this.Text[this.SelectionStart] == ','))
this.SelectionStart++;
if (e.KeyCode == Keys.Back)
if ((this.SelectionLength == 0) && (this.Text[this.SelectionStart - 1] == ','))
this.SelectionStart--;
}
catch { }
}
protected override void OnEnter(EventArgs e)
{
InputLanguage.CurrentInputLanguage = InputLanguage.FromCulture(System.Globalization.Cul tureInfo.CreateSpecificCulture("EN"));
}
protected override void OnLeave(EventArgs e)
{
if (this.Text == "")
this.Text = "0";
}
}
}
حالا مشکل اینجاست که وقتی از این کلاس توی فرم استفاده میکنم دیگه نمیتونم از رویداد TextChanged استفاده کنم
آیا راهی وجود داره که بشه از این رویداد دوباره استفاده کرد
ممنون
نقل قول: کار نکردن textchange در تکست باکس اختصاصی
هر event رو که تعریف می کنی یه دونه( base.eventname(e آخرش اضافه کن مانند این مورد:
protected override void OnTextChanged(EventArgs e)
{
int last_cur_textBox2 = this.SelectionStart;
int last_len = this.Text.Length;
if (this.Text.Length > 0)
{
try
{
if (this.Text.Equals("0"))
this.Text = "0";
else
{
this.Text = Convert.ToInt64(this.Text.Replace(",", "").ToString()).ToString("#,#");
Int64 a = Convert.ToInt64(this.Text.Replace(",", ""));
string_back4 = this.Text;
}
}
catch
{
this.Text = string_back4;
InputLanguage.CurrentInputLanguage = InputLanguage.FromCulture(System.Globalization.CultureInfo.CreateSpecificCulture("EN"));
}
}
try
{ this.SelectionStart = this.Text.Length - last_len + last_cur_textBox2; }
catch { this.SelectionStart = 0; }
base.OnTextChanged(e);
}
نقل قول: کار نکردن textchange در تکست باکس اختصاصی
تشکر میکنم
واقعا عالی بود
ممنون میشم جواب بدید که آیا از قبل میدونستید یا اینکه خودتون هم سرچ کردید؟؟؟
و اگه سرچ کردید، لطفا بگید چه چیزی رو سرچ کردید؟؟؟
باز هم ممنون
نقل قول: کار نکردن textchange در تکست باکس اختصاصی
قبلا توی یک مثال دیده بودم