Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 14 years ago.
Improve this question
I have a Winform application built with C# and .Net 2.0. I have a textbox set with the MultiLine property.
The problem is when someone writes text with multiple lines (press few enters), presses the save button, and then closes and loads the form again, all the new lines disappear (the text is there at least).
For example, if the textbox had this in it:
Line1
Line3
It will look like this after I save and load:
Line1 Line3
Any idea why?
Update
The database is PostGres and when I use PGAdmin I can see all the line AND the "enters". So the persistence seem to have save all the line... the problem seem to be when I put back the string in the Textbox.
If I recall correctly, the textbox is really a string array.
I think you can do this:
textBox1.Lines = foo.Split(new String[] {"\n"},StringSplitOptions.RemoveEmptyEntries);
Edit again: If you want to keep the blank lines, the change to StringSplitOptions.None
In Windows forms all carriage returns are preserved in a multiline text box, so the problem likely lies in the way data is retrieved from your database. I've never used PostGres, but I'm guessing that the way you're retrieving the text from the db is replacing all whitespace with single spaces.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have an Application build in WPF. It have a Textbox that will always accept only 10 digits and is always ready for Scanning ID Barcode Contains 10 Digits or Entering Number with Keyboard.
Now some Customers are entering just 2 digits and leaving system as it is. Let us say he write 12 in TextBox and left it. When new Customer is coming he is Scanning his Id without noticing that there is something already written in the TextBox. So New Number is coming like this 1224444444 and two numbers are missing that is 34.
How can I clear Textbox before Scanning or Before Writing?
some example code of exactly how you are attempting this would be useful.
A WPF textbox can be cleared by either calling the .Clear method, or simply by setting the "Text" property of the Textbox to string.empty.
With regards to most barcode scanners i've seen and used (usually KB emulation), you can usually set them up to get a prefix and suffix on the data so that you can detect scan input over keyboard input. You can then detect a scan and clear the textbox prior to entering the new information
react at the new scanevent from the barcodescanner and clear the textbox.text with string.empty
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
Basically, I want to make a constant input reader in my form, that waits for inputs and only after the input finishes(these inputs are from an external source, specifically - a hand-held scanner) should it be read, this code works exactly how I want, because the scanner at the end of input somehow informs that it's the end of stream/line(not really sure how though):
while (true)
{
string someString = Console.ReadLine();
doSomethingWithString(someString);
}
but I don't know how to cleanly transfer it to a form application.
Any help would be appreciated.
Assuming I understand you correctly, you want to do something like this:
public void SendScansToForm(string[] scans) //pass in an array (or list, or etc.) of the scanned items
{
MyForm form = new MyForm(); //Create a new instance of the form
form.variableToHoldScans = scans; //variable (on the form instance) to pass the scan to
}
In this way, you read in all the scans, then pass them into a new instance of the form. Presumably, this could be followed with a form.Open() or display the scans to the user, or change as needed to do whatever task is required.
EDIT:
Apparently I didn't understand; if you want to port the current code to forms, you can use System.IO.Stream (as mentioned in the comments). Additionally, you will need to determine how the scanner terminates an entry. This may be with a return character \n, \r, etc. or some other method and likely changes with different scanner models.
EDIT 2 - Additional info from the comments:
In order to read input from a scanner, you need to determine what character it's passing in to terminate the input. From my limited experience, this should be carriage return, line feed, enter or something similar.
Once this has been determined, it should be trivial to implement a method that acts on the presence of this character, allowing you to process each scan as they come in.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have my log-in form and under that there's also the "Change Password" my teacher recommended me that if I write my old password in the old password textbox i'll see the characters, but if I leave that textbox and go to the new password textbox the characters should turn into "*".
How can I make that possible ?
Firstly, by convention there's no need to do this. The only reason that happens on mobile devices is that it's very easy to type wrong characters on tiny keyboards with large fingers. Getting a chance to quickly preview the last typed character is highly desirable. On a WinForms app I've never come across that usability. But, if you really want to do it, you'll need to create a custom control. The problem is that the PasswordChar property will mask all characters, not just all but the last one.
You could perhaps inherit from TextBox and add a property called TimedPasswordChar. Then subscribe to the ValueChanged event. In this handler, if TimedPasswordChar is not null or empty then start a Timer object with a 1000ms interval. In the Tick event handler, stop the timer on the first line the convert the last character to the TimedPasswordChar. Bear in mind though that you will need to add each character you switch to the TimedPasswordChar to a private member variable holding the actual password. I'd suggest using System.Security.SecureString given it's a password.
Just before you convert the last char to the TimedPasswordChar then add the entered value with .AppendChar(...).
One point that complicates it though is if the user edits the string. You need to monitor which string has been edited and then use .RemoveAt(...) on the secure string to keep it in sync.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
In my current project I want to implement a checkbox that, if checked, replaces all strings in labels, tabs, etc. currently being shown on a form with a different string.
For example, If checked, all instances of the word "car" would change to the word "truck" all through out the program.
I'd rather not go through a do a .replace on every single string in the code. I was wondering if there was some way to "intercept" output strings and replace them on the fly; something like making a string-listener. Any help would be appreciated!
I am no GUI/WinForms program but this would be my personal approach. Add all of these UI elements to a List<T> in the forms constructor. Then in the "replace box checked event handler" you can just iterate over the list applying the same change to all the items. It's by no means a perfect solution but it does mean you only have to statically reference each of the items once. After they're in the list you can operate on all of them very easily.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
Just need a little help with a program i have been working on. basically i work in a call centre and i am going to use this to record my notes during calls, i have everything worked out besides on feature. So i when filling out the fields i need it to show up in a specific textbox, and i need to structure this data to specific lines. I also want to try do this without having to store the data to txt file or a database, i want to try do it all within strings if possible. any help would be greatly appreciated guys.
thanks in advance
So in short.. you just created a button and some fields and have no idea how to proceed.. try selecting one programming language as #TheKingDave suggested. For example, if you go for C#..
try to read up on the below links to get yourself started:
system.windows.controls.textbox
system.windows.controls.combobox
but just, if I understand your question correctly, because let's face it, it's far from clear, you want to grab information you added into several textboxes and comboboxes etc and format them into one multiline textbox? If so...
Create a on_click event for your button in which you want to add stuff like..
string Example1 = this.mytextbox1.text;
string Example2 = this.mytextbox2.text;
string Example3 = this.mycombobox.SelectedItem;
...
afterwards you want to add all these strings together, for example
string MyResult = "Example1: " + Example1 + "\r\n" + "Example2" + ... ;
and then show this in your resulting textbox
this.myresulttextbox.text = MyResult;
Hope this answers your question somewhat but I strongly advise reading up on this before going any further..
What is actually your programming language?
Not sure about your question but if your goal is to concatenate everything into a single string, just read the text value from every *boxes you have and add them into the text value of your destination using a special joker character that is unused in your edited fields like 'ยค' for example to separate every string. It's easy then to process it later. The brutal way is to hard code every copy. A slightly more refined one would be to have a list of interesting components and for the copy to loop on them and according their type, chose the right access method to get the information.