|
I am looking for a way to select the contents of the control when tabbed into/focus....it does not have SelectionLength/SelectionStart properties.... |
| MigrationUser 1 Thursday, February 05, 2004 11:14 AM |
what kind of control is it, and what program are u using? |
| MigrationUser 1 Friday, February 06, 2004 12:49 PM |
It's a windows Application and the control I was talking about was NumericUpDown control, available in .NET.
|
| MigrationUser 1 Saturday, February 07, 2004 4:26 PM |
You can use the ValueChanged event to grab the current value
private void numericUpDown1_ValueChanged(object sender, System.EventArgs e) { MessageBox.Show( numericUpDown1.Value.ToString() ); }
|
| MigrationUser 1 Sunday, February 08, 2004 12:06 PM |
I think I may not ahve been clear. What I am looking to do is, highlight the contents of the controls once the user either tabs into the field or enters it by clicking on it. Just the way we can highlight the contents of a textbox, by setting it's SelectionStart and Selection lenght properties, I was looking at a way to do similar thing in NUmeric UpDowm control. |
| MigrationUser 1 Sunday, February 08, 2004 4:18 PM |
Change the ForeColor and BackColor properties on the Enter event then set them back to normal on the leave event
private void numericUpDown1_Enter(object sender, System.EventArgs e) { numericUpDown1.ForeColor = Color.Yellow; numericUpDown1.BackColor = Color.Blue;
}
private void numericUpDown1_Leave(object sender, System.EventArgs e) { numericUpDown1.ForeColor = Color.Black; numericUpDown1.ForeColor = Color.White;
}
|
| MigrationUser 1 Sunday, February 08, 2004 10:31 PM |
Hi, This just mimics the behaviour I want, but does not simulate it. When I use the code you suggested in the Enter and Leave events, the controls change color as desired, but that's about it. What I want it to do is when I start typing in it should override the existing data, and if I go to the end then it should start appending the data. I can do it with some coding...I was seeing if there are some properties I could set that would do this for me.
Thanks for your help. |
| MigrationUser 1 Tuesday, February 10, 2004 9:59 AM |
I trying to do the same thing. I tried Enter and GotFocus event so that when user click on the numeric control, I try numericupdown.select(1,3) for example but it did not work.
Do you have a solution already? I understand from what you want is like doubleclicking, the value will be highlighted, ready for overwrite. This is the same as what I need.
Vincent |
| VincGoh Wednesday, March 01, 2006 2:39 AM |
For all who encounter this problem after I did , may this work for you also:
// Wire up your event for when the control receives focus in your form initialization section
this.numericUpDownControl.Enter += new System.EventHandler(this.numericUpDownControl_Enter);
// In your event handler, call your reusable subroutine to select the text
private void numericUpDownControl_Enter(object sender, System.EventArgs e) { SelectAllText(numericUpDownControl); }
// In your reusable subroutine, set a reference to the UpDownBase interface - this is a superclass of the NumericUpDown control. It is on this interface that you will execute the Select method to highlight your text. Enhance at your leisure.
private void SelectAllText(NumericUpDown nudControl) { UpDownBase udb = (UpDownBase)nudControl; udb.Select(0, udb.Text.Length); }
RS |
| a173234 Thursday, May 04, 2006 11:03 PM |
That's a working solution. You can simplify it slightly by not casting the NumericUpDown to UpDownBase. There's no need to cast it to the base class to call base class members.
public Form1()
{
InitializeComponent();
numericUpDown1.Enter += new EventHandler(numericUpDown1_Enter);
}
void numericUpDown1_Enter(object sender, EventArgs e)
{
numericUpDown1.Select(0, numericUpDown1.Text.Length);
} |
| Yifung Lin - MSFT Friday, May 05, 2006 5:15 AM |
Holy cow, how did I miss that!
Thanks for that catch, Yifung - I'm off to find some NoDoz...
RS |
| a173234 Friday, May 05, 2006 2:45 PM |
ı have the same problem but ı am using vb.net ...is there any solution for my problem...ı am new in vb.net...if there is a solution for me pls answer my question clear:P sorry for my bad english:(((
thanks |
| ferhat Monday, October 30, 2006 3:50 PM |
Just convert it to VB Private Sub nuds_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles nud1.Enter, nud2.Enter, nud3.Enter, 4.Enter Dim udb As NumericUpDown = CType(sender, NumericUpDown) udb.Select(0, udb.Text.Length) End Sub
|
| MIkeTims Friday, May 01, 2009 3:33 PM |