textbox

How to focus a datatemplated TextBox in the first element of an ItemsControl in a Window, when the Window is opened? (C#, WPF)

六月ゝ 毕业季﹏ 提交于 2020-01-02 06:23:20
问题 When the user clicks a button in the application, a window opens up. I want the TextBox belonging to the first item in the ItemsControl to be focused, so that the user can start typing as soon as the Window is opened, without needing to manually select the TextBox. How can this be done? For simplicity, we can say that the Window looks approximately like this: <Window> <Grid> <ItemsControl ItemsSource="{Binding MyItems}"> <DataTemplate> <Grid> <StackPanel> <StackPanel> <customControls

Masked TextBox with decimal numbers

寵の児 提交于 2020-01-01 15:07:06
问题 In my window application I need masked textbox which accept real decmal numbers. eg. 1) 1.56 2) 22.34 3) 123.34 4) 12312.34 This all value should be valid. Can anyone tell me how can I do this? And ya if anyone have better solution for real decimal numbers, instead of this masked TextBox than I love to see it. Thanks... 回答1: Use a custom control like this one (modify it to fulfill your needs): using System; using System.ComponentModel; using System.Text; using System.Windows.Forms; using

Remove focus on first textbox

会有一股神秘感。 提交于 2020-01-01 09:08:25
问题 In our Windows Store app we have a textbox, and when the application starts this textbox always get focus. In a desktop scenario that's no problem, but on a tablet device this focus will directly open the onscreen keyboard which is not a scenario that we want. We tried to set the focus on another control programmatic with the .Focus(FocusState) method, but somehow the focus is set back to the textbox. We have both set the focus in the LoadState or the OnNavigatedTo method. Only when we have

how to insert image in a textbox

让人想犯罪 __ 提交于 2020-01-01 08:33:18
问题 Is there a way to insert an image in a textbox? I'm working on a chat application. And I want to change the values ":)", ":(" etc. with icon images. But I couldn't find that how can I insert image in a textbox? Thanks. 回答1: Use RichTextBox Insert Plain Text and Images into RichTextBox at Runtime Inserting images into a RichTextBox control (the OLE way) 回答2: If you are using RichTextBox for chat than look at Paste method Bitmap bitmap = new Bitmap(); Clipboard.SetDataObject(bitmap );

Win Forms text box masks

佐手、 提交于 2020-01-01 05:27:26
问题 How can I put mask on win form text box so that it allows only numbers? And how it works for another masks data, phone zip etc. I am using Visual Studio 2008 C# Thanks. 回答1: Do you want to prevent input that isn't allowed or validate the input before it is possible to proceed? The former could confuse users when they press keys but nothing happens. It is usually better to show their keypresses but display a warning that the input is currently invalid. It's probably also quite complicated to

Limiting Characters per Line in a Textarea

我的未来我决定 提交于 2020-01-01 03:17:13
问题 I have been searching all weekend for the solution to this quandry and have yet to find a solution that works correctly. What I am trying to acchieve is to limit the number of charatcers per line in a textarea - not limiting them identically, but a different number of characters per line of my choosing. For Example: I want to have only 4 lines in my textarea Line 1,2 and 3 will be limited to 24 characters Line 4 will have an unlimited number of characters Is this possible with a textarea, or

Get user input from a textbox in a WPF application

微笑、不失礼 提交于 2020-01-01 02:33:52
问题 I am trying to get user input from the textbox in a WPF application I am building. The user will enter a numeric value and I would like to store it in a variable. I am just starting on C#. How can I do it? Currently I am opening the textbox and letting the user enter the value. After that the user has to press a button upon which the text from textbox is stored in a variable. private void TextBox_TextChanged(object sender, TextChangedEventArgs e) { } private void Button_Click(object sender,

Cursor Focus on Textbox in WPF/C#

 ̄綄美尐妖づ 提交于 2019-12-31 08:29:59
问题 I am currently in the process of creating a Onscreen keyboard. I am handling the button click using routedcommands. The issue is that when i click on the button in keyboard panel the focus shifts to the button rather than on the Textbox. The requirement states that a cursor should always appear in the text box to indicate the position where the next character will be inserted. Is there a way i can keep focus on the textbox while button is clicked. 回答1: To set logical focus to an input control

How to capture the value of a textbox from an OnChange event

旧城冷巷雨未停 提交于 2019-12-31 07:41:38
问题 In my C# MVC app, I have a series of textboxes that are generated as such... @foreach (object item in items) { @Html.TextBox(....) } The rendered result is a series of text boxes that look like this.... <input class="item-quantities valid" data-bomid="1939" data-rid="2054" id="AddedItemIDs_1939_" name="AddedItemIDs[1939]" onchange="ChangeItemQuantity(156,78)" onkeypress="return isNumberKey(event)" type="text" value="7" aria-invalid="false"> <input class="item-quantities valid" data-bomid=

How to capture the value of a textbox from an OnChange event

末鹿安然 提交于 2019-12-31 07:41:32
问题 In my C# MVC app, I have a series of textboxes that are generated as such... @foreach (object item in items) { @Html.TextBox(....) } The rendered result is a series of text boxes that look like this.... <input class="item-quantities valid" data-bomid="1939" data-rid="2054" id="AddedItemIDs_1939_" name="AddedItemIDs[1939]" onchange="ChangeItemQuantity(156,78)" onkeypress="return isNumberKey(event)" type="text" value="7" aria-invalid="false"> <input class="item-quantities valid" data-bomid=