Click here to Skip to main content
15,890,717 members
Home / Discussions / C#
   

C#

 
GeneralRe: What is an Integer Pin
Roger Wright1-Sep-11 20:08
professionalRoger Wright1-Sep-11 20:08 
QuestionC#.net object reference error Pin
dcof31-Aug-11 11:32
dcof31-Aug-11 11:32 
AnswerRe: C#.net object reference error Pin
Eddy Vluggen31-Aug-11 11:59
professionalEddy Vluggen31-Aug-11 11:59 
QuestionTextbox onTextChanged method. Pin
vanikanc31-Aug-11 9:59
vanikanc31-Aug-11 9:59 
AnswerRe: Textbox onTextChanged method. Pin
#realJSOP31-Aug-11 10:08
mve#realJSOP31-Aug-11 10:08 
GeneralRe: Textbox onTextChanged method. Pin
vanikanc31-Aug-11 10:13
vanikanc31-Aug-11 10:13 
AnswerRe: Textbox onTextChanged method. Pin
Luc Pattyn31-Aug-11 12:51
sitebuilderLuc Pattyn31-Aug-11 12:51 
GeneralRe: Textbox onTextChanged method. Pin
BillWoodruff2-Sep-11 2:21
professionalBillWoodruff2-Sep-11 2:21 
The 'trouble' with the WinForms 'TextBox' 'TextChanged' Event is that it doesn't give you much information: its 'event argument' is just a dumb old 'EventArgs.

If you use the 'Leave event of the TextBox to judge the user is done, imho that's an 'ambiguous' choice that can lead to confusion, since all it means is the user shifted focus to some other control or object.

A TextBox with its 'MultiLine' property set to 'false, will ignore Enter/Return key-presses, and the focus will stay in the TextControl. The properties 'AcceptsTab, and 'AcceptsReturn only apply to MultiLine = 'true TextBoxes.

A Tab entry is going to move the focus to the next control in the tab-order; again, imho, an unsatisfactory way to handle the need to know the user has finished doing whatever they want to do with a TextBox.

The KeyPress, KeyDown, and KeyUp events give you access easily to which key is pressed.

So, what to do ? Since it is something of a convention that hitting the 'Enter key means you are 'done' with something, why not use that:
C#
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
    if (e.KeyCode == Keys.Enter || e.KeyCode == Keys.Return)
    {
        // do whatever ... validate, make buttons enabled or disabled ...
        // put up a 'confirm dialog, etc.
    }
}
Another idea I would consider, if dealing with users who were not 'socialized' to 'enter key = done' ... would be to make a UserControl that would be a combination of a CheckBox and a TextBox.

good luck, Bill
"Is it a fact - or have I dreamt it - that, by means of electricity, the world of matter has become a great nerve, vibrating thousands of miles in a breathless point of time? Rather, the round globe is a vast head, a brain, instinct with intelligence!" - Nathanial Hawthorne, House of the Seven Gables

QuestionObserver Design Patterns! Pin
borges0231-Aug-11 8:52
borges0231-Aug-11 8:52 
AnswerRe: Observer Design Patterns! Pin
Pete O'Hanlon31-Aug-11 9:22
mvePete O'Hanlon31-Aug-11 9:22 
QuestionWhat's the difference between Proxy Patterns and Observer Patterns? Pin
borges0231-Aug-11 7:44
borges0231-Aug-11 7:44 
AnswerRe: What's the difference between Proxy Patterns and Observer Patterns? Pin
Abhinav S31-Aug-11 8:00
Abhinav S31-Aug-11 8:00 
QuestionC#.net class library error Pin
dcof31-Aug-11 7:22
dcof31-Aug-11 7:22 
AnswerRe: C#.net class library error PinPopular
Wayne Gaylard31-Aug-11 7:34
professionalWayne Gaylard31-Aug-11 7:34 
QuestionCustom Control Regions Pin
cjb11030-Aug-11 23:58
cjb11030-Aug-11 23:58 
AnswerRe: Custom Control Regions Pin
BobJanova31-Aug-11 0:27
BobJanova31-Aug-11 0:27 
GeneralRe: Custom Control Regions Pin
cjb11031-Aug-11 0:40
cjb11031-Aug-11 0:40 
GeneralRe: Custom Control Regions Pin
BobJanova31-Aug-11 7:43
BobJanova31-Aug-11 7:43 
GeneralRe: Custom Control Regions Pin
cjb1102-Sep-11 2:27
cjb1102-Sep-11 2:27 
Questionhow to associate file type in window registry for c# program ? Pin
Kim061830-Aug-11 23:29
Kim061830-Aug-11 23:29 
AnswerRe: how to associate file type in window registry for c# program ? Pin
BobJanova31-Aug-11 0:20
BobJanova31-Aug-11 0:20 
AnswerRe: how to associate file type in window registry for c# program ? Pin
Tony Pazzard31-Aug-11 3:28
Tony Pazzard31-Aug-11 3:28 
AnswerRe: how to associate file type in window registry for c# program ? Pin
PIEBALDconsult31-Aug-11 3:29
mvePIEBALDconsult31-Aug-11 3:29 
QuestionProblem while reading data from excel in c# Pin
nainakarri30-Aug-11 20:33
nainakarri30-Aug-11 20:33 
AnswerRe: Problem while reading data from excel in c# Pin
Wayne Gaylard30-Aug-11 21:29
professionalWayne Gaylard30-Aug-11 21:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.