>>>>>For testing, I activate this code by pressing a command button.
>>>>>Is there any way that I can force this code to be activated automatically after the multiline textbox is filled?
>>>>
>>>>What type of TextBox - Winforms, Web, WPF ?>>>>How does it get populated ?
>>>
>>>It's a Winform textbox.
>>>It is populated when someone puts the cursor in the upper lefthand corner and runs a currency counting machine attached to a serial port on the PC.
>>>The serial stream is read by proprietary software that converts it into simulated keystrokes.
>>>When reading the stream the textbox behaves exactly as it would if a human keyed in a quantity and hit Enter, and repeated that keystroke combination 6 more times.
>>>The appearance of the screen is identical and so is the value to the text.property of the textbox.
>>>If there is no quantity for a denomination, it sends a zero followed by Enter, so there are always 7 quantities and 7 Enters.
>>
>>Maybe watching OnTextChanged would work ? e.g:
protected override void OnTextChanged(EventArgs e)
>> {
>> if (this.Text.Count(t => t == '\n' ) == 7)
>> {
>> DoConversion(this.Text);
>> this.Text = String.Empty;
>> }
>>
>> base.OnTextChanged(e);
>> }
>>You could create a custom control sub-classed from Textbox if you are using it in more than one place.....
>
>I was thinking of something along that line.
>Your solution is more elegant than what I had in mind, though.
>I'll try it
When I consider Viv's embolded question a few lines above, I'd encapsulate that functionality in a small Dotnet class, which you could then use to embellish all of the textboxes Viv mentioned if the need arises. Put the magic numbers like the 7 into class properties and you are set to branch out into other currency counters ;-))
The Custom Control would have the same ease of handling and needs only aggregation of the "counter class" and the wiring into the specific textbox class. More flexibility...