- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想写一个简单的“注册/登录”程序,只是为了我,只是为了好玩。
我想更改用户键入姓名的 TxtBox 的颜色。当txtBox.Length<4
它应该将其背景更改为红色。
我不知道为什么我的下面的代码不起作用。当我将 txtBox 属性中的文本固定更改为超过 5 个时,它一开始是蓝色的,但之后没有改变。
我的代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace _4Fun
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
if (regTxtBoxName.TextLength<4) {
regTxtBoxName.BackColor = Color.Red;
}
else{
regTxtBoxName.BackColor = Color.DarkBlue;
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void regBtn_Click(object sender, EventArgs e)
{
if (regTxtBoxName.TextLength < 4)
{
txtBoxStatus.Text = "Choose a name with minimal length 5. "; // Urobit txtboxname a pass v registru červene pozadie ak x<4
}
else {
txtBoxStatus.Text = "Your account has been successfully created.";
string name = regTxtBoxName.Text;
}
if (regTxtBoxPass.TextLength < 4)
{
txtBoxStatus.Text = txtBoxStatus.Text + "Choose password with minimal length 5. ";
}
else {
txtBoxStatus.Text = "Your account has been successfully created.";
string pass = regTxtBoxPass.Text;
}
}
}
}
最佳答案
您的代码在窗体的构造函数中设置颜色,然后您不更改它。您需要在 TextBox
上注册 TextChanged
事件,以便在应用程序运行时根据 Textbox
中的字符数更改颜色.
关于C# 按长度更改 txtBox BackColor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27705031/
我在两个不同的 C# Windows 窗体示例中使用了工具提示。这些示例的工具提示的背景颜色会有所不同,如下所示。 ToolTip with yellow BackColor ToolTip with
我想知道如何为TextBox中的选定文本实现自定义背景色。默认情况下,它对所选文本使用Windows的标准颜色(浅蓝色)。由于我使用的是基于winforms TextBox的皮肤文本编辑器,而Text
当某个值来自串行端口时,我想在固定时间内更改 Button 的 BackColor。我在这里设置了 Timer 对象: public formLabel() { InitializeCompo
如何将代码隐藏中的文本框 BackColor 更改为如下所示: Textbox1.BackColor = "#F2F0E1 代替 Textbox1.BackColor = System.Drawing
我想写一个简单的“注册/登录”程序,只是为了我,只是为了好玩。 我想更改用户键入姓名的 TxtBox 的颜色。当txtBox.Length<4它应该将其背景更改为红色。 我不知道为什么我的下面的代码不
我使用的是 OwnerDraw = true,我无法更改项目的背景颜色(我还有几个子项目并且 ListView 设置为详细信息 View )。 最佳答案 我不确定这是否有帮助,因为这个问题有点含糊,但
我的 UITableView 显示来自 SOAP 网络服务的可变数据。最后一行显示总计。我怎样才能仅 TableView 的最后一行设置灰色背景? 这是我的: - (UITableViewCell *
我有一个像下面两个这样的 ProgressBar 控件: 第一个画得很好。如您所见,第二个只有一个0,它应该有两个但另一个看不到,因为ProgressBar 的ForeColor 与TextColor
我想知道如何将用户窗体中标签的背景颜色更改回默认值? (透明或类似 UserForm 的颜色) Info_Label.BackColor = xlTransparent 或 Info_Label.Ba
概览 我目前正在为我的应用开发一个主题系统,允许用户选择浅色和深色主题(类似于 visual studio)。整个过程非常简单,这就是我目前更改 ListView 控件的 BackColor 属性的方
是否可以更改 ToolStripSeparator 控件的 BackColor?设计器中有一个 BackColor 属性,但它似乎没有被使用 - 颜色始终为白色。 最佳答案 我只是将分隔符的 Pain
我有一个看起来像这样的数据表: Row1 Row2 Row3 Row4 Row5 Row6 Gold Gold Pink
我有一个包含 4 个标签的表单。我希望这些标签以指定的频率闪烁,例如 12.5、10、8 和 4 HZ。我使用了计时器,但它无法正常工作,它们闪烁的频率要低得多,我知道这是因为下面的 freqMeth
我重写 OnPaint 方法是为了将颜色放入 DateTimePicker 控件的文本框中,并禁用在文本框中手动键入? 你有解决这个问题的想法吗? public class BCDateTimePic
我有一个 Compact Framework (3.5) 控件,我希望它具有 SystemColors.Window 的默认颜色,外观类似于编辑控件。我遇到的问题是 Visual Studio (20
我在 VS 2015 中使用 Win Form Metro Framework 在 Windows 7 中构建带有 Metro Tiles 的 Metro Form。 .但是,它不起作用。没有任何反应
我想使用不同的颜色为每个 ListView 单元格的 BackColor 着色。这可能吗? 最佳答案 要更改单元格的BackColor 颜色,您可以这样做: listView1.Items[0].Us
如何在 IE7 中更改 DropDownList BackColor?在 Firefox 中,它正确绘制了整个 DropDown,但在 IE7 中,DropDown 的边框始终保留白色。 最佳答案 本
我希望在 ASP.NET 表单中获取标签的背景色,并使用此值更改此标签的颜色这可能吗? '> 谢谢。 最佳答案 //标签,通过HexaColor设置前景色 lblResult.ForeColor =
有没有一种简单的方法可以让选定的 TreeNode 保留其 SystemColors.Highlight BackColor 而 TreeView 没有焦点?因为即使将 HideSelection 设
我是一名优秀的程序员,十分优秀!