Multiline Textbox that receives the lines on top - c#

I have a multiline textbox that receives values from a different class, and I want that every line is added on top instead of the bottom, how can I do that?

Use String.Insert():
textBox.Text = textBox.Text.Insert(0, string.Format("{0}\r\n", "Your text content here"));

Related

How To add * in Textbox Starting value and print into label in C#

I have some text boxes in my form where the user need to enter the different prices of article, what I want to do is to automatically add Starting value * whenever text is changed . So when the user types 1 it is displayed like *****1
and text box Length are 6 size fix. then again user type 111 it is display like ***111
Not sure if you are on web, forms or what, but here is what you looking for:
txt1.Text = txt1.Text.PadLeft(6, '*');
Reference: PadLeft
You can use the PadLeft method for a string:
textBox1.Text = textBox1.Text.PadLeft(6, '*');
See an example here: https://dotnetfiddle.net/GPfFsx

How to bold a part of string being passed into TextBox in c#

I have a string builder where value is appending at runtime via placeholder. Once string builder has appended, it is assigned to a text box (not rich txt) to show up in UI.
I want part of the text to be bold.
sb.AppendFormat("Added {0} by {1}:\n{2}", DateTime.ToString(), userName, note);
txt.Text = sb.ToString();
Expected output:
Added 9/01/2016 8:47:19 PM by Vinoth: Testing Purpose
How can I achieve this? Is there anyway of looping over words with the : symbol until I want it to be bold?
You will have to build up the text in sections.
Either as different TextBoxes/TextBlocks or as a single RichTextBox with separate Runs for the sections you want in a different style.

Over come placeholder text with innerText

What I want to do is to fill it with text programatically.
webBrowser1.Document.GetElementById("textBox").InnerText = "foo";
This code works but some websites have a placeholder text. This code will not allow me to fill this as value but instead it as a placeholder text.
Strangely in some text box, it will be paste as value when there are a placeholder text. But some text box it wont.
Another scenario is that when it is innerText is placed as a placeholder text, all I have to do is click on that text box and write something next to it. This will act as a text box values.
Is there another way around this?
You need to set the value attribute of the <input id='textBox'> elment not the innertext.
webBrowser1.Document.GetElementById("textBox").SetAttribute("value", "text text text");

How to add text boxes dynamically when one text box is filled?

I have text box to fill the ph.numbers in that, here what i want is, whenever i'm entering the value in that text box i need to add another empty text box dynamically where i can add another value in that in the same way if they are entering any value into this new empty box another empty text box should add at the bottom of this. And after all there is a confirm link button. When clicking on it all these ph.numbers entering on the text boxes should get. How is it possible?
You add textboxes dynamically using jquery and on the button click/submit there values to the server. What you can do is on keyup event of a textbox you can add another below it.
Try this.
I'm basing this condition that your number format is of 11, Ex: 09123456789
So on the Textbox_Textchanged event of your textbox.
if(textbox.text.length >= 11)
{
Textbox text = new Textbox();
text.TextChanged += Textbox_Textchanged; // So it would also trigger the event
// Do positioning here
}
Im thinking you can better optimize this by having a better EventArgs but you get the idea right?

How to Make a Text Box Equal All Letters To The Left of a Specific Letter or Character From Another Text Box in C#

I am trying to figure out a simple way of making a text box equal all letters to the left of a "-" in another text box. Basically, if an end-user types blah-test in textbox1, I would like textbox2 to equal blah. I have tried if statements and substrings based off of letter position count (i.e. substring(0, 5); however, this got very lengthy and impractical, since the words entered into textbox1 can be any length.
Thank you,
DFM
Try this:
if(textbox2.text.Contains("-"))
{
textbox1.text = textbox2.text.Split("-")[0];
}
Here we first check if textbox2 contains the - character and if it does we split the text in two parts and set the text of textbox1 to the part that is left of the first - character.
it's very simple
select and double click on the OnTextChange event on textbox1
Write this code inside textbox1_OnTextChange:
string text = textbox1.Text;
textbox2.text = text.Substring(0, text.indexOf("-"));
and you're done!

Categories

Resources