我要在C# Windows Forms 中自定义TextBox控件,按要求:(1)这个TextBox控件的最大长度为32767(int型),要求当输入的长度大于32767时TextBox就不能再输入了(不过此时可以删除);(2)另外,假设TextBox的长度为6,在粘贴数据之前TextBox中已经有1234四位数字,现在当光标位于2、3之间时我要粘贴567这个数字进TextBox(因为TextBox假设的最大长度为6),所以在粘贴数据时只能把56粘进去,数据最终变成“125634”(粘贴时光标可位于文本框任何位置)。请问高手如何实现这两个功能?
你可以找第三方的控件,比如DevExpress的TextEdit控件,有EditValueChanging事件,可以拿到变化前和变化后的值,这样处理起来方便多了。
添加新事件: private void DataGrid_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
if (e.RowIndex >= 0) //点标题不触发
{
try
{
点击(this, new EventArgs());
}
catch { }
}
} private void DataGrid_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
{
if (e.RowIndex >= 0) //点标题不触发
{
try
{
双击(this, new EventArgs());
}
catch { }
}
}sorry,没做过文本框的.这个是GridView的,供参考下.
楼主为什么不给悬赏分,郁闷...