textbox

Only allow numeric values in the textbox

ぐ巨炮叔叔 提交于 2019-12-19 06:01:19
问题 I want to make a TextBox control that only accepts numerical values. How can I do this in VB6? 回答1: In the text box text Change event, check if the entered value is a number. If it's not a number then set the old value back again. Dim textval As String Dim numval As String Private Sub TextBox1_Change() textval = TextBox1.Text If IsNumeric(textval) Then numval = textval Else TextBox1.Text = CStr(numval) End If End Sub 回答2: Right click on control box > component > Control -> Microsoft Masked

Focus on a TextBox in a DataTemplate

ぐ巨炮叔叔 提交于 2019-12-19 05:51:36
问题 I have DataTemplate containing a TextBox . I'm setting this template to a listbox item on a selection. I'm unable to set focus to textbox in the template. I tried to call MyTemplate.FindName, but it ends up with an Invalid Operation Exception: This operation is valid only on elements that have this template applied. How can I access it? 回答1: Since you know the name of the TextBox you want to focus, this becomes relatively easy. The idea is to get hold of the template as it's applied to the

Focus on a TextBox in a DataTemplate

跟風遠走 提交于 2019-12-19 05:51:06
问题 I have DataTemplate containing a TextBox . I'm setting this template to a listbox item on a selection. I'm unable to set focus to textbox in the template. I tried to call MyTemplate.FindName, but it ends up with an Invalid Operation Exception: This operation is valid only on elements that have this template applied. How can I access it? 回答1: Since you know the name of the TextBox you want to focus, this becomes relatively easy. The idea is to get hold of the template as it's applied to the

Autocomplete a textbox in c#

情到浓时终转凉″ 提交于 2019-12-19 04:21:41
问题 I'm trying to autocomplete a textbox. I'm retrieving values from Access Database. Just one field from a data table. If anyone can help me. 回答1: AutoCompleteStringCollection autoCompleteList = new AutoCompleteStringCollection(); /* copy your datacolumn in to autoCompleteList iteratively here */ txtBox.AutoCompleteMode = AutoCompleteMode.SuggestAppend; /* or just Suggest */ txtBox.AutoCompleteCustomSource = autoCompleteList; 回答2: You can use this control in your application if you using c#

textbox text color change

别说谁变了你拦得住时间么 提交于 2019-12-19 03:24:09
问题 I have textbox textbox1 and I want to change text color, but in the part of all text. For example from /* to */ like comments in visual studio? How I can do this? 回答1: Try this one: 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

Iterating through TextBoxes in asp.net - why is this not working?

删除回忆录丶 提交于 2019-12-19 02:31:23
问题 I have 2 methods I tried to iterate through all my textboxes in an asp.net page. The first is working, but the second one is not returning anything. Could someone please explain to me why the second one is not working? This works ok: List<string> list = new List<string>(); foreach (Control c in Page.Controls) { foreach (Control childc in c.Controls) { if (childc is TextBox) { list.Add(((TextBox)childc).Text); } } } and the "not working" code: List<string> list = new List<string>(); foreach

How to draw on top of a TextBox

大兔子大兔子 提交于 2019-12-18 18:23:45
问题 I have winform with a TextBox and I want to draw some GDI graphics on top of it. The text box does not have a Paint() event to hook to, so I assume it all has to happeen within the form's Paint event. As a test I am drawing a rectangle from the origin to a location within the text box with: private void FindForm_Paint(object sender, PaintEventArgs e) { using (Pen pen = new Pen(Color.Blue)) { e.Graphics.DrawRectangle(pen, 0, 0, point.X, point.Y); } } The problem is that when I run, the drawing

How do I configure a TextBox control to automatically resize itself vertically when text no longer fits on one line?

这一生的挚爱 提交于 2019-12-18 15:29:08
问题 How do I configure a TextBox control to automatically resize itself vertically when text no longer fits on one line? For example, in the following XAML: <DockPanel LastChildFill="True" Margin="0,0,0,0"> <Border Name="dataGridHeader" DataContext="{Binding Descriptor.Filter}" DockPanel.Dock="Top" BorderThickness="1" Style="{StaticResource ChamelionBorder}"> <Border Padding="5" BorderThickness="1,1,0,0" BorderBrush="{DynamicResource {ComponentResourceKey TypeInTargetAssembly=dc:NavigationPane,

Delete Lines From Beginning of Multiline Textbox in C#

99封情书 提交于 2019-12-18 15:11:12
问题 Is there a graceful way in C# to delete multiple lines of text from the beginning of a multiline textbox? I am using Microsoft Visual C# 2008 Express Edition. EDIT - Additional Details The multiline textbox in my application is disabled (i.e. it is only editable by the application itself), and every line is terminated with a "\r\n". 回答1: This is an incomplete question. So assuming you are using either TextBox or RichTextBox you can use the Lines property found inTextBoxBase. //get all the

C#:为详情查看界面设计的万用TextBox自定义控件

谁都会走 提交于 2019-12-18 15:05:27
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 在写C#的Winform页面的时候,经常会遇到下面的问题: 一个详情查看类的页面,控件是从相关录入页面复制来的。为了让控件不可编辑,经常要设置控件的Enabled属性为False,或ReadOnly属性为True(如TextBox)等。但这样做最大的坏处就是造成了界面风格的不统一,如果字体、字号、风格、颜色都不统一,界面就会显得非常难看。 为此我设计了一个自定义控件,继承自TextBox,目的是让界面风格统一,原型效果如下: (以上两张原型图使用Balsamiq绘制) 我设计的控件MultiFuncViewTextBox代码如下: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Windows.Forms; namespace CustuomControl { public class MultiFuncViewTextBox : TextBox { public MultiFuncViewTextBox() { this