textbox 相关问题

文本框是一个图形用户界面元素,它允许简单的输入文本,通常只有一行文本。

如何在自定义 Tkinter 中对齐这些数字

每当我运行我的代码时,一切都排列整齐 输出(在 vscode / 终端中): 预览 1 2 3 4 5 6 7 8 9 R H E 太空人队 0 0 0 0 幼崽 0 0 0 0 布...

回答 1 投票 0

在c#文本框中,我如何知道我按Enter键的确切索引位置?

在c#文本框中,当按下回车键时,如何获取按下它的索引? 例如,我有一个名为 txtDesc 的文本框,并且 txtDesc 当前包含短语 “敏捷的棕色狐狸j...

回答 1 投票 0

限制表单输入文本字段中允许的字符数

如何限制或限制用户在文本框中最多只能输入五个字符? 下面是我的表单的输入字段: 如何限制或限制用户在文本框中最多只能输入五个字符? 下面是我表单的一部分的输入字段: <input type="text" id="sessionNo" name="sessionNum" /> 是否使用了 maxSize 之类的东西? 最大长度: 接受输入的最大字符数。这可以大于 SIZE 指定的值,在这种情况下,该字段 将适当滚动。默认无限制。 <input type="text" maxlength="2" id="sessionNo" name="sessionNum" onkeypress="return isNumberKey(event)" /> 但是,这可能会或可能不会受到您的处理程序的影响。您可能还需要使用或添加另一个处理程序函数来测试长度。 最简单的方法: maxlength="5" 所以..将此属性添加到您的控件中: <input type="text" id="sessionNo" name="sessionNum" onkeypress="return isNumberKey(event)" maxlength="5" /> 让事情变得更简单 <input type="text" maxlength="3" /> 并使用警报来显示已使用最大字符数。 将以下内容添加到标题中: <script language="javascript" type="text/javascript"> function limitText(limitField, limitNum) { if (limitField.value.length > limitNum) { limitField.value = limitField.value.substring(0, limitNum); } } </script> <input type="text" id="sessionNo" name="sessionNum" onKeyDown="limitText(this,5);" onKeyUp="limitText(this,5);"" /> 根据 w3c,MAXLENGTH 属性的默认值是无限数量。因此,如果您没有指定最大值,用户可以多次剪切和粘贴圣经并将其粘贴在您的表单中。 即使您确实将 MAXLENGTH 指定为合理的数字,请确保在处理之前仔细检查服务器上提交的数据的长度(使用 php 或 asp 等),因为无论如何,绕过基本的 MAXLENGTH 限制都很容易 <input type="text" maxlength="5"> 输入中最多可以输入 5 个字母。 最大长度 接受输入的最大字符数。 maxlength 属性指定元素中允许的最大字符数。 Maxlength W3 学校 <form action="/action_page.php"> Username: <input type="text" name="usrname" maxlength="5"><br> <input type="submit" value="Submit"> </form> 我总是这样做: $(document).ready(function() { var maxChars = $("#sessionNum"); var max_length = maxChars.attr('maxlength'); if (max_length > 0) { maxChars.on('keyup', function(e) { length = new Number(maxChars.val().length); counter = max_length - length; $("#sessionNum_counter").text(counter); }); } }); 输入: <input name="sessionNum" id="sessionNum" maxlength="5" type="text"> Number of chars: <span id="sessionNum_counter">5</span> 您可以使用 <input type = "text" maxlength="9"> 或 <input type = "number" maxlength="9"> 表示数字 或者 <input type = "email" maxlength="9"> 用于电子邮件 验证将会显示 <input type="number" id="xxx" name="xxx" oninput="maxLengthCheck(this)" maxlength="10"> function maxLengthCheck(object) { if (object.value.length > object.maxLength) object.value = object.value.slice(0, object.maxLength) } 以下代码包含了一个计数... var count = 1; do { function count_down(obj, count){ let element = document.getElementById('count'+ count); element.innerHTML = 80 - obj.value.length; if(80 - obj.value.length < 5){ element.style.color = "firebrick"; }else{ element.style.color = "#333"; } } count++; } while (count < 20); .text-input { padding: 8px 16px; width: 50%; margin-bottom: 5px; margin-top: 10px; font-size: 20px; font-weight: 700; font-family: Raleway; border: 1px solid dodgerblue; } <p><input placeholder="Title" id="bike-input-title" onkeyup="count_down(this, 3)" maxlength="80" class="text-input" name="bikeTitle" ></p> <span id="count3" style="float: right; font-family: Raleway; font-size:20px; font-weight:600; margin-top:-5px;">80</span><br> 晚了,但如果你想要一个完整的证明方法来限制数字或字母,这只是 javascript 并且还限制字符长度: 更改.slice后的第二个数字以设置字符数。这对我来说效果好多了maxlength。 只是数字: oninput="this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*)\./g, '$1').slice(0, 11); 只是字母: oninput="this.value=this.value.replace(/[^A-Za-z\s]/g,'').slice(0,20);" 完整示例: <input type="text" name="MobileNumber" id="MobileNumber" oninput="this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*)\./g, '$1').slice(0, 11);"/> 不要为旧的解决方案而烦恼。 这就是您需要的: function isNumberKey(evt) { var charCode = (evt.which) ? evt.which : evt.keyCode; // Allowing only numbers and specific keys (backspace, delete, arrow keys) if (charCode > 31 && (charCode < 48 || charCode > 57)) { return false; } // Checking maximum character limit if (evt.target.value.length >= 11) { return false; } return true; } <input type="text" placeholder="ID Number" maxlength="11" onkeypress="return isNumberKey(event)"> 使用 maxlenght="字符数" <input type="text" id="sessionNo" name="sessionNum" maxlenght="7" /> <input type="text" name="MobileNumber" id="MobileNumber" maxlength="10" onkeypress="checkNumber(event);" placeholder="MobileNumber"> <script> function checkNumber(key) { console.log(key); var inputNumber = document.querySelector("#MobileNumber").value; if(key.key >= 0 && key.key <= 9) { inputNumber += key.key; } else { key.preventDefault(); } } </script>

