Aid*_*yan 54 .net c# numericupdown winforms
当用户NumericUpDown选中我的时候,我希望选择所有文本.这可能吗?
Jon*_*n B 117
private void NumericUpDown1_Enter(object sender, EventArgs e)
{
    NumericUpDown1.Select(0, NumericUpDown1.Text.Length);
}
(注意,Text属性在Intellisense中隐藏,但它就在那里)
我想为将来搜索Tab和Click的人添加这个.
Jon B的回答非常适合Tab,但我需要修改以包含click
如果您选中或单击,下面将选择文本.如果单击并输入框,则会选择文本.如果您已经专注于该框,则单击将执行通常所做的操作.
    bool selectByMouse = false;
    private void quickBoxs_Enter(object sender, EventArgs e)
    {
        NumericUpDown curBox = sender as NumericUpDown;
        curBox.Select();
        curBox.Select(0, curBox.Text.Length);
        if (MouseButtons == MouseButtons.Left)
        {
            selectByMouse = true;
        }
    }
    private void quickBoxs_MouseDown(object sender, MouseEventArgs e)
    {
        NumericUpDown curBox = sender as NumericUpDown;
        if (selectByMouse)
        {
            curBox.Select(0, curBox.Text.Length);
            selectByMouse = false;
        }
    }
您可以将它用于多个numericUpDown控件.只需要设置Enter和MouseDown事件
| 归档时间: | 
 | 
| 查看次数: | 26919 次 | 
| 最近记录: |