将C#转换为C#WPF ......... [英] Converting C# to C# WPF............
本文介绍了将C#转换为C#WPF .........的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码
this is my code
panel.Bounds.Contains(MousePosition);
can some one please conver this code into C# WPF code?
推荐答案
没有C#与C#WPF — C#是C#.没有转换" —库是不同的并且做不同的事情.
现在,我想您只需要对照面板的边界矩形检查鼠标坐标即可.问题是:您在哪个坐标系中具有MousePosition
?如果从此控件的事件中获取了鼠标坐标,则返回始终为true
;否则,返回true
.如果鼠标位置是屏幕坐标,则使用System.Windows.Media.Visual.PointToScreen
将矩形(0,0),(ActualWidth
,ActualHeight
)的角点计算为屏幕坐标,并比较鼠标位置;或者,使用System.Windows.Media.Visual.PointFromScreen
计算鼠标在控件坐标系中的位置.很简单.
当您可以使用点击测试时,您不必这样做.参见:
http://msdn.microsoft.com/en-us/library/ms608859.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/ms608858.aspx [ ^ ].
—SA
There is not C# vs C# WPF — C# is C#. There is no "convert" — the libraries are different and do different things.
Now, I guess you simply need to check mouse coordinate against panel''s bounding rectangle. The question is: in what coordinate system do you haveMousePosition
? If you got the mouse coordinates from the event of this control, the return is alwaystrue
; if you have mouse position is screen coordinates, useSystem.Windows.Media.Visual.PointToScreen
to calculate corner points of the rectangle (0, 0), (ActualWidth
,ActualHeight
) into screen coordinates and compare the mouse position; alternatively, calculate mouse position in the control''s coordinate system usingSystem.Windows.Media.Visual.PointFromScreen
. Simple enough.
You don''t have to do this when you can use hit tests. See:
http://msdn.microsoft.com/en-us/library/ms608859.aspx[^],
http://msdn.microsoft.com/en-us/library/ms608858.aspx[^].
—SA
这篇关于将C#转换为C#WPF .........的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文