gpt4 book ai didi

c# - 表格中的光标点

转载 作者:行者123 更新时间:2023-11-30 22:33:04 25 4
gpt4 key购买 nike

我想在表单中而不是在屏幕中获取光标点,我知道我需要使用:

        Point ptCursor = Cursor.Position;
ptCursor = PointToClient(ptCursor);

问题是我在一个在不同线程上工作的方法中使用了它,它给了我这个错误信息:

Cross-thread operation not valid: Control 'Form1' accessed from a thread other than the thread it was created on.

为什么我收到这个错误消息?我可以在线程上运行的方法中使用这些行吗?我怎样才能调用一个方法在几秒钟内在表单线程上运行?

最佳答案

您需要在 GUI 线程上分派(dispatch) PointToClient 操作:

this.Invoke(new Action(() => ptCursor = PointToClient(ptCursor)));

关于c# - 表格中的光标点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8489118/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com