Tag: 文本框

在WPF中动态添加文本框

我正在动态创建一个文本框。 我的网格中有2列。 如果另一个文本框值=“茶”,我想在行中添加新文本框。 我想创建新的文本框到相应的行文本框值更改。 我无法使用Tag在此处获取所选行。 因为我已经出于某种目的使用了Tag。 我对Tag不太了解。 无论如何,如何将新文本框添加到column1到相应的行? 这是我的代码.. public int count = 1; public TextBox txt1; private void btn_addnew_Click(object sender, RoutedEventArgs e) { //Creating Rows.. RowDefinition row0 = new RowDefinition(); row0.Height = new GridLength(40); grid1.RowDefinitions.Add(row0); //Creating columns.. ColumnDefinition col0 = new ColumnDefinition(); ColumnDefinition col1 = new ColumnDefinition(); col0.Width = new GridLength(150); col1.Width = new […]

将填充设置为动态文本框C#asp.net

这是我用C#代码创建文本框的代码。 for (int x = 0; x < 30; x++) { TextBox txt = new TextBox(); txt.ID = "txt – " + x.ToString(); data.Controls.Add(txt); data.Controls.Add(new LiteralControl("”)); } 所有文本框都会互相粘贴..我想我可以在循环中添加填充顶部吗? 我该怎么办? 感谢您的帮助,您的建议和评论是适用的。 这是通过使用C#创建的 我希望得到像这样的空间。 请忽略下拉框..它只是一个例子。

c# – 文本框是否有字符限制?

可能重复: TextBox C#中的Max Char? MaxLenght设置为0的c#winform应用程序中的文本框中是否存在已知字符限制? 谢谢,汉斯

从Datagrid中选择Datagrid的行数据

我想从连接到Entity Framework数据库的数据网格中获取每列的数据。 我想将它们转换为各自的Textboxes,但我似乎无法从datagrid中绘制数据。 这是我最初使用的代码( 在SO上看到它 ): private void DataGridCamiao_SelectionChanged(object sender, SelectionChangedEventArgs e) { DataGrid DataGridCamiao = sender as DataGrid; DataRowView row = (DataRowView)DataGridCamiao.SelectedItems[0]; TextBoxMarca.Text = row[“Marca”].ToString(); } 虽然运行后它给我一个错误: System.InvalidCastException:无法将(我的自定义类型)关联到DataRowView 我已经读过它并且我已经将它改为我的自定义类型,它说它不能被索引并且不能运行,这基本上让我难以接受,因为我尝试了其他方法。 我想要了解一下我在这里做错了什么,也许是实现同一目标的不同方法,我还要感谢任何想帮助我的人。

使用换行符将文本转储到文件

private void btnDump_Click(object sender, EventArgs e) { using (StreamWriter sw = new StreamWriter(“E:\\TestFile.txt”)) { // Add some text to the file. sw.WriteLine(txtChange.Text); } } 这会将txtChange的文本转储到文本文件中。 txtChange是一个富文本框,其中包含换行符(换行符)。 当用户单击“转储”按钮时,所有文本都被转储但不在新行上。 例如txtChange看起来像 1 2 3 4 转储文本看起来像1234 如何格式化文本的转储以使文本在新行上?

如何在不禁用它的情况下使WinForms TextBox中的文本无法选择?

是否可以在不禁用TextBox的情况下使TextBox中的文本无法选择? 这是一个RichTextBox,我需要它的格式和选择function。 我无法禁用它,因为我想处理MouseMove和MouseDown事件。 到目前为止,我已经考虑过禁用“文本”框并在其上面放置一个面板,将面板的事件委托给文本框处理程序,但是我无法使面板透明,因此它隐藏了文本框。 谢谢。

如何在代码后面的占位符中获取文本框值?

我创建了一些文本框,我希望动态获取它们的值。 简而言之,ı解释我的页面: 我有dropDown列表的编号为1到15.当用户选择编号时,我创建了文本框作为选中的编号。 例如; 用户选择3,我创建3个文本框,用户在文本框中写入内容。 这是我的代码:aspx Side: 代码背后: protected void ddlUserSelected_SelectedIndexChanged(object sender, EventArgs e) { for (int a = 1; a <= int.Parse(ddlUserSelected.SelectedItem.Text); a++) { TextBox txtDate = new TextBox(); Label lbl = new Label(); lbl.Text = "”; txtDate .Width = 70; txtDate .CssClass = “tbl”; txtDate .ID = “txtDate” + a; PlaceHolder1.Controls.Add(txtDate); PlaceHolder1.Controls.Add(lbl); } […]

在单独的表单上写入文本框(C#)

假设我有两种forms:Form1和Form2。 Form2有一个名为text1的文本控件 在VB6中,我可以写入Form 2的文本框 使用以下方法控制Form1:Form2.Text1.text =“这里有些文字” 如何在C#中完成这项工作? 我已经尝试了一切! 我试过的: Form2 Frm2 = new Form2(); Frm2.show(); Frm2.Activate(); // Trying everything to make sure it sees the form (it does). Frm2.Text1 (Doesn’t find the control)… 回答: 我最终在Form2中创建了一个公共例程,然后从form1调用此例程。 在Form2的这个公共例程中,我将调用文本框!

如何绑定到CaretIndex又名文本框的光标位置

嗨,我正在尝试绑定到不是DependencyProperty的TextBox.CaretIndex属性,所以我创建了一个Behavior ,但它没有按预期工作。 期望(专注时) 默认= 0 如果我在视图中更改了值,它应该更改viewmodel中的值 如果我更改了viewmodel中的值,它应该更改我视图中的值 目前的行为 当窗口打开时,viewmodel值被调用 代码隐藏 public class TextBoxBehavior : DependencyObject { public static readonly DependencyProperty CursorPositionProperty = DependencyProperty.Register( “CursorPosition”, typeof(int), typeof(TextBoxBehavior), new FrameworkPropertyMetadata( default(int), new PropertyChangedCallback(CursorPositionChanged))); public static void SetCursorPosition(DependencyObject dependencyObject, int i) { // breakpoint get never called dependencyObject.SetValue(CursorPositionProperty, i); } public static int GetCursorPosition(DependencyObject dependencyObject) { // breakpoint […]

仅允许TextBox中的整数

我在检查文本框时遇到问题,并确保其中只有整数。 到目前为止,我能够确认文本框中有文本,但检查它们是否为整数是不起作用的。 这是迄今为止我的代码。 if (textBox1.Text.Length == 0) { errorProvider1.SetError(textBox1, “need Cost of Disks”); return; } if (textBox2.Text.Length == 0) { errorProvider2.SetError(textBox2, “need Total disks in package”); return; } if (textBox3.Text.Length == 0) { errorProvider3.SetError(textBox3, “need the Gigabyte per disk”); return; } try { Double[] myValues = new Double[3]; myValues[0] = Double.Parse(textBox1.Text); myValues[1] = Double.Parse(textBox2.Text); myValues[2] […]