回答 15 投票 0

是否可以将 MahApps 的 TextBoxHelper 应用于 ScrollViewer?

我正在构建一个 WPF 应用程序,其中有一个 TextBox。要对其应用圆角,在这里我读到我需要使用边框内的 ScrollViewer 创建特定的样式。到目前为止一切顺利,b...

回答 1 投票 0

有没有办法加快winforms文本框中显示大量文本的速度?

有没有办法加快winforms文本框中显示大量文本的速度? 我的应用程序读取一个文件(最大可达 20MB),然后将其显示到文本框 (TextBoxX.Text = fileText;)。 ...

回答 9 投票 0

为什么无法在文本框中插入小数?

这是我的视图模型: 公共类 ViewModelData :INotifyPropertyChanged { 私有小数?我的价值; 公共十进制?我的价值 { 获取 { 返回 myValue; } 放 { ...

回答 1 投票 0

用于在 Excel 工作簿中取消形状(特别是文本框)分组的宏

我有一个宏,用于翻译 Excel 工作簿中文本框形状内的文本,但如果任何文本框分组在任何工作表中,则该宏会失败。有没有一种简单的方法可以取消

回答 1 投票 0

Wpf 问题:带有样式的文本框不会在文本框中获取值。 (它总是空字符串)

我是wpf编程新手。当我点击按钮时。它应该向我显示文本框中的消息。但是,它仅显示一个空字符串。我的文本框使用名为“

回答 1 投票 0

如何在tkinter中制作闪烁的文本框?

所以我的计算课正在用Python制作一张圣诞卡,其中一个位将有一个带有消息的文本框,但如何使背景从绿色和红色交替? 如果

回答 2 投票 0

为什么我的自动完成文本框事件 TextChanged 在 VB.NET 中运行得这么慢

我正在尝试使用文本框事件 TextChanged 自动完成,但使用 VB.NET 运行速度很慢。 虽然只有6条记录,我的代码有问题吗,请指导我。 我附上了一份gi...

回答 1 投票 0

如何用VB.NET改变文本框类中图标的位置

我正在尝试使用 VB.NET 更改文本框类中图标的位置 也许我的代码不合适,请指导我。 请指导我。 谢谢 下面的代码在vb.net中 公开课搜索文本...

回答 1 投票 0

如何在 HTML/Javascript 中制作自定义的项目符号文本框?

我正在尝试用 HTML/Javascript 制作一个自定义文本框,并满足以下要求: 文本框的初始状态将是单个项目符号点,如下所示: 每行必须以项目符号开头...

回答 1 投票 0

使用 VBA(Excel 宏)将文本框内容从西班牙语翻译和替换为英语

我希望尽可能高效地翻译 Excel 工作簿文件,其中包含单元格中的某些内容和放置在每个工作表中的文本框对象中的其他内容。我找到了一些很好的例子...

回答 1 投票 0

使用python在excel上插入Texbox

我需要使用python在Excel工作表中插入一个文本框,我已经尝试过openpyxl,更具体地说是openpyxl.drawing.shape,xlsxwriter等,但它不起作用。 从 openpyxl 导入 Workboo...

回答 1 投票 0

如何编写文本框中鼠标滚动时发生的事件?

我想更改鼠标滚动时文本框的数量。我有一个滚动文本框,但我不想使用它。有与此相关的活动吗? 我应该编写一个文本框事件吗?如果是的话,如何...

回答 4 投票 0

如何从 WinForms 中的 TextBox 中移除焦点?

我需要从几个文本框中删除焦点。我尝试使用: textBox1.Focused = false; 它的 ReadOnly 属性值为 true。 然后我尝试将焦点设置在表单上,以便将其删除......

回答 21 投票 0

WPF圆角文本框

我不懂WPF,现在正在学习。我正在寻找 WPF 中的圆角 TextBox。所以我搜索了Google并找到了一段XAML: 我不了解WPF,现在正在学习。我在 WPF 中寻找圆角TextBox。所以我在Google上搜索并找到了一块XAML: <!–Rounded Corner TextBoxes–> <ControlTemplate x:Key=”RoundTxtBoxBaseControlTemplate” TargetType=”{x:Type Control}”> <Border Background=”{TemplateBinding Background}” x:Name=”Bd” BorderBrush=”{TemplateBinding BorderBrush}” BorderThickness=”{TemplateBinding BorderThickness}” CornerRadius=”6″> <ScrollViewer x:Name=”PART_ContentHost”/> </Border> <ControlTemplate.Triggers> <Trigger Property=”IsEnabled” Value=”False”> <Setter Property=”Background” Value=”{DynamicResource {x:Static SystemColors.ControlBrushKey}}” TargetName=”Bd”/> <Setter Property=”Foreground” Value=”{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}”/> </Trigger> <Trigger Property=”Width” Value=”Auto”> <Setter Property=”MinWidth” Value=”100″/> </Trigger> <Trigger Property=”Height” Value=”Auto”> <Setter Property=”MinHeight” Value=”20″/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> 所以请告诉我将其粘贴到哪里XAML。请详细帮助我。我是 WPF 的初学者。 @Smolla 在对 @Daniel Casserly 的回答的评论中给出了更好的答案: <TextBox Text="TextBox with CornerRadius"> <TextBox.Resources> <Style TargetType="{x:Type Border}"> <Setter Property="CornerRadius" Value="3"/> </Style> </TextBox.Resources> </TextBox> 如果您希望 TextBox 和 ListBox 的所有边框都有圆角,请将样式放入您的 Window 或 App 中<Resources>。 在 WPF 中,您可以修改或重新创建控件的外观。因此,如果您的示例他们所做的是通过修改现有 ControlTemplate 的 TextBox 来更改文本框的外观。因此,要查看和探索这段代码,只需使用下面的代码 <Window x:Class="WpfApplication4.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"> <Window.Resources> <ControlTemplate x:Key="TextBoxBaseControlTemplate" TargetType="{x:Type TextBoxBase}"> <Border Background="{TemplateBinding Background}" x:Name="Bd" BorderBrush="Black" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="10"> <ScrollViewer x:Name="PART_ContentHost"/> </Border> <ControlTemplate.Triggers> <Trigger Property="IsEnabled" Value="False"> <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" TargetName="Bd"/> <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/> </Trigger> <Trigger Property="Width" Value="Auto"> <Setter Property="MinWidth" Value="100"/> </Trigger> <Trigger Property="Height" Value="Auto"> <Setter Property="MinHeight" Value="20"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Window.Resources> <Grid> <TextBox Template="{StaticResource TextBoxBaseControlTemplate}" Height="25" Margin="5"></TextBox> </Grid> 因此,我们在窗口的资源部分声明了一个静态资源,并在 Template 的 TextBox 属性中使用了 Resource TextBoxBaseControlTemplate 作为 Template="{StaticResource TextBoxBaseControlTemplate}" 。 自定义 WPF 控件的模板只需参考此文档即可获得想法 http://msdn.microsoft.com/en-us/magazine/cc163497.aspx 您可以使用以下样式将所有文本框更改为圆角: <Style TargetType="{x:Type TextBox}"> <Style.Resources> <Style TargetType="{x:Type Border}"> <Setter Property="CornerRadius" Value="3" /> </Style> </Style.Resources> </Style> 受到以下答案的启发:https://stackoverflow.com/a/13858357/3387453 只需将文本框的 BorderThickness 设置为零即可在文本框周围添加边框。 <Border BorderThickness="1" BorderBrush="Black" CornerRadius="10" Padding="2" HorizontalAlignment="Center" VerticalAlignment="Center"> <TextBox Text="Hello ! " BorderThickness="0"/> </Border> 输出如图所示! 这个问题在 msdn 上得到了很好的讨论: http://social.msdn.microsoft.com/forums/en-US/wpf/thread/549775ed-1c2a-4911-9078-d9c724294fb3/ 尝试那里的解决方案,它们非常详细,并且足够详细,让您知道将代码放在哪里。 您可以使用附加属性来设置TextBox边框半径(同样适用于按钮)。 为附加属性创建类 public class CornerRadiusSetter { public static CornerRadius GetCornerRadius(DependencyObject obj) => (CornerRadius)obj.GetValue(CornerRadiusProperty); public static void SetCornerRadius(DependencyObject obj, CornerRadius value) => obj.SetValue(CornerRadiusProperty, value); public static readonly DependencyProperty CornerRadiusProperty = DependencyProperty.RegisterAttached(nameof(Border.CornerRadius), typeof(CornerRadius), typeof(CornerRadiusSetter), new UIPropertyMetadata(new CornerRadius(), CornerRadiusChangedCallback)); public static void CornerRadiusChangedCallback(object sender, DependencyPropertyChangedEventArgs e) { Control control = sender as Control; if (control == null) return; control.Loaded -= Control_Loaded; control.Loaded += Control_Loaded; } private static void Control_Loaded(object sender, EventArgs e) { Control control = sender as Control; if (control == null || control.Template == null) return; control.ApplyTemplate(); Border border = control.Template.FindName("border", control) as Border; if (border == null) return; border.CornerRadius = GetCornerRadius(control); } } 然后您可以使用附加属性语法来设置多个文本框的样式,而无需重复样式: <TextBox local:CornerRadiusSetter.CornerRadius="10" /> <TextBox local:CornerRadiusSetter.CornerRadius="5, 0, 0, 5" /> <TextBox local:CornerRadiusSetter.CornerRadius="10, 4, 18, 7" /> 以困难的方式去做。 在 Visual Studio 中创建一个新的空 WPF 项目。将 TextBox 添加到主 Window。然后将鼠标放在 TextBox 上,右键单击并选择 编辑模板、编辑副本...。在出现的对话框中,选择应用于全部和此文档。 您现在拥有 TextBox 模板的副本。现在看看名称为 Border 的 border。只需添加一个 CornerRadius 即可。 接下来将此代码复制/粘贴到您的App.xaml中的/Application/Application.Resources/ResourceDictionary中。 它比其他解决方案需要更多的时间,它更复杂,但更干净,一旦你掌握了这个过程,你就可以使用 WPF 做任何你想做的事情。 这读起来很有趣。

回答 7 投票 0

WPF TextBox为所有控件设置通用的StringFormat

是否可以为项目中的所有(或部分)文本框设置 Binding 属性的 StringFormat ?是的,我可以写一些类似的东西 是否可以为项目中的所有(或部分)文本框设置 Binding 属性的 StringFormat ?是的,我可以写类似的东西 <TextBox x:Name="SetPosition" Style="{StaticResource TextBoxSmallStyle}" Text="{Binding SetPosition, Mode=TwoWay, StringFormat='{}{0:#0.0}'}" /> 但是为许多相同的文本框设置它太无聊了)))如你所见,我使用的样式包括高度,宽度等。我无法覆盖样式中的绑定属性,因为需要将此样式与任何绑定路径属性一起使用,但绑定只能完全覆盖。 哪里有解决方法? 附:我已经使用的不是标准 TextBox,而是覆盖了我的特殊功能的控件。我可以覆盖 Binding 以使用组件的代码隐藏吗? 我对在“查看”时需要“特殊”处理的属性使用(可重用)“功能”代码;例如 public string FirstName { get; set; } public string LastName { get; set; } public string FullName => this.FirstName + " " + this.LastName; ... TextBlock Text={Binding FullName} ...

回答 1 投票 0

滚动条和...文本框的奇怪问题? (垂直内容对齐)

我有这个奇怪的问题,我不明白是什么原因造成的。在我的整个项目中,文本框无法垂直居中,无论我使用什么,padding,VerticalContentAlign...

回答 1 投票 0

将旋转框绑定到文本框

我们如何获取 Spinbox 的值(从 1 到 10)然后将其乘以一个数字(例如:100)?然后将结果显示到TKINTER中的文本框中??? 我尝试了.get()方法来获取值,t...

回答 1 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.