WPF下取得控件或窗体的句柄

窗体: 
IntPtr hwnd = new WindowInteropHelper(this).Handle;
控件: 
IntPtr hwnd = ((HwndSource)PresentationSource.FromVisual(uielement)).Handle;

句柄的取得不要在构造 函数中取得,此时的vitual还没有产生,在Loaded中 就可以了

猜你喜欢

转载自blog.csdn.net/xionglifei2014/article/details/84999509
今日推荐