代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
CSharp
】
PANEL跨越滚动条截图
作者:
小火柴
/ 发布于
2012/12/6
/
545
//使用方法 //ZgkeLib.ControlImage.GetPanel(panel1).Save(@"C:/1.bmp"); using System; using System.Drawing; using System.Drawing.Imaging; using System.Reflection; using System.Runtime.InteropServices; using System.Windows.Forms; namespace WindowsFormsApplication2 { public partial class Form2 : Form { public Form2() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { ControlImage.GetPanel(panel1).Save("D:\\dd.gif"); ; } } /// <summary> /// zgke@sina.com /// qq:116149 /// Panel截图 /// </summary> public class ControlImage { #region API [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] public struct SCROLLINFO { public uint cbSize; public uint fMask; public int nMin; public int nMax; public uint nPage; public int nPos; public int nTrackPos; } public enum ScrollBarInfoFlags { SIF_RANGE = 0x0001, SIF_PAGE = 0x0002, SIF_POS = 0x0004, SIF_DISABLENOSCROLL = 0x0008, SIF_TRACKPOS = 0x0010, SIF_ALL = (SIF_RANGE | SIF_PAGE | SIF_POS | SIF_TRACKPOS) } public enum ScrollBarRequests { SB_LINEUP = 0, SB_LINELEFT = 0, SB_LINEDOWN = 1, SB_LINERIGHT = 1, SB_PAGEUP = 2, SB_PAGELEFT = 2, SB_PAGEDOWN = 3, SB_PAGERIGHT = 3, SB_THUMBPOSITION = 4, SB_THUMBTRACK = 5, SB_TOP = 6, SB_LEFT = 6, SB_BOTTOM = 7, SB_RIGHT = 7, SB_ENDSCROLL = 8 } [DllImport("user32.dll", CharSet = CharSet.Auto)] public static extern int GetScrollInfo(IntPtr hwnd, int bar, ref SCROLLINFO si); [DllImport("user32")] public static extern int SetScrollPos(IntPtr hWnd, int nBar, int nPos, bool Rush); [DllImport("user32.dll", CharSet = CharSet.Auto)] public static extern int SendMessage(IntPtr hWnd, int msg, int wParam, int lParam); #endregion public static Bitmap GetPanel(Panel p_Panel) { bool _PanelAotu = p_Panel.AutoScroll; Size _PanelSize = p_Panel.Size; p_Panel.Visible = false; p_Panel.AutoScroll = true; MoveBar(0, 0, p_Panel); MoveBar(1, 0, p_Panel); Point _Point = GetScrollPoint(p_Panel); p_Panel.Width += _Point.X + 5; p_Panel.Height += _Point.Y + 5; Bitmap _BitMap = new Bitmap(p_Panel.Width, p_Panel.Height); p_Panel.DrawToBitmap(_BitMap, new Rectangle(0, 0, _BitMap.Width, _BitMap.Height)); p_Panel.AutoScroll = _PanelAotu; p_Panel.Size = _PanelSize; p_Panel.Visible = true; return _BitMap; } /// <summary> /// 获取滚动条数据 /// </summary> /// <param name="MyControl"></param> /// <param name="ScrollSize"></param> /// <returns></returns> private static Point GetScrollPoint(Control MyControl) { Point MaxScroll = new Point(); SCROLLINFO ScrollInfo = new SCROLLINFO(); ScrollInfo.cbSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(ScrollInfo); ScrollInfo.fMask = (uint)ScrollBarInfoFlags.SIF_ALL; GetScrollInfo(MyControl.Handle, 1, ref ScrollInfo); MaxScroll.Y = ScrollInfo.nMax - (int)ScrollInfo.nPage; if ((int)ScrollInfo.nPage == 0) MaxScroll.Y = 0; GetScrollInfo(MyControl.Handle, 0, ref ScrollInfo); MaxScroll.X = ScrollInfo.nMax - (int)ScrollInfo.nPage; if ((int)ScrollInfo.nPage == 0) MaxScroll.X = 0; return MaxScroll; } /// <summary> /// 移动控件滚动条位置 /// </summary> /// <param name="Bar"></param> /// <param name="Point"></param> /// <param name="MyControl"></param> private static void MoveBar(int Bar, int Point, Control MyControl) { if (Bar == 0) { SetScrollPos(MyControl.Handle, 0, Point, true); SendMessage(MyControl.Handle, (int)0x0114, (int)ScrollBarRequests.SB_THUMBPOSITION, 0); } else { SetScrollPos(MyControl.Handle, 1, Point, true); SendMessage(MyControl.Handle, (int)0x0115, (int)ScrollBarRequests.SB_THUMBPOSITION, 0); } } } }
试试其它关键字
滚动条截图
同语言下
.
文件IO 操作类库
.
Check图片类型[JPEG(.jpg 、.jpeg),TIF,GIF,BMP,PNG,P
.
机器名和IP取得(IPV4 IPV6)
.
Tiff转换Bitmap
.
linqHelper
.
MadieHelper.cs
.
RegHelper.cs
.
如果关闭一个窗体后激活另一个窗体的事件或方法
.
创建日志通用类
.
串口辅助开发类
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
小火柴
贡献的其它代码
(
15
)
.
统计数据库中表,视图,存储过程个数
.
动态调用WebService方法
.
强制关闭浏览器窗口
.
复制网页内容到剪切板
.
Excel 创建、打开、读取、写入、保存的一般性代码
.
Eval绑定时间格式化
.
控制Repeater每行显示条数
.
无标题栏窗体的鼠标拖动效果
.
自动加载图标
.
Winform获取bin目录的路径
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3