textbox

How to know if the text in a textbox is selected?

房东的猫 提交于 2019-12-17 22:32:39
问题 I have text boxes <input type='text'> that only allow numeric characters and wont let the user enter a dot (.) more than once. Problem is, if the text in the text box is selected, the user intends to overwrite the contents with a dot, hence making it allowed! The question is, how can you tell in javascript whether the text in that text box is selected or not. Thanks 回答1: The following will tell you whether or not all of the text is selected within a text input in all major browsers. Example:

How can I set Regular Expression on TextBox?

空扰寡人 提交于 2019-12-17 20:23:30
问题 How can I set a regular expression on WPF TextBox? I want the textbox to accept input in some predefined format. Is it possible? 回答1: You have several options: You can create a ValidationRule subclass (see below) and add it to your Binding's Validators property You can set a ValidationCallback on your bound property, throw an exception if the value is wrong, and use this technique for easily showing validation errors You can create an attached property that registers an event handler for the

Keep text selection when focus changes

时光毁灭记忆、已成空白 提交于 2019-12-17 19:52:37
问题 I have a normal textbox, and a lightbox with a text input. I want to keep the user's selection in the textbox, even when the user focuses on the lightbox's text input. Select text in normal textbox Toggle lightbox Focus on lightbox input At step 3., the user's text selection is discarded. How can this be prevented? See Google docs link insertion lightbox for example. Thanks :) Update Ok, so Google docs uses an iframe for the blank page section, which is how they are handling the multiple

How to change the highlighted text's Foreground color for a WPF TextBox?

扶醉桌前 提交于 2019-12-17 19:45:01
问题 I am working on an application having both WinForms and WPF controls; In case of WinForms TextBox selected text Background color comes Blue and White respectively whereas in WPF TextBox it is LightBlue and Black. As answered in these questions I can use SelectionBrush property(WPF 4) to change the selected text's background, but How can I change the foreground color of selected text? How can you change the highlighted text color for a WPF TextBox? How can I change the highlighted text color

Why can't I access a TextBox by Name with FindName()?

亡梦爱人 提交于 2019-12-17 19:23:49
问题 Why does FindName() return null in the following example? XAML: <Window x:Class="TestDynamicTextBox343.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1" Height="300" Width="300"> <StackPanel> <Border > <DockPanel x:Name="FormBase" LastChildFill="True"> </DockPanel> </Border> <Button Content="Save" Click="Button_Click"/> </StackPanel> </Window> Code Behind: using System; using System.Windows; using

How to validate html textbox not to allow special characters and space?

我们两清 提交于 2019-12-17 18:59:10
问题 This is my html: <input type="text" name="folderName"> Here, I want to validate the textbox value by not allowing to key in special characters and space. But it should allow underscore. How to validate this textbox? 回答1: You may try to use this function: <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title></title> <script type="text/javascript"> function blockSpecialChar(e){ var k; document.all ? k = e.keyCode : k = e.which; return ((k > 64 && k < 91) || (k >

How can I define how many spaces a TAB jumps in a XAML TextBox?

馋奶兔 提交于 2019-12-17 18:57:31
问题 When the user presses a tab in this textbox, the cursor jumps an equivalent of 8 spaces . How can I change it so it jumps only 4 or 2? <TextBox Width="200" Height="200" Margin="0 0 10 0" AcceptsReturn="True" AcceptsTab="True" Text="{Binding OutlineText}"/> 回答1: You can create your own TextBox control to give the desired affect: public class MyTextBox : TextBox { public MyTextBox() { //Defaults to 4 TabSize = 4; } public int TabSize { get; set; } protected override void OnPreviewKeyDown

How do I remove all default Webkit search field styling?

会有一股神秘感。 提交于 2019-12-17 18:22:55
问题 By default, <input type="search" /> renders like a "native" search field on Mac OS X (rounded corners, clear button, etc.). I want to completely remove this custom styling so that the input looks identical to an equivalent text input ( <input type="text" /> ), but while keeping the input type set to search . I've tried -webkit-appearance: none; , which gets it very close...but there's something funny going on with margins/padding that I can't seem to override, which causes the width of the

How do I set a textbox's text to bold at run time?

孤者浪人 提交于 2019-12-17 18:01:04
问题 I'm using Windows forms and I have a textbox which I would occassionally like to make the text bold if it is a certain value. How do I change the font characteristics at run time? I see that there is a property called textbox1.Font.Bold but this is a Get only property. 回答1: The bold property of the font itself is read only, but the actual font property of the text box is not. You can change the font of the textbox to bold as follows: textBox1.Font = new Font(textBox1.Font, FontStyle.Bold);

C# Numeric Only TextBox Control [duplicate]

好久不见. 提交于 2019-12-17 16:44:28
问题 This question already has answers here : numeric-only textbox as a control in Visual Studio toolbox (4 answers) Closed 6 years ago . I am using C#.NET 3.5, and I have a problem in my project. In C# Windows Application, I want to make a textbox to accept only numbers. If user try to enter characters message should be appear like "please enter numbers only", and in another textbox it has to accept valid email id message should appear when it is invalid. It has to show invalid user id. 回答1: I