Click here to Skip to main content
15,891,943 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 Updated

TextBoxBase 

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[^].
5 Jan 2014 by Abhinav S
You can easily search the number within the listbox.Have a look at this[^] example.
2 Apr 2015 by Abhinav S
You will need a method that will check the validity of the password.For e.g. in code below IsValidPasxword() will check if password is valid. protected void txtpwd_TextChanged(object sender, EventArgs e) { if (txtpwd.Text == IsValidPasxword()) { ...
10 Nov 2015 by Abhinav S
Try string.Format("{0:n0}", bb);.
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 =...
22 Dec 2018 by Ahmed Taha
I have text-boxes and their texts are set by default to normal or none, the problem is that when I click on one text-box and then click on another text-box, all the other text-boxes default text will disappear. You can check this picture to understand my problem: Imgur: The magic of the...
27 May 2013 by ajaypelluri555
Auto complete textbox property in .net has the custom source was given in coding phase but it had to save new ones aromatically in the source at run time .I find the code but the new ones are saved until the app is open.and then we close and open it again it will not showing the new ones.
7 Oct 2018 by Alex McAllister
Im making a site where my students can submit anonymous answers to me, I have a domain for the site, and I just want the site to be a blank page with a text box that they can enter words into. How to I receive what the students posted, so that other students cant see it? Can I send the answers...
23 Feb 2013 by aliwpf
Hi.i guess you want to have a TextBox like this: ...
1 Jan 2014 by amadofirst
Iam using Visual studio 2012,i would like to change text box values automatically based on fixed combo box values, meaning i have combobox with 4 fixed values & i want to change another text box values based on these changeable values.so anyone know simple method to apply that will...
18 Dec 2014 by Amir Mir Motahari
dear programming talentshi i Need urgent help to create a folder with the name of the combo box and text box values in solution directory, and put the pictureBox image into the folder and if folders Already created , it does not re-create And then copy the image directly into the old...
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..
11 Apr 2013 by Amogh Natu
You can validate that in javascript. Use the following code. function Validate() { var txtValue = document.getElementById("MainContent_txtTestBox").value; var checkFlag = isNaN(txtValue); if (!checkFlag) { return...
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,...
13 Nov 2014 by Anbu_Mannan
function ValidateDate(txt, keyCode) { if(keyCode==16) isShift = false; var val=txt.value; var lblmesg = document.getElementById("") ; if(val.length == 10) { var...
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...
17 Feb 2013 by Andrews Smith
I have created a timer which makes a textbox's text appear to be moving from left to right, how can I make it look smoother?So far it does what I want, but the movement doesn't look right.Timer internal is 100Code:Public Class Form1 Dim CurrentName As String =...
27 Apr 2015 by Andy Lanng
The issue is that editing the text inputs value as someone types will reset the caret (cursor) position to after the new text.You need to A: Get where the caret is before changing the text and B: Set the caret after changing the text:function A(element){ //You will won't to add...
4 Jun 2015 by Andy Lanng
Simple :)or fro winforms check out this article:TextBox with Placeholder[^]WPF XAMP:XAML only WPF Watermarked TextBox[^] and A WatermarkTextBox in 3 lines of XAML[^]finally: the heretics on SO have...
7 Dec 2014 by Anurag Prajesh
String lblValue=lblUserID.Text;String quesryString="Home.aspx?uid='"+lblValue+"'";
14 Jul 2014 by ArunRajendra
In which event are you doing this. you need do this key down event.
24 Jul 2012 by AshishChaudha
Dear turan,Is there any identity field in your table, update your record on basis of an identity field not with Textfield. and Try to use parameterized query, so No SQL injection will distroy your data.string query = "UPDATE TEL_REHBERI SET AD ='" + txtGnclAd.Text.ToUpper() + "' , SOYAD...
18 Dec 2014 by BacchusBeale
You need a method such as:string dir ="path";if(Directory.Exists(dir)==false) Directory.CreateDirectory(dir);
11 May 2015 by Bert Goens - HW
* Are you certain you didnt place another textbox above this one? * Is the textbox attribute ReadOnly=false?* Is the textbox attribute Enabled=true?
19 Jun 2012 by bhagirathimfs
Use Focus method.Like if you want your cursor should select a textbox then write TextBox1.Focus().
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...
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 =...
30 Jul 2016 by BillWoodruff
Rendering characters in any language requires your having those language resources installed on your system, and you need to use the appropriate Windows "CultureInfo" class instance (language specific software context) to display text: [^]. Also, see: [^].There's a code example here using...
3 Oct 2018 by Bob@work
You can set the listview.itemselectionchanged to change the text in a textbox. For a list that only allows a single selection: Private Sub myListView_ItemSelectionChanged(sender As Object, e As ListViewItemSelectionChangedEventArgs) Handles myListView.ItemSelectionChanged If...
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...
18 Dec 2013 by CHill60
You are much better off asking the author to help you out ... post a comment against his article at Fast Colored TextBox for Syntax Highlighting[^]
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...
15 Jul 2014 by CHill60
Because you have this code in the Form_Load event you are only setting the initial state of the TextBox2You also need to respond to the user entering data into TextBox1You could put this into the Private Sub TextBox1_KeyDown event, but note that it would run each time the user pressed a...
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 Apr 2013 by Clifford Nelson
void textBox1_KeyPress(object sender, KeyPressEventArgs e){if (!Char.IsDigit(e.KeyChar) && e.KeyCode != Keys.Back ){e.Handled = true;}}
2 Dec 2021 by Craig Borri
I have an ASP.net application that saves a multi-line text box to SQL. We've found that when the user puts line breaks into the text, they are saved as the LF character, not CR/LF. This doesn't matter for our application, as it inserts the ...
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?
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 Jan 2023 by Dave Kreskowiak
Don't use foreach for this. Use a normal for loop and start the index at 1 instead of 0. The TextBox does not know the concept of "line" so you have to parse the text, probably .Split on Environment.NewLine, the go through the resulting string...
18 Jun 2023 by Dave Kreskowiak
As far as I can see, there is no solution to your problem. The spelling errors collection returns ranges in Word, which do not map to the text in your textbox.
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 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...
7 Dec 2017 by ddgjgj
This is a working code , but want i want to do is how can i change the textbox @Html.TextBoxFor(model => model.CategoryID, new { @class = "form-control" }) into dropdowncolumn , with all the same functionalities has ,i mean autocomplete option like that : ...
25 Apr 2016 by Derek Kennard
Hello, I was reading the article at Code Project and the suggestion worked great; however, now I'm stuck with a new problem. I get Object reference not set to an instance of an object on my textboxes. Code: private void DgPatSrch_SelectionChanged(object sender,...
10 Sep 2015 by Dipsi Jain
I m tryig to access the Textbox wich is dynamically created in Gridview ...But cannot Get its value on Button Click.Plz help me to find this Out...! :)
22 Jan 2014 by Dnyaneshwar@Pune
Change the property of your text box to enableViewState=false and AutoPostback=true
27 Jan 2014 by DoingWork
Suggestion list for a text box updated dynamically and fetched from sql database. When I press down key to select/Scroll item from suggestion list then 1st item is selected only. I can't select 2nd, 3rd, 4th ans so on items from suggestion list. How to resolve it ? Here is my code...........
23 Feb 2012 by E.F. Nijboer
Have a look at TryParse. http://msdn.microsoft.com/en-us/library/f02979c7.aspx[^]Good luck!
24 Jul 2016 by Echospider
If you want to display the value of a particular column then you have to usetextBox63.Text = ds.Tables[0].Rows[0]["ColumnName"].ToString();ORtextBox63.Text = ds.Tables[0].Rows[0][ColumnIndex].ToString();
25 Dec 2018 by el_tot93
Dear: friends please if you have time to solve my problem i have many textbox in my form with one button and one datagridview i use this code to make the search DataTable dt = new DataTable(); if (txtCIVILIDD.Text.Length > 0) { ...
25 Dec 2018 by el_tot93
i get the solution with this code i hope it help anyone private string CreateSqlFilter(string fieldName, Control userInputControl, SqlCommand command, bool exactMatch) { string searchValue = null; if (userInputControl is TextBox) searchValue = ((TextBox)userInputControl).Text; ...
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(),...
4 Dec 2022 by ernteSKY
I load all of data from the database into a List then display all in a ListBox. games_listBox.DataSource = _games; All games have a data: year of publication, year of manufacture, name, manufacturer, category. The question: How to display...
9 Jun 2016 by F-ES Sitecore
There is an example of how to edit a listview and access the controls hereEdit,Update,Delete and Insert in ListView Control[^]
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 FoxRoot
Is there anybody to solve this? Please
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
21 Oct 2013 by Gadgetzoned
I don't know the correct format for email using textbox. because I am going to put a lot or recipients. I'm gonna call the textbox only
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) ...
31 Jul 2016 by Garth J Lancaster
In Addition to Bill's answer to a very similar question you posted here How to get system time in arabic in C# label[^] you could also look at Microsoft Middleeast - MSDN[^]
10 Nov 2015 by George Jonsson
I think you will find the help you need reading the info on MSDN: Custom Numeric Format Strings[^]It also depends on the localization setting you have on your computer.
4 Jun 2015 by Gihan Liyanage
Simple Article http://www.codeproject.com/Articles/27849/WaterMark-TextBox-For-Desktop-Applications-Using-C[^]
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...
7 Jul 2014 by goathik
That isn't possible. You must try a different approach concerning the business role, or you use a grid or a third party control to perform that.
5 Mar 2017 by Graeme_Grant
IF you want the simple format as an alternative to the above answers:sum1 = sum1 + Double.Parse(dataGridView2.Rows[i].Cells[1].Value);which is exactly the same assum1 += Double.Parse(dataGridView2.Rows[i].Cells[1].Value);
20 Jan 2023 by Graeme_Grant
This is a pretty straightforward task: Dim text = "Line 1" + vbCrLf + "Line 2" + vbCrLf + "Line 3" + vbCrLf + "Line 4" + vbCrLf + "Line 5" + vbCrLf Dim lines = text.Split(New Char() {vbCr, vbLf},...
11 Apr 2013 by Halit YILMAZ
hi,i have a form to get customer informations and i must have a number value in a textbox. my problem is getting it formatted as decimal on key press according to culture. forexample when i typed 100025 into a textbox i want it to format as 1.000,25 while i am writing. how can i do...
25 Sep 2015 by Hani Mehdi
hello friends,im using following code to insert data in database using dynamic text box. its work excellent but now i want to submit data in database without refresh page.kindly advise what and where i change my code.plz help. thanks in advance :)OUTPUT.PHP
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...
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.
4 Nov 2023 by Inczu
I want to create a code using netuser function that will search by clicking on the button: private void NextForm3_Click(object sender, EventArgs e) if the user by selecting an Item from listbox. private void...
4 Nov 2023 by Inczu
I want to create a code without admin license when I select a username from a Items listbox: private void ExistUserList_SelectedIndexChanged(object sender, EventArgs e) Then the code must search the same username in lusrmgr.msc and put the...
14 Nov 2023 by Inczu
I have a admin account in Windows Forms. I have a code that create a account to the lusrmgr but the problem is when I want to write username before creating a account, I will always have a username called NowyUzytkownik (in polish language it's:...
1 Dec 2023 by Inczu
Hello, I want to create a research for my listbox. I have created listbox called: public void ExistUserList_SelectedIndexChanged(object sender, EventArgs e) and a code that will write in a textbox private void AllText2_TextChanged(object...
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) { ...
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.
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()); ...
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...
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...
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...
5 Mar 2017 by Karthik_Mahalingam
This will take care of empty/null values in the cellsDouble sum = 0; for (int i = 0; i
22 Jan 2014 by ketan italiya
Why ontextchanged event of textbox isnot working after postback
5 Mar 2017 by Kornfeld Eliyahu Peter
It seems you are using SQL... so use SQL's power and sum the value at the SQL level...SUM (Transact-SQL)[^]SELECT SUM(double_colum) FROM table1But if you insist to do it in code, do it right...Double sum1 = 0;for (int i = 0; i
2 Jun 2014 by kunal r somani
How to stop textbox textchanged event on button click event in asp.net
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,...
3 Dec 2013 by Leung Yat Chun
This sample bind a textblock width to it's parent's actual width.
8 Sep 2013 by loraloper_22
HelloMy problem is i want to take the amount of seconds from user, and my program will run for this amount of seconds. Now i am very new in coding i Know how to get a value from text box but i want to convert it in the seconds?. for example if user entered 3 i want it to be 3 seconds.English...
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...
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!
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...
3 Dec 2013 by Mahesh Alappuzha
i have a listview and i have a header template in that listview.In that header template i have a textbox.How can i set width and height of the textbox with respect to the header template's width and height??
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...
6 Nov 2014 by Makulais
I have a number of databound textboxs, a textbox variable, a measure button, and a save button on a form.the textbox variable allows auto incrementing of the textboxes after the measure button is pushed and a value is read. I use a doubleclick function on the textboxes also to allow the...
6 Nov 2014 by Makulais
Okay, gave up. No ideas so rather than writing to the textbox.text value, I wrote to the underlying class which bound the DataContext field using CallByName.Dim mystring As String mystring = measure_current_textbox.DataBindings.Item(0).BindingMemberInfo.BindingField.ToString ...
18 Dec 2013 by Manfred Rudolf Bihy
You probably were trying to use a font with proportional width[^].Here is a quote from Pavel's superb article:Restrictions"The component does not support center or right alignment and uses only monospaced[^] fonts. Also tabs are always replaced by spaces."Regards,— Manfred