点滴积累,融会贯通

-----喜欢一切有兴趣的东西

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
可以借助 Htmlpage 对象 HtmlPage(System.Windows.Browser;)
HtmlPage.Window.AttachEvent("DOMMouseScroll", OnMouseWheel);
            HtmlPage.Window.AttachEvent(
"onmousewheel", OnMouseWheel);
            HtmlPage.Document.AttachEvent(
"onmousewheel", OnMouseWheel);        

            
private void OnMouseWheel(object sender, HtmlEventArgs args)
           {

           }

 

之后我们要在onmousewheel 方法中获取一个旋转角度属性

但是在不同浏览器中 这个属性的名称有些不同

根据这个角度我们可以得知鼠标正在向上或是向下滚动

 

            double mouseDelta = 0;
            ScriptObject e 
= args.EventObject;
            
if (e.GetProperty("detail"!= null)
            {
// 火狐和苹果
                mouseDelta = ((double)e.GetProperty("detail"));
            }    
            
else if (e.GetProperty("wheelDelta"!= null)
            {
// IE 和 Opera    
                mouseDelta = ((double)e.GetProperty("wheelDelta"));
            }
            mouseDelta 
= Math.Sign(mouseDelta);
            
if (mouseDelta > 0
            {
                txt.Text 
= "向上滚动";
            }
            
else if (mouseDelta<0
            {
                txt.Text 
= "向下滚动";
            }

 

在向上向下滚动的时候可以加入鼠标坐标的判断,以便确定鼠标在那个控件上,可以执行不同的操作.

接下来 再给大家聊聊 如何获取键盘的组合键(比如我们经常按住ctrl+鼠标点击 或者 ctrl+enter)

其实 我们只要用到一个枚举值

namespace System.Windows.Input
{
    
// Summary:
    
//     Specifies the set of modifier keys.
    [Flags]
    
public enum ModifierKeys
    {
        
// Summary:
        
//     No modifiers are pressed.
        None = 0,
        
//
        
// Summary:
        
//     The ALT key is pressed.
        Alt = 1,
        
//
        
// Summary:
        
//     The CTRL key is pressed.
        Control = 2,
        
//
        
// Summary:
        
//     The SHIFT key is pressed.
        Shift = 4,
        
//
        
// Summary:
        
//     The Windows logo key is pressed.
        Windows = 8,
        
//
        
// Summary:
        
//     The Apple key (also known as the "Open Apple key") is pressed.
        Apple = 8,
    }
}

具体如何方法

好比我们现在页面注册一个点击事件

this.MouseLeftButtonDown += new MouseButtonEventHandler(Page_MouseLeftButtonDown);
void Page_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
 {}

我们需要在里面做一点儿小操作就可以判断用户是否还在按住了键盘上的某个按键

 

            ModifierKeys keys = Keyboard.Modifiers;
            txt.Text 
= "";
            
if ((keys & ModifierKeys.Shift) != 0)
                txt.Text 
+= "shift";
            
if ((keys & ModifierKeys.Alt) != 0)
                txt.Text 
+= "alt";
            
if ((keys & ModifierKeys.Apple) != 0)
                txt.Text 
+= "apple";
            
if ((keys & ModifierKeys.Control) != 0)
                txt.Text 
+= "ctrl";
            
if ((keys & ModifierKeys.Windows) != 0)
                txt.Text 
+= "windows";
            txt.Text 
+= " + 鼠标点击"
posted on 2010-08-05 10:37  小寒  阅读(867)  评论(0编辑  收藏  举报