HTML Text Input: Avoid submit when enter is pressed

Using jQuery: <script> $(‘#first_page’).keypress(function(e) { if (e.keyCode == ’13’) { e.preventDefault(); //your code here } });​ </script> using javascript <input type=”text” id=”first_page” onPaste=”” onkeydown=”if (event.keyCode == 13) { alert(‘enter’);return false;}” />

How to disable cursor in textbox?

In C#, you can use the following read-only textbox: public class ReadOnlyTextBox : TextBox { [DllImport(“user32.dll”)] static extern bool HideCaret(IntPtr hWnd); public ReadOnlyTextBox() { this.ReadOnly = true; this.BackColor = Color.White; this.GotFocus += TextBoxGotFocus; this.Cursor = Cursors.Arrow; // mouse cursor like in other controls } private void TextBoxGotFocus(object sender, EventArgs args) { HideCaret(this.Handle); } }

Set the focus on a TextBox in WPF XAML

You can use the FocusManager.FocusedElement attached property for this purpose. Here’s a piece of code that set the focus to TxtB by default. <StackPanel Orientation=”Vertical” FocusManager.FocusedElement=”{Binding ElementName=TxtB}”> <TextBox x:Name=”TxtA” Text=”A” /> <TextBox x:Name=”TxtB” Text=”B” /> </StackPanel> You can also use TxtB.Focus() in your code-behind if you don’t want to do this in XAML.

Change color and font for some part of text in WPF C#

If you just want to do some quick coloring, the simplest solution may be to use the end of the RTB content as a Range and apply formatting to it. For example: TextRange rangeOfText1 = new TextRange(richTextBox.Document.ContentEnd, richTextBox.Document.ContentEnd); rangeOfText1.Text = “Text1 “; rangeOfText1.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Blue); rangeOfText1.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Bold); TextRange rangeOfWord = new TextRange(richTextBox.Document.ContentEnd, richTextBox.Document.ContentEnd); rangeOfWord.Text = “word … Read more

Capture mouse clicks on WPF TextBox

TextBox Class TextBox has built-in handling for the bubbling MouseUp and MouseDown events. Consequently, custom event handlers that listen for MouseUp or MouseDown events from a TextBox will not be called. If you need to respond to these events, listen for the tunneling PreviewMouseUp and PreviewMouseDown events instead, or register the handlers with the HandledEventsToo … Read more

Change the borderColor of the TextBox

You can handle WM_NCPAINT message of TextBox and draw a border on the non-client area of control if the control has focus. You can use any color to draw border: using System; using System.Drawing; using System.Runtime.InteropServices; using System.Windows.Forms; public class ExTextBox : TextBox { [DllImport(“user32”)] private static extern IntPtr GetWindowDC(IntPtr hwnd); private const int WM_NCPAINT … Read more

tech