-
April 5th, 2010, 05:49 AM
#1
How to add "OnFocus" event in Visual Studio 2005
Quick question about Visual Studio 2005 IDE.
When I double-click a control in the design window, the IDE automatically creates a method for the default control event. But what about tons of the other events, how can I catch them?
For instance, I want to create a method for the event "OnFocus". How can I do that? I remember a pull-down menu in which all of the events where listed, but not sure of it...
Thanks in advance.
-
April 5th, 2010, 06:17 AM
#2
Re: How to add "OnFocus" event in Visual Studio 2005
instead of double-clicking just select the control and right click and select 'properties' - there you might the event lists in the datagrid control property
-
April 5th, 2010, 06:26 AM
#3
Re: How to add "OnFocus" event in Visual Studio 2005
Originally Posted by vcdebugger
instead of double-clicking just select the control and right click and select 'properties' - there you might the event lists in the datagrid control property
Rather than, I found this solution and it works just fine:
http://msdn.microsoft.com/en-us/libr...8VS.80%29.aspx
Title in page: To create an event handler in the Properties window
Using this article I created the following method:
Code:
private void txtIpB_OnFocus(object sender, EventArgs e)
{
txtIpB.SelectionStart = 0;
txtIpB.SelectionLength = txtIpB.Text.Length;
}
However, this doesn't work.
And neither this one works:
Code:
private void txtIpB_OnFocus(object sender, EventArgs e)
{
txtIpB.SelectAll();
}
My purpose is to select all the text in a TextBox when the control catches focus.
How can I do that?
-
April 5th, 2010, 06:38 AM
#4
Re: How to add "OnFocus" event in Visual Studio 2005
hoe do you know whether it is working or not ? just put a break point that function and see if the control comes there... and assign the text in that control to some string and see if the text present in that control gets updated to that string...
Code:
string text = txtIpB.Text;
-
April 5th, 2010, 06:53 AM
#5
Re: How to add "OnFocus" event in Visual Studio 2005
Originally Posted by vcdebugger
hoe do you know whether it is working or not ? just put a break point that function and see if the control comes there... and assign the text in that control to some string and see if the text present in that control gets updated to that string...
Code:
string text = txtIpB.Text;
Thank you for your reply.
I put a break point inside txtIpB_OnFocus() to see that this method is indeed called when I focus on the control. And saw that the "txtIpB.Text" contains the string control has as it was expected.
So, how can I select the text in this edit control?
-
April 5th, 2010, 06:59 AM
#6
Re: How to add "OnFocus" event in Visual Studio 2005
there is no need of selecting , the property txtIpB.Text itself contains the text you want to select...
-
April 5th, 2010, 07:03 AM
#7
Re: How to add "OnFocus" event in Visual Studio 2005
Originally Posted by vcdebugger
there is no need of selecting , the property txtIpB.Text itself contains the text you want to select...
I want to make it selected, so that when user clicks on it he can immediately start typing new data without bothering to delete the old one, like in the web forms implemented by JavaScript.
Thanks in advance.
-
April 5th, 2010, 07:08 AM
#8
Re: How to add "OnFocus" event in Visual Studio 2005
by default when the focus comes to that control automatically all the text inside that should get selected with what I have observed some years back in vc6.. not sure of C#..
anyways there should be some property for edit box which makes it EDITABLE so that all the text get selected and user can start typing so that old text gets erased automatically... right click on text box and check the properties referring to option - *EDITABLE ** NON-EDITABLE
-
April 5th, 2010, 07:22 AM
#9
Re: How to add "OnFocus" event in Visual Studio 2005
The entire text in the control is selected only if you focus the control by means of pressing the TAB key. The text is not selected if the control catches focus by mouse click.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|