System.Windows.Forms.Timer中的Graphics问题

hnhujun518 2011-05-21 09:45:13
IntPtr handle = webBrowser.Handle;
StringBuilder className = new StringBuilder(100);
while (className.ToString() != "Internet Explorer_Server") // The class control for the browser
{
handle = GetWindow(handle, 5); // Get a handle to the child window
GetClassName(handle, className, className.Capacity);
}
//handle 表示浏览器的句柄
Graphics g = Graphics.FromHwnd(handle);
IntPtr dc;
dc = g.GetHdc();//此时失败。


同样的代码在botton的click事件中执行是正确的。
...全文
52 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
足球中国 2011-05-21
  • 打赏
  • 举报
回复
判断handle 是不是0
wtj2832 2011-05-21
  • 打赏
  • 举报
回复
用完就dispose呢
hnhujun518 2011-05-21
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 sjzlxd 的回复:]
引用楼主 hnhujun518 的回复:
IntPtr handle = webBrowser.Handle;
StringBuilder className = new StringBuilder(100);
while (className.ToString() != "Internet Explorer_Server") // The class control for the bro……
[/Quote]

你好,我在调试堆栈中看线程熟悉的时候 timer是处于ui线程空间的啊。求解。
人工智能算法 2011-05-21
  • 打赏
  • 举报
回复
[Quote=引用楼主 hnhujun518 的回复:]
IntPtr handle = webBrowser.Handle;
StringBuilder className = new StringBuilder(100);
while (className.ToString() != "Internet Explorer_Server") // The class control for the browser
{
hand……
[/Quote]

不是创建控件的线程中访问控件是不合法的. 即便得到了句柄属性 也是没有权限操作的.

110,525

社区成员

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

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

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