winform 失去焦点后btn文字自动刷新

weixin_43936063 2019-04-12 02:34:39




private void txtB0_entry(object sender, EventArgs e) {
btn0.Text = "你来了";
}

private void txtB0_Leave(object sender, EventArgs e) {
btn0.Text = "你走了";
}


问题出在鼠标离开了没有及时显示 你走了
而是你要手动点下btn才显示你走了
...全文
275 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
weixin_43936063 2019-04-12
  • 打赏
  • 举报
回复

上源程序
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 ZY05 {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
}

private void textBox2_Enter(object sender, EventArgs e) {
button2.Text = "你来了";
}

private void textBox2_Leave(object sender, EventArgs e) {
button2.Text = "你走了";
}
//==========================================
// private void textBox2_LostFocus(object sender, EventArgs e) {
// if(textBox2.LostFocus())
// button2.Text = "你走了";
// }
//=========================================
//怎么写这个函数呢又能被正确调用呢?
//========================================
}
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ZY05 {
static class Program {
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main() {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}

weixin_43936063 2019-04-12
  • 打赏
  • 举报
回复
lostFocus 关键如何用呢VS2017
奇点码农 2019-04-12
  • 打赏
  • 举报
回复
引用 4 楼 吹风的兔子 的回复:
二楼是正解。

MouseEnter
MouseLeave

—— 这两个 事件,是非常及时的 光标 进入、离开 事件。

这两个方法在datagridview中好像不适用,虽然有但是不好用
吹风的兔子 2019-04-12
  • 打赏
  • 举报
回复
二楼是正解。 MouseEnter MouseLeave —— 这两个 事件,是非常及时的 光标 进入、离开 事件。
weixin_43936063 2019-04-12
  • 打赏
  • 举报
回复
还是不明白求助
无奈的奈 2019-04-12
  • 打赏
  • 举报
回复
private void textBox1_MouseLeave(object sender, EventArgs e) { label1.Text = "鼠标离开文本框"; } private void textBox1_MouseEnter(object sender, EventArgs e) { label1.Text = "鼠标进入文本框"; }
北京.NET 2019-04-12
  • 打赏
  • 举报
回复
LostFocus

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