Answered Combine multiple lines into a single line in a textbox

Govind Sankar

Active member
Joined
May 15, 2020
Messages
42
Programming Experience
Beginner
Hi,

I have a wpf application that has a textbox to which value is inserted using a scanner. At one time when I scan a single data, multiple lines comes into textbox which can be scrolled down to see. But I dont want them as multiple lines. I want to combine all lines into a single line and see in the textbox without scrolling. How can I do that. Thank You.
 
In C++ and Java there is the concept of inheritance. That's all you need to do: inherit from the TextBox control and add your custom stuff.
I do know inheritance and I understood that from your pseudo code that the custom textbox is inheriting actual textbox control. But I dont know stuff like how does it work. Because in c++ and java when u inherit from a class, u still need to call the new class with a object of its own. But here I am confused. What happens when I run the program. I run the program and the mainwindow with the textbox opens up and when I press the trigger on my scanner gun and the qr code is read then which textbox will be triggered. The one in the main UI or the custom control class. So those things I dont know and I am unable to find any good online tutorial on that.
 
In C++ and Java there is the concept of inheritance. That's all you need to do: inherit from the TextBox control and add your custom stuff.
Ok let me get this right. I must have understood custom controls completely. Is this how it it works. I create a different user control with a textbox and place that new textbox with the added functionalities in place of the existing control. Is this how it works.
 
Yes. That is the clean way to do it. Subclass the text box and use the subclass instead.

The alternative way is to not subclass, but attach event handlers to the text change event to do the same thing: fire off a timer. Reset the timer each time there is a change. If after some period of time there are no more changes, then the timer tick event will fire. In the timer tick event handler, do the processing to combine lines, and do your database processing.
 
Yes. That is the clean way to do it. Subclass the text box and use the subclass instead.

The alternative way is to not subclass, but attach event handlers to the text change event to do the same thing: fire off a timer. Reset the timer each time there is a change. If after some period of time there are no more changes, then the timer tick event will fire. In the timer tick event handler, do the processing to combine lines, and do your database processing.
Ok thanks, I just started learning about custom controls and thats when I got the idea and posted the above. Ok I still have a lot to learn before I am good in creating a custom textbox.
 
Back
Top Bottom