zoukankan      html  css  js  c++  java
  • c# sendmessage control to scroll

    Declare some constants:
    private const int WM_SCROLL = 276; // Horizontal scroll
    private const int WM_VSCROLL = 277; // Vertical scroll
    private const int SB_LINEUP = 0; // Scrolls one line up
    private const int SB_LINELEFT = 0;// Scrolls one cell left
    private const int SB_LINEDOWN = 1; // Scrolls one line down
    private const int SB_LINERIGHT = 1;// Scrolls one cell right
    private const int SB_PAGEUP = 2; // Scrolls one page up
    private const int SB_PAGELEFT = 2;// Scrolls one page left
    private const int SB_PAGEDOWN = 3; // Scrolls one page down
    private const int SB_PAGERIGTH = 3; // Scrolls one page right
    private const int SB_PAGETOP = 6; // Scrolls to the upper left
    private const int SB_LEFT = 6; // Scrolls to the left
    private const int SB_PAGEBOTTOM = 7; // Scrolls to the upper right
    private const int SB_RIGHT = 7; // Scrolls to the right
    private const int SB_ENDSCROLL = 8; // Ends scroll
    
    Add a using reference
    using System.Runtime.InteropServices;
    
    Declare external SendMessage:
    [DllImport("user32.dll",CharSet=CharSet.Auto)]
    private static extern int SendMessage(IntPtr hWnd, int wMsg,IntPtr wParam, IntPtr lParam);
    
    Usage: 
    If you have some textbox on the form...
    
    SendMessage( Control Handle , WM Scroll Message, (IntPtr) Scroll Command ,IntPtr.Zero);
    
    Scroll page up
    SendMessage(textBox1.Handle,WM_VSCROLL,(IntPtr)SB_PAGEUP,IntPtr.Zero);
    
    Scroll page down
    SendMessage(textBox1.Handle,WM_VSCROLL,(IntPtr)SB_PAGEDOWN,IntPtr.Zero);

    The DataGridView control has 2 sub-controls, a VScrollBar and a HScrollBar. If you want to do a scroll over a DataGridView you have to send the WM_VSCROLL or WM_HSCROLL message to the DataGridView handle, with wParam as the SB_xxxx value you want, and lParam as the scrollbar handle. 

    Example: 
    public void ScrollControlDown(DataGridView dataGridView) 

    VScrollBar barraVertical = null; 

    foreach (Control c in dataGridView.Controls) 

    if (c is VScrollBar) barraVertical = (VScrollBar)c; 


    if (barraVertical != null) 

    SendMessage(dataGridView.Handle, WM_VSCROLL, (IntPtr)SB_LINEDOWN, barraVertical.Handle); 
    SendMessage(dataGridView.Handle, WM_VSCROLL, (IntPtr)SB_ENDSCROLL, barraVertical.Handle); 



    This method requires the DataGridView's ScrollBars property shows the scrollbar over you are going to do the programatical scroll. If you want to send WM_VSCROLL, ScrollBars property must be set to Both or Vertical. If you want to send WM_HSCROLL, ScrollBars propery must be set to Both or Horizontal. 

  • 相关阅读:
    vmware里面的名词 vSphere、vCenter Server、ESXI、vSphere Client
    SQL Server2014 SP2新增的数据库克隆功能
    看完SQL Server 2014 Q/A答疑集锦:想不升级都难!
    Windows Server 2012 NIC Teaming 网卡绑定介绍及注意事项
    最近帮客户实施的基于SQL Server AlwaysOn跨机房切换项目
    基于本地存储的kvm虚拟机在线迁移
    SQL Server 数据加密功能解析
    android开发之GestureDetector手势识别(调节音量、亮度、快进和后退)
    Datazen介绍
    jquery智能弹出层,自己主动推断位置
  • 原文地址:https://www.cnblogs.com/wolly88/p/4454808.html
Copyright © 2011-2022 走看看