Click here to Skip to main content
15,886,110 members
Everything / TextBoxBase

TextBoxBase

TextBoxBase

Great Reads

by PIEBALDconsult
Getting the line and position of the cursor in a TextBox
by siliconvideo
This StringBox control implements keystroke validation using regular expressions and a touch of glue logic
by PIEBALDconsult
OK, here's another way (I found this at http://dotnet.mvps.org/dotnet/faqs/?id=textboxcaretpos&lang=en[^]). [System.Runtime.InteropServices.StructLayoutAttribute (System.Runtime.InteropServices.LayoutKind.Sequential)]private struct ApiXY{ public int X ; public int Y ;}[ ...
by Tadit Dash (ତଡିତ୍ କୁମାର ଦାଶ)
Inspired by a question, I am blogging about a simple technique to attach KeyPress Event to all the TextBoxes of a WebPage.

Latest Articles

by siliconvideo
This StringBox control implements keystroke validation using regular expressions and a touch of glue logic
by Tadit Dash (ତଡିତ୍ କୁମାର ଦାଶ)
Inspired by a question, I am blogging about a simple technique to attach KeyPress Event to all the TextBoxes of a WebPage.
by PIEBALDconsult
Getting the line and position of the cursor in a TextBox
by PIEBALDconsult
OK, here's another way (I found this at http://dotnet.mvps.org/dotnet/faqs/?id=textboxcaretpos&lang=en[^]). [System.Runtime.InteropServices.StructLayoutAttribute (System.Runtime.InteropServices.LayoutKind.Sequential)]private struct ApiXY{ public int X ; public int Y ;}[ ...

All Articles

Sort by Score

TextBoxBase 

3 Jan 2012 by PIEBALDconsult
Getting the line and position of the cursor in a TextBox
22 Jul 2020 by siliconvideo
This StringBox control implements keystroke validation using regular expressions and a touch of glue logic
17 Feb 2012 by vonDy
i have a gridview and a textboxall i wanna do is a searching textbox that on each onkeyup the gridview contents changedi did this part althoughthe problem is when the page postback, the focus on textbox lost.And when i write code in code-behind as textbox.focus(), all the element...
11 Apr 2013 by Sergey Alexandrovich Kryukov
It could be something likeconst string numericFormat = "###,###,###,###,###,###,###"; // make it long enough to fit maximum and minimum decimal of the range you need// if this string is longer then needed, it won't harm//...decimal myValue = //...myTextBox.Text =...
8 Sep 2013 by Joezer BH
Your line is just fine for converting your textbox's text to an int.//You could also use int.Parse(textBox1.Text);Using the counter variable in your code as seconds will be when you use it in the code's context.e.g. main(){ counter = Convert.Toint32(textBox1.Text.Trim()); ...
1 Jan 2014 by CHill60
You have several issues with your attempts. Most importantly you are trying to mix numeric data and string data. Sometimes you will get an implicit conversion done "for you" but you should never rely on this.In your second attempt you are confusing SelectedIndex (the rank of the selected...
22 Jan 2014 by Dnyaneshwar@Pune
Change the property of your text box to enableViewState=false and AutoPostback=true
30 Nov 2016 by Karthik_Mahalingam
try like thisint value1 ,value2; bool isValid1 = int.TryParse(textbox1.Text, out value1); bool isValid2 = int.TryParse(textbox2.Text, out value2); if (isValid1 && isValid2) { if (value1 > value2) { // your...
20 Jun 2017 by Patrice T
Try private void save_Click(object sender, EventArgs e) { Properties.Settings.Default.Source = textBox1.Text; Properties.Settings.Default.Save(); Application.Exit(); }
10 Feb 2020 by OriginalGriff
You can't, not unless you create an entirely new TextBox-like control form a UserControl and allow am much, much larger-than-standard Length. But it's not a good idea, even if you could (or you go to all the effort involved in "rolling your own"...
9 Apr 2020 by Maciej Los
Just create a new textbox inside a loop: Imports System.Text Imports System.Text.RegularExpressions Public Class Form1 Dim myTxtBoxes As List(Of TextBox) = New List(Of TextBox) Private Sub Button1_Click(sender As Object, e As...
25 Dec 2011 by PIEBALDconsult
OK, here's another way (I found this at http://dotnet.mvps.org/dotnet/faqs/?id=textboxcaretpos&lang=en[^]). [System.Runtime.InteropServices.StructLayoutAttribute (System.Runtime.InteropServices.LayoutKind.Sequential)]private struct ApiXY{ public int X ; public int Y ;}[ ...
7 Feb 2012 by Christian Graus
This is an insane 'learning' project. You'd have to hook in to the existing applications, and change them. I am not sure if it's possible in WPF, but I know the methods I can think of, would not work in WPF. In any case, you'd be learning how to do things that are ugly and should be avoided. ...
12 Feb 2012 by RDBurmon
Try this using System;using System.IO;class Program{ static void Main() { // See if this file exists in the SAME DIRECTORY. if (File.Exists("TextFile1.txt")) { Console.WriteLine("The file exists."); } // See if this file exists in the C:\...
23 Feb 2012 by Sudip Saha
Use itint totalexp ;int.tryParse(txtTotalExpPer.Text,out totalexp )
19 Jun 2012 by OriginalGriff
Assuming you are using a standard MaskedTextBox: maskedTextBox1.Select(0, 0);
17 Jan 2013 by rakesh1503
hi,what i can suggest you to go by is the code like below:suppose,we have this sort of design ...
11 Apr 2013 by Prasad Khandekar
Hello,Here is a example directly taken from MSDN. You will have to modify it a bit to suite your needs,// Boolean flag used to determine when a character other than a number is entered.private bool nonNumberEntered = false;// Handle the KeyDown event to determine the type of...
7 May 2013 by OriginalGriff
No - there is no standard way to change either the size of the text box, or the font size to fit the text into the display.However, if you make it multi line and enable ScrollBars it can do something like what you want.If you must have a re-sizing control, then I suspect you will have to...
27 May 2013 by renish patel
Properties those you have to set to the textbox :AutoCompleteMode : Suggest AppendAuoCompleteSource : CustomSourceThese properties must set to the textbox that to which textbox you want to set the AutoCompleteMode.Then only the code will be performs.Event: This code should...
15 Sep 2013 by norbitrial
If you just need this operation you can use some of the events on clientside for textbox.There is for example a onchange event for textbox on clientside. You can use it and after validation the text of your label will be changed.Just add this line to your code and try...
21 Oct 2013 by Sergey Alexandrovich Kryukov
There is no one correct format for that. Main messages can have different parts, each in its own "format": text, graphics, and more. One of the content types is HTML, but some use RTF (way too obsolete). After all processing, everything is represented and sent as a plain text, but parts of the...
5 Dec 2013 by Sergey Alexandrovich Kryukov
"Focus" in Windows means "keyboard focus" and nothing else. This is the ability of the control to handle keyboard events. Not all controls are focusable. If a control is focusable, calling its Focus method in invalid or is ignored. The focus in general is explained here:...
5 Jan 2014 by SukyCZ
Hello guys,First of all sorry for my bad english.Is there any way how to calculate in listwiev?I have a list view with two columns, ID and Number, using searching from text box.SEARCH BUTTONforeach(ListViewItem ID in listView1.Items) { if (search.Text...
5 Jan 2014 by Abhinav S
You can easily search the number within the listbox.Have a look at this[^] example.
5 Jan 2014 by BillWoodruff
Here's a simple illustration of how to search a ListView for a ListViewItem that matches a string, and how to get the match's SubItem, test to see if it is convertible to a number, and convert it to a number.private void button1_Click(object sender, EventArgs e){ ListViewItem foundItem =...
22 Jan 2014 by V5709
Make Text Box blank after showing error message & if u want to show entered text value also then make it visible in your error message likelblmessage.Text = "'Your entered text' is Already Exist";
14 Jun 2014 by Tadit Dash (ତଡିତ୍ କୁମାର ଦାଶ)
Use JavaScript.Attach the onkeypress event for that TextBox on which you want to press Enter key.Check which key is pressed. If it is Enter Key, then do your calculation.
18 Dec 2014 by BacchusBeale
You need a method such as:string dir ="path";if(Directory.Exists(dir)==false) Directory.CreateDirectory(dir);
3 May 2015 by Suvendu Shekhar Giri
That concept is called validation, FYI.You check the value at your property layer (if you have one) or on the button click or where ever you want you can just write a simple if..else.. statement to check that.Something like-try{ int yourValue=int.Parse(txtYourTb.Text); ...
10 Nov 2015 by OriginalGriff
Try:string a;double bb;if (!double.TryParse(textBox1.Text, out bb)) { // Report a problem to the user. ... }else { a = bb.ToString("#,000.00"); ...
10 Nov 2015 by Abhinav S
Try string.Format("{0:n0}", bb);.
23 Feb 2016 by OriginalGriff
Try:myList.Add(myTextBox.Text);
18 Dec 2016 by Mehedi Shams
Hi Member 9983063,This is not a problem at all. Just use ToString() in the message box as message box requires a string in it.MessageBox.Show(a3.ToString());
19 Dec 2016 by Mehedi Shams
Hi Member 9983063,This is not the way TryParse() works. TryParse() requires two parameters - one is the text to convert to integer, and the second is the output variable where it stores the converted value. The code you provided translates into:if (Boolean > Boolean) // You are trying...
19 Dec 2016 by Jean-Claude ADIBA
Hi try this int textBox00 = 0; int txtTotal = 0; if(int.TryParse(textBox00.Text, out textBox00) && int.TryParse(txtTotal.Text,out txtTotal)) { if (textBox00 > txtTotal) { ...
11 Feb 2020 by Dave Kreskowiak
Why would you want to do this? The existing MaxLength of the TextBox also reflects the actual maximum length of a string in bytes. You can't make a MaxLength property larger and have it work. You can't create a string bigger than Int32.MaxValue...
1 Dec 2021 by Dave Kreskowiak
So what does the sequence look like when you're saving the text to the database? It's fairly easy to normalize that text before you save the data, though it's not a configurable setting. This is how web browsers work, and you have to write your...
20 Jun 2023 by Andre Oosthuizen
I have found a very good tutorial with examples that might suit your needs at - Writing for Web Accessibility[^] Topics covered - Quote: -Provide informative, unique page titles -Use headings to convey meaning and structure -Make link text...
3 Nov 2023 by Dave Kreskowiak
Like Richard already said, I told you how to validate credentials against the machines local account database that does not use shelling out to "NET USE". It is not called "in Windows services". That phrase means something completely different...
30 Oct 2023 by Richard Deeming
You can't. Windows does not store user passwords using a reversible encryption. Passwords technical overview | Microsoft Learn[^]: For use in Windows networking, including Active Directory domains, the password is stored two different ways by...
30 Oct 2023 by Dave Kreskowiak
An "admin license," whatever that is, has nothing to do with this. You're completely misunderstanding the Windows security system and directory. You cannot check an entered password against what you perceive to be a plain text password in the...
25 Dec 2011 by Himachandra
Hai All, I am developing one application in VB.net for Serialport reading from GSM Modem......While i read data from serialport that is append to string variable, after that i need to check weather that text is valid or not , if data is valid i append that text to TextBox.Text here I...
25 Dec 2011 by Abhinav S
You are trying to access the textbox on a thread (the socket return method) which is not the main UI thread. Hence you get the error.You can solve this by using the invoke method as explained here[^].
7 Feb 2012 by Mazen el Senih
Hi angel :I think your idea is very interesting !,here is my answer hope you will find what you are looking for :You may build an application as a service (or hidden process) which its mission is to hook on every window (using API functions) and convert any Text box to password char...
12 Feb 2012 by MR. AngelMendez
Hi, I am currently finishing up my first successful project but I still need some help with a bug. In my project your able to type in a TextBox("search box") that TextBox is there so that users can start which ever program name or path they type. The problem is that I get a default error...
12 Feb 2012 by OriginalGriff
Try:if (!File.Exists(path)) { ... }Off topic - yes, if you explain your code well, and it is interesting, you could submit it as a article. Have a look under "Articles" on the menu bar in the top left of the screen. Be aware though that an article is a lot of work, you can't...
18 Feb 2012 by Nilesh Patil Kolhapur
Hey This Javascript work fine for me//for serching gridview on keyup function Filter(Obj) { var grid = document.getElementById('cntPlcHolder_gvDisplay'); var terms = Obj.value.toUpperCase(); var cellNr = 0; //your grid cellindex like name ...
23 Feb 2012 by piushshukla
I want to insert the value in textbox int totalexp = Int32.Parse(txtTotalExpPer.Text);but if field is empty then it gives the error[edit]pre tag c# code added and Treat my content as plain text, not as HTML is unchecked - PES[/edit]
23 Feb 2012 by E.F. Nijboer
Have a look at TryParse. http://msdn.microsoft.com/en-us/library/f02979c7.aspx[^]Good luck!
23 Feb 2012 by Manoj Kumar Choubey
Use require validation or check before type conversion .......
23 Feb 2012 by AmitKumar89
hi there..try to use required field validator.. or else use this code..int totalexp = Convert.ToInt32(txtTotalExpPer.Text);all the best..
23 Feb 2012 by Nandakishore G N
so...u have to insert the value from totalexp to textbox(i.e,txtTotalExpPer.Text)right...then use...txtTotalExpPer.Text=totalexp .ToString();...You Can Check The TextBox Is Empty..By Using If()...
24 Feb 2012 by Adeyinka Oluwaseun Doyin
Use this code , it works... i wrote and tested it.private void button1_Click(object sender, EventArgs e) { int expectedResultFormat; string ExpPer = txtTotalExpPer.Text; // first pass the value to a string variable bool myResult =...
24 May 2012 by Sesharaman
Try the followingShadows Text property hides the base class Text property. Hence usage of Mybase.text in my opinion is not successful. So, make the method overrides and use text as string. Have another property to report double value. In the designer hide the text value and report the double....
27 May 2012 by Member 8743576
i want to load my datagrid view from main form to child form. the child form contain textbox... this is the code when my child form load and fill the textbox wtih data from datagridview.. private void Form3_Load(object sender, EventArgs e) { ...
27 May 2012 by Monjurul Habib
Try using the following lines and let me know if there is any other issue:DateTime elshose;bool elshoseOkay;//elshoseOkay = DateTime.TryParse("1/21/2012 12:00:00 AM", out elshose);elshoseOkay = DateTime.TryParse(Data["tahunterbit"].ToString(), out elshose);if (elshoseOkay){ ...
19 Jun 2012 by Usman Hussain Attari
HiI mask A textBox.But when i run the application and Open the form My cursor is blinking after the masked area in textbox and i have to set the cursor at first character.Can any one tell the solution that when i open the form my cursor is at initial point.
2 Jul 2012 by EriBeh
Since TextBox.GetCharacterIndexFromPoint always seems to return a position before a character, and not a psoition behind a cahracter, even if you click right of the latest character, it could be a solution to calculate myself if the position is right of the last char:if (mousePoint.X >...
2 Jul 2012 by EriBeh
Found the solution. Thanks for your interest.SizeF size;using (System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(new Bitmap(1, 1))){ size = graphics.MeasureString(CustomTextBox.Text, new Font(CustomTextBox.FontFamily.ToString(),...
24 Jul 2012 by FoxRoot
Hi everyone,I am newly started C# and also oracle. I am developing a phone book at c#. I am Using Oracle DB. I have completed insert, delete, search. However, I cant update the information. Please help me. That is my first question. Sorry for my ignorance.I list the records on a gridtable....
24 Jul 2012 by sachin10d
Try this OracleConnection con = new OracleConnection("Data Source=O10G;User Id=plsql_staj;Password=*****;"); con.Open(); string query = string.Format("UPDATE TEL_REHBERI SET AD ='{0}', SOYAD ='{1}', YAS = '{2}', CEP_NO = '{3}' , EV_NO = '{4}', DOGUMYERI =...
30 Jul 2012 by FoxRoot
Hello everyone. I am getting data via textbox but I want to restrict it. Namely, User can not enter character string or anything. I just want numeric characters between 100 and 999. Is it possible ?String coursecode = Integer.parseInt(txtCourseCode.getText());if(coursecode
30 Jul 2012 by I.explore.code
Think this does count as a solution. You can try using Regular Expressions to restrict the input to numbers only and once that's done you can have a bounds check on the values, which you already have done in your code apparently.
1 Aug 2012 by Leo Rajendra Dhakal
I'm using textbox inside Gridview with ajax. I've following columns:SN, ItemCode, ItemName, PurchaseRate, SalesRate1, where SN is automatic generated in accordance of rows2, We select ItemName through autocomplete extender.3, we have to set itemCode columns after selected ItemName4,...
21 Sep 2012 by jim lahey
I don't think your jQuery string is correct. Try this:String str = "$('.txt').css('border-style', 'none');";On another matter, SA is correct: you don't need to and shouldn't .ToString() a string.
21 Sep 2012 by Sergey Alexandrovich Kryukov
I would advise to use the scripts:$(.txt).addClass("withBorder");// and$(.txt).removeClass("withBorder");Your ".txt" CSS class should be without the borders, and the class "withBorder" (should be named like that, without '.'), should define some border. This way, you can switch between...
28 Nov 2012 by daniel micah
please i want to know how to insert an image into a textbox in asp.net,please can anybody help me out?
28 Nov 2012 by OriginalGriff
Textboxes hold text: not images. You would have to create your own custom control to hold an image instead (or as well).
1 Jan 2013 by Member 9490803
i have 2 working databases. one is called EquipmentDB one is called EmployeeDBI created another form. I want to key in the Company ID of the employee in the textbox and click a Button. The rest of the details of the employee will display in textbox or label as followed:Name:Department:...
1 Jan 2013 by Sampath Kumar Sathiya
Hi,Try the following,http://stackoverflow.com/questions/11855651/multiple-connection-string[^]
1 Jan 2013 by Zafar Sultan
If you have your databases on different servers you can use two connection strings. But if you have your databases on the same server you can pass database name as a variable to your stored procedure and there you can create a dynamic query. For example:Create Procedure...
17 Jan 2013 by Member 9750618
i want to update marks of a particular student in particular subject out of eight subjects.know my question is how to identify that the particular text box value has been changed after clicking submit button there by the updation task is forwarded to the update.php. please give me your...
9 Feb 2013 by Software Engineer 892
How to restrict user not to select previous years using Textbox calendar extender.---------------------------------------------------------------------------------Hi FRNDS,my project is based on Asp.net c#.In this Project, We will create new users to access the Project.In this...
10 Feb 2013 by Pallavi Waikar
go trough following links Tip.6..AJAX Calender Extender[^] Calendar Extender function checkDate(sender,args){var selDate= sender._selectedDate;var today = new Date(); if (selDate.getFullYear() > today.getFullYear()){alert("You cannot select a day earlier than...
17 Feb 2013 by Sergey Alexandrovich Kryukov
First of all, I don't know what timer do you use. If you are using you are using System.Windows.Forms.Timer, don't do it: this timer is absolutely unsuitable for animation, because its accuracy is unacceptable, it can be amazingly bad. The only "benefit" of this timer class is the simplicity of...
23 Feb 2013 by sadat_prog
hi my friends!I want create vertical Text Box in design or run time that user in run time type in itpleas help me
23 Feb 2013 by aliwpf
Hi.i guess you want to have a TextBox like this: ...
6 Mar 2013 by Kaizen202
Hi All,I have a TextBox in my Form and I am drawing a string into it as below.Font myFont = new Font("Arial",18F,FontStyle.Regular,GraphicsUnit.Point,128);Graphics g = myTextBox.CreateGraphics();Brush b = new SolidBrush(Color.Red);g.DrawString("Item Drawn with DrawString",myFont...
6 Mar 2013 by garaber
That's a good question. You'll have to download the source for those calls to find out.Graphics.cs this is only one version there are others public void DrawString(String s, Font font, Brush brush,RectangleF layoutRectangle, StringFormat format) { if (brush == null) ...
3 Apr 2013 by Pablo Aliskevicius
Replace vbLf and vbCrLf by ""Hope this helps, Pablo.
12 Apr 2013 by Clifford Nelson
void textBox1_KeyPress(object sender, KeyPressEventArgs e){if (!Char.IsDigit(e.KeyChar) && e.KeyCode != Keys.Back ){e.Handled = true;}}
7 May 2013 by Luci C
I create programatically some textboxes, and I want to put some text in them. But they don't display the whole text, I have to click and drag to left to show all text..Isn't there an option, maybe "AutoSize", "AutoFit" or something like that?Thank you!
7 May 2013 by CHill60
You can use TextRenderer http://msdn.microsoft.com/en-us/library/system.windows.forms.textrenderer.aspx[^] to determine what size the text box needs to be in the TextChanged event of the textbox - or better yet do as OriginalGriff suggests and make your own re-sizing custom control inheriting...
7 May 2013 by venkatesh ekkaluri
in text box properties change the text mode(single line->multiline)
3 Jun 2013 by Matt T Heffron
You can specify the color of a subset of the text in a or using the element:
4 Jun 2013 by rohith naik
Thanks Matt T Heffron for the solution. Here is how I did it on code behindFlowDocument fldoc = generateFlowDocument(MyList);richTextBox.Document = fldoc;private FlowDocument generateFlowDocument(List> MyList){ FlowDocument fd = new FlowDocument(); ...
7 Jun 2013 by Majid Yaghoubi
Hi every body !I have a table (WareTable) in SQL Server.My table has 3 columns: (wareName,SellPrice,Stoke)I need to use a datagridviwe(=dgw) in my form. datasource = WareTableIn my dgw , 1st column is a ComboBox (WareName).I want when choose a value in ComboBox , next column...
7 Jun 2013 by Sergey Alexandrovich Kryukov
Assign a string value to System.Windows.Forms.DataGridViewCell.Value:http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcell.aspx[^],http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcell.value.aspx[^].You need to be sure that the cell's...
3 Jul 2013 by LordVovin
Hi everyone!,I'm trying to create a project, so that I will have the opportunity to refill the table on SQL server. The table is created and it has several columns. I searched the internet, but did not come across to the the solution I'm looking for. Maybe, I will explain first what would my...
3 Jul 2013 by John M Bundy
Not sure I am following exactly, but is sounds like you are just trying to get the lines of a multi-line textbox and store them.For Each Str As String In Me.TextBox2.Lines MsgBox(Str) NextIf you have country in say textbox1 then you can useFor Each Str As String In...
8 Sep 2013 by Nitin Singh India
If you want to delay the execution of a code block for a given period, and want the period to be given as input at runtime from the user, you code to take in intervals in seconds is ok. Once you have this time, convert it into milli-seconds (x 1000) and have a call to Thread.Sleep(period) and...
9 Sep 2013 by BillWoodruff
I was about to post this a few hours ago, and then my computer crashed, and some business came up that had to be handled, but I'll post it anyway.I assume that when the OP says "take the amount of seconds from user, and my program will run for this amount of seconds," they mean they want to...
15 Sep 2013 by sazzad37
I have create a textbox by simply clicking a button. TextBox txtGainMark = new TextBox(); txtGainMark.ID = count.ToString(); txtGainMark.Text = "GiveYourMark"; txtGainMark.TextChanged += new EventHandler(updateGivenMark); ...
15 Sep 2013 by sazzad37
I have create a textbox by simply clicking a button. TextBox txtGainMark = new TextBox(); txtGainMark.ID = count.ToString(); txtGainMark.Text = "GiveYourMark"; txtGainMark.Attributes.Add("onchange",...
15 Sep 2013 by Gitanjali Singh
protected void Page_Load(object sender, EventArgs e) { TextBox textBox = new TextBox(); textBox.TextChanged += new EventHandler(textBox_TextChanged); } protected void textBox_TextChanged(object sender, EventArgs e) { // Your code here }Hope...
16 Sep 2013 by Anand Kumar Prajapati
Before adding Textbox to placeholder, just bind TextChanged event to it.{ //... same previous code txtGainMark.TextChanged += new EventHandler(txtGainMark_TextChanged); placeholder.Controls.Add(txtGainMark);}protected void txtGainMark_TextChanged(object sender,...
15 Sep 2013 by Singh Gyan
Yes please check with autopostback property. You are not submitting the page on text chnage thats why unable to submit the page.
26 Nov 2013 by Sampath Lokuge
For that you can use javascript function window.print().For more info check below mentioned links:If you need to print an specific content, you can hide the rest (and format the printed area) by CSS: .noPrint{ display: block; } .yesPrint{ display: block...