Here are some frequently asked questions about Windows Forms and their answers.
Browse by Tags
All Tags » TextBox (RSS)
-
|
When I set a TextBox to Readonly or set Enabled to false, the text color is gray. How can I force it to be the color specified in the ForeColor property of the TextBox? You can download a VB.NET sample. Override the OnPaint event of the TextBox. For example...
|
-
|
Say you have a Parent table related to a Child table related to a GrandChildTable, and you want to bind a TextBox to a column in the GrandChild table. To do this you have to have nested relations defined, and you use this nesting to create the DataMember...
|
-
|
You can handle the textbox's KeyPress event and if you want the keypress to be an overwrite, just select the current character so the keypress will replace it. The attached sample has a derived textbox that has an OverWrite property and a right-click...
|
-
|
Each type has a ToString method that can be used to perform formatting. Also, you can use the String.Format method to format things as well. To format dates, use the ToString member of DateTime. You may want to use the InvariantInfo setting to get culture...
|
-
|
You can set the ContextMenu property of the TextBox to a dummy, empty ContextMenu instance. Contributed from George Shepherd's Windows Forms FAQ
|
-
|
Add a handler for your TextBox's KeyDown event. (This assumes you set the AcceptsReturn property to False). Then in your KeyDown eventhandler, have code such as: [C#] if (e.KeyCode = Keys.Enter) SendKeys.Send("{TAB}"); [Visual Basic] If...
|
-
|
There are several of ways to do this. Here are a few: 1) Insert a carriage return, linefeed combination, "\r\n", between lines of text. textBox1.Text = "This is line 1.\r\nThis is line 2"; 2) Use the Environment.NewLine property. This...
|
-
|
You can handle the textbox's KeyPress event and if the char passed in is not acceptable, mark the events argument as showing the character has been handled. Below is a derived TextBox that only accepts digits (and control characters such as backspace...
|
-
|
You can do this by deriving the TextBox, overriding the WndProc method and ignoring these mouse down messages. [C#] public class CustomTextBox : TextBox { protected override void WndProc( ref Message m ) { // WM_NCLBUTTONDOWN WM_LBUTTONDOWN if ( !( ReadOnly...
|
-
|
Set the TextBox.PasswordChar property. textBox1.PasswordChar = '\u25CF'; Contributed from George Shepherd's Windows Forms FAQ
|
-
|
I have a delete key shortcut for my main menu. When my textbox is being edited, pressing delete activates this menu items instead of being processed by the TextBox. How can I get my TextBox to handle this delete? Subclass the TextBox and override its...
|
-
|
Use the CharacterCasing property of the TextBox. textBox1.CharacterCasing = CharacterCasing.Upper; textBox2.CharacterCasing = CharacterCasing.Lower; Contributed from George Shepherd's Windows Forms FAQ
|
-
|
There is a protected SendMessage call you can use for this purpose, so you have to derive from TextBox. public class CustomTextBox : TextBox { private const int EM_XXXX = 0x1234; public int LineIndex { get { return base.SendMessage( EM_XXXX, 0, 0 ); ...
|
-
|
You use the Frameworks OpenFileDialog to implement this functionailty. using System.Text; using System.IO; private void button1_Click( object sender, EventArgs e ) { OpenFileDialog dlg = new OpenFileDialog(); dlg.Title = "Open text file" ; dlg...
|
-
|
How do I prevent the user from being able to paste from the clipboard into a TextBox, e.g., through Ctrl+V and the context menu? First set the ContextMenu property of the TextBox to a dummy, empty ContextMenu instance. This will prevent the default context...
|
-
|
You can prevent the beep when the enter key is pressed in a TextBox by deriving the TextBox and overriding OnKeyPress. [C#] public class CustomTextBox : TextBox { protected override void OnKeyPress( KeyPressEventArgs e ) { if ( e.KeyChar == (char) 13...
|