博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
c# sendmessage control to scroll
阅读量:7114 次
发布时间:2019-06-28

本文共 2462 字,大约阅读时间需要 8 分钟。

Declare some constants:private const int WM_SCROLL = 276; // Horizontal scrollprivate const int WM_VSCROLL = 277; // Vertical scrollprivate const int SB_LINEUP = 0; // Scrolls one line upprivate const int SB_LINELEFT = 0;// Scrolls one cell leftprivate const int SB_LINEDOWN = 1; // Scrolls one line downprivate const int SB_LINERIGHT = 1;// Scrolls one cell rightprivate const int SB_PAGEUP = 2; // Scrolls one page upprivate const int SB_PAGELEFT = 2;// Scrolls one page leftprivate const int SB_PAGEDOWN = 3; // Scrolls one page downprivate const int SB_PAGERIGTH = 3; // Scrolls one page rightprivate const int SB_PAGETOP = 6; // Scrolls to the upper leftprivate const int SB_LEFT = 6; // Scrolls to the leftprivate const int SB_PAGEBOTTOM = 7; // Scrolls to the upper rightprivate const int SB_RIGHT = 7; // Scrolls to the rightprivate const int SB_ENDSCROLL = 8; // Ends scrollAdd a using referenceusing 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 upSendMessage(textBox1.Handle,WM_VSCROLL,(IntPtr)SB_PAGEUP,IntPtr.Zero);Scroll page downSendMessage(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. 

转载于:https://www.cnblogs.com/wolly88/p/4454808.html

你可能感兴趣的文章
将敏捷应用于工业机械开发
查看>>
有赞HBase技术实践:读流程解析与优化
查看>>
微软最具价值技术专家:我的16年软件开发经验总结
查看>>
腾讯云+未来高峰对话:智能+时代的创新与探索
查看>>
C# 8中的默认接口方法
查看>>
实现TeX的算法:回首编程技术的过去三十年
查看>>
京东构建了全球最大的Kubernetes集群,没有之一
查看>>
Facebook是如何缩短iOS应用启动时间的
查看>>
又拍云CDN再出力作,三驾马车为视频护航
查看>>
Java RESTful Web Service实战
查看>>
全球首届APMCon,带你给“应用性能”把把脉
查看>>
详解分布式系统本质:“分治”和“冗余”
查看>>
谈谈常见H5制作方法——视频与CSS3
查看>>
[译]Yarn:一个新的JavaScript包管理器
查看>>
用VS2015开发Linux程序详细教程-配置篇
查看>>
实用的IT类网站及工具大集合
查看>>
tomcat的servlet读取请求参数
查看>>
CentOS下jenkins安装与配置
查看>>
首屏渐进式渲染设想
查看>>
web缓存机制
查看>>