我有文本框,当我lostFocus被解雇时我正在更改其中的文本,但这也会激活textChanged我正在处理的事件,但是我不想在这种情况下解雇它,我怎么能在这里禁用它?
这个想法bool很好,但我有几个文本框,我对所有这些都使用相同的事件,所以它并不像我想要的那样完全正常工作.
现在它正在运作!:
private bool setFire = true;
private void mytextbox_LostFocus(object sender, RoutedEventArgs e)
{
if (this.IsLoaded)
{
System.Windows.Controls.TextBox textbox = sender as System.Windows.Controls.TextBox;
if(textbox.Text.ToString().Contains('.'))
{
textbox.Foreground = new SolidColorBrush(Colors.Gray);
textbox.Background = new SolidColorBrush(Colors.White);
setFire = false;
textbox.Text = "something else";
setFire = true;
}
}
}
private void mytextbox_TextChanged(object sender, TextChangedEventArgs e)
{
if ((this.IsLoaded) && setFire)
{
System.Windows.Controls.TextBox textbox = sender as System.Windows.Controls.TextBox;
if(textbox.Text.ToString().Contains('.'))
{
textbox.Foreground = new SolidColorBrush(Colors.White); …Run Code Online (Sandbox Code Playgroud) QPlainTextEdit我的应用程序中有一个QSyntaxHighlighter分配给它的小部件。在该文本编辑区域内的每个内容更改时,我需要收到通知(以更新全局应用程序保存/更改状态)。但是,textChanged()每次荧光笔开始工作时也会发出信号,我需要以某种方式过滤掉。
我已经看过了modificationChanged(),但这似乎也不起作用。它忽略突出显示的更改并在第一次内容更改时成功通知我,但不会通知我任何后续更改。该文件提到,我应该能够与复位内部状态setModified(false),但这种方法似乎并不存在。
关于如何过滤更改的任何想法?
我一定要切换到QTextDocument似乎有哪些单contentsChanged()是说忽略语法高亮的变化?
在C#中,文本框有一个事件,如下所示
private void fooText_TextChanged(object sender, EventArgs e)
{
//do something
}
Run Code Online (Sandbox Code Playgroud)
一旦文本框中的文本被更改,就会触发fooText_TextChanged中的代码.
什么是Java相当于此?或者如何在java中实现与此类似的东西?
感谢您提供任何反馈/帮助/建议.
private void NameVal_TextChanged(object sender, EventArgs e)
{
String text = NameVal.Text;
}
Run Code Online (Sandbox Code Playgroud)
一旦我输入我姓名的第一个字母,该程序就会被执行.如何输入程序,直到我输入字段的整个字符串(例如名称ex:James).
我对多行文本框 (WinForms) 中的 TextChanged 事件有一个非常奇怪的问题。在某些情况下,该事件似乎会触发两次。
这个完整的代码演示了这个问题:
public partial class TextChangedTest : Form
{
public TextChangedTest()
{
InitializeComponent();
}
private void TextChangedTest_Load(object sender, EventArgs e)
{
TextBox tb = new TextBox();
//Remove the following line and the code behaves as expected
tb.Multiline = true;
this.Controls.Add(tb);
tb.TextChanged += new EventHandler(tb_TextChanged);
}
private void tb_TextChanged(object sender,EventArgs e)
{
//Need to validate and use the new text here.
//For testing, just use a MessageBox
MessageBox.Show("Handler fired");
}
}
Run Code Online (Sandbox Code Playgroud)
如果您现在在 TextBox 中键入一个字符,则会触发该事件。正确的行为。
如果您删除该角色,该事件将触发一次。正确的行为。
如果您使用退格键删除字符,则事件会触发一次。正确的行为。
如果您通过选择该字符并按 …
所以,例如,如果我在WFA中有2个文本框.以下代码有效.
private void textBox1_TextChanged(object sender, EventArgs e)
{
textBox2.Text = textBox1.Text;
}
Run Code Online (Sandbox Code Playgroud)
我明白了.当我更改它时,第二个文本框中的文本等于第一个文本框中的文本.

但是当谈到WPF时,我会得到完全不同的行为.当我这样做.
private void textBox_TextChanged(object sender, TextChangedEventArgs e)
{
textBox1.Text = textBox.Text;
}
Run Code Online (Sandbox Code Playgroud)
然后按Ctrl + F5测试应用程序,没有任何反应.日志显示"Build Succeeded"并没有.这有什么不对?
这是XAML代码.
<Window x:Class="TextBoxTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:TextBoxTest"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<TextBox x:Name="textBox" HorizontalAlignment="Left" Height="23" Margin="212,77,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120" TextChanged="textBox_TextChanged"/>
<TextBox x:Name="textBox1" HorizontalAlignment="Left" Height="23" Margin="212,124,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120"/>
</Grid>
Run Code Online (Sandbox Code Playgroud)
我有一个绑定到数据源的文本框.文本框的TextChanged事件更新了另一个文本框.
问题是,我不希望第一个文本框显示,所以我将其Visible属性设置为false.
但是,现在TextChanged活动并不开火!
我可以解决它通过设置Visible=True,Left=-100000在窗体加载,但我想一个妥善的解决办法.
任何人都可以提供解释吗?
我有2个文本框,如果我在textbox1中写anythng,它应该立即反映在textbox2中,如果我在textbox2中写任何东西,它应该反映在textbox1中.
那我该怎么做?我以前看过这篇文章以及如何在两个文本框之间实现?
http://www.zurb.com/playground/jquery-text-change-custom-event
这是我的文本框:
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
Run Code Online (Sandbox Code Playgroud) 我将根据另一个edittext上的值输入更改edittext的文本.并且也喜欢相同的thig,反之亦然.
为此,我使用TextChanged Listener并实现如下:
includedText.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if(!(includedText.getText().toString().equals("")))
{
double included = Double.parseDouble(includedText.getText().toString());
included = roundTwoDecimals(included);
String amt = String.valueOf(roundTwoDecimals(included-(included/1.15)));
String excluded = String.valueOf(included/1.15);
System.out.println("The Amount is: "+amt);
amountText.setText(amt);
excludedText.setText(excluded); //////// Error Line
}
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
@Override
public void afterTextChanged(Editable s) {
}
});
// worked
excludedText.addTextChangedListener(new TextWatcher()
{
@Override
public void onTextChanged(CharSequence s, int start, int …Run Code Online (Sandbox Code Playgroud) 我想得到一列datagridview的总和,并在文本框中显示.每次输入后,应动态更改总和.为此,我使用文本框的textChanged事件但是当输入时,它不显示任何结果.我想在文本框中动态获取结果.我想避免使用按钮来求和.
这是textbox textChanged事件的一段代码:
private void textBox9_TextChanged(object sender, EventArgs e)
{
double sum = 0;
for (int i = 0; i < dataGridView2.Rows.Count; ++i)
{
sum += Convert.ToDouble(dataGridView2.Rows[i].Cells[5].Value);
}
textBox9.Text = sum.ToString();
}
Run Code Online (Sandbox Code Playgroud) textchanged ×10
c# ×6
textbox ×6
winforms ×5
wpf ×2
android ×1
asp.net ×1
c++ ×1
data-binding ×1
datagridview ×1
java ×1
jquery ×1
jtextfield ×1
lostfocus ×1
multiline ×1
qt5 ×1
swing ×1
user-input ×1