- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
.Net 中的 Cursor.Current
和 this.Cursor
(this
是 WinForm)之间有区别吗?我一直使用 this.Cursor
并且运气很好,但我最近开始使用 CodeRush 并将一些代码嵌入到“Wait Cursor” block 中,而 CodeRush 使用了 Cursor.Current
属性。我在 Internet 上和工作中看到其他程序员对 Cursor.Current
属性有一些问题。这让我想知道两者是否有区别。提前致谢。
我做了一个小测试。我有两个winform。我单击 form1 上的一个按钮,将 Cursor.Current
属性设置为 Cursors.WaitCursor
,然后显示 form2。两种形式的光标都不会改变。它仍然是 Cursors.Default
(指针)光标。
如果我在 form1 上的按钮单击事件中将 this.Cursor
设置为 Cursors.WaitCursor
并显示 form2,则等待光标仅显示在 form1 上,默认光标为在预期的 form2 上。所以,我仍然不知道 Cursor.Current
的作用。
最佳答案
Windows 向包含鼠标光标的窗口发送 WM_SETCURSOR 消息,使其有机会更改光标形状。像 TextBox 这样的控件利用了这一点,将光标更改为 I-bar。 Control.Cursor 属性决定了将使用什么形状。
Cursor.Current 属性直接更改形状,无需等待 WM_SETCURSOR 响应。在大多数情况下,这种形状不太可能长期存在。一旦用户移动鼠标,WM_SETCURSOR 就会将其变回 Control.Cursor。
.NET 2.0 中添加了 UseWaitCursor 属性,以便更轻松地显示沙漏。不幸的是,它不是很好用。它需要 WM_SETCURSOR 消息来更改形状,当您将属性设置为 true 然后执行需要一段时间的操作时,这不会发生。例如试试这个代码:
private void button1_Click(object sender, EventArgs e) {
this.UseWaitCursor = true;
System.Threading.Thread.Sleep(3000);
this.UseWaitCursor = false;
}
光标永远不会改变。要使其成形,您还需要使用 Cursor.Current。这里有一个小助手类可以使它变得简单:
using System;
using System.Windows.Forms;
public class HourGlass : IDisposable {
public HourGlass() {
Enabled = true;
}
public void Dispose() {
Enabled = false;
}
public static bool Enabled {
get { return Application.UseWaitCursor; }
set {
if (value == Application.UseWaitCursor) return;
Application.UseWaitCursor = value;
Form f = Form.ActiveForm;
if (f != null && f.Handle != IntPtr.Zero) // Send WM_SETCURSOR
SendMessage(f.Handle, 0x20, f.Handle, (IntPtr)1);
}
}
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wp, IntPtr lp);
}
然后像这样使用它:
private void button1_Click(object sender, EventArgs e) {
using (new HourGlass()) {
System.Threading.Thread.Sleep(3000);
}
}
关于c# - Cursor.Current 与 this.Cursor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/302663/
我使用 Apache DBCP 来获取连接池,我每次都使用 PoolingDataSource 来获取连接。当我向数据库中插入一个对象时,它工作得很好,但是当我尝试从数据库中选择一个元素时,就会出现问
术语“幽灵光标”有点令人困惑;我的意思是鼠标光标不是由用户控制的,而是由程序创建并完全控制的。 这意味着屏幕上现在有 2 个光标,而不是一个。 屏幕上是否有超过 1 个光标的概念?如果是,有什么方法/
我在关闭 SQLite 类中的 Cursor 时遇到问题。当我在finally block (在DBHelper中)中关闭游标和SQLiteDatabase时,我无法读取其他类中的数据(无法重新打开关
我想连接两个游标,连接后第二个游标的内容也出现在第一个游标中。 正是我的代码, public final Uri AllImage_URI_Int = MediaStore.Images.Media.
.Net 中的 Cursor.Current 和 this.Cursor(this 是 WinForm)之间有区别吗?我一直使用 this.Cursor 并且运气很好,但我最近开始使用 CodeRus
我在 R Studio 中使用 Cobalt 编辑器主题,我通过更改相应的 .cache.css 文件对其进行了微调。背景颜色是深色的(我的选择),但文本光标(鼠标指针)也是深色的,所以很难看清。我在
我做了以下事情: import MySQLdb as mdb con = mdb.connect(hostname, username, password, dbname) cur = con.cur
当我通过 psql 客户端运行此 SQL 查询时,它会运行几秒钟(~90 秒,这是正常的,因为它是一个巨大的表)并返回,然后我可以检查我的行是否已成功插入。 SELECT merge_data('89
我是用pymongo来查询一个地区的所有元素(其实是在一张 map 上查询一个地区的所有 field )。我之前使用 db.command(SON()) 在球形区域中搜索,它可以返回一个字典,并且在字
intellij 调试:运行到光标处,忽略光标前的所有断点。有办法吗?假设光标前有很多断点,不方便一一禁用。 Line10 Line500 <-- cursor 最佳答案 Force Run
看看这两个 python 代码片段, conn = MySQLdb.connect(c['host'], c['user'], c['password'], c['db']) cur = conn.c
我有 2 个来自 SQLite 数据库中不同表的游标。我正在尝试将来自两个游标的数据放入一个 ListView 但每个游标的数据格式不同。 我考虑的是使用 MergeCursor 来组合两个游
许多 RDBMS 支持某种“CURSOR”类型。这些类型在从存储过程返回时最有用。 Oracle 中的示例: TYPE t_cursor_type IS REF CURSOR; CREATE PROC
我的应用程序结合了 Swing 和 JavaFX。我希望所有组件都使用相同的光标。 从 AWT 游标创建 JavaFX 游标的最佳方法是什么? 编辑:有一个名为 javafx.embed.swing.
我在这里遇到问题: conn = psycopg2.connect(conn_string) cursor = conn.cursor() sql = """ SELECT DISTINCT
我想检索我的 Sqlite3 数据库的前 100 行: connection = sqlite3.connect('aktua.db') cursor = connection.cursor() pr
我目前正在使用 libclang 和 C++ 编写一个简单的克隆检测器。 程序使用结构存储游标,包含指向翻译单元的指针和通过调用 clang_getCursorLocation(cursor) 获得的
我有一个 Observable返回单个 Cursor实例(Observable)。我正在尝试利用 ContentObservable.fromCursor获取 onNext 中每个游标的行回调。 我想
许多 RDBMS 支持某种“CURSOR”类型。这些类型在从存储过程返回时最有用。 Oracle 中的示例: TYPE t_cursor_type IS REF CURSOR; CREATE PROC
我正在为可视化工具编写拖动系统。单击并拖动时,它会移动您在窗口中看到的内容。当鼠标碰到面板的边缘时,我开始重新定位光标,使其永远不会离开框。如果光标在框内,它会跟踪光标所在的虚拟位置。这部分代码工作正
我是一名优秀的程序员,十分优秀!