代码语言
.
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
】
WINFROM下带有自动滚动条截图
作者:
zgke
/ 发布于
2014/7/29
/
1105
WINFROM下带有自动滚动条截图根据滚动条的长度进行截图,发图复制到一起 使用PANEL 如果是窗体请把窗体放到PANEL里 要不会多出标题来
using System; using System.Drawing; using System.Drawing.Imaging; using System.Reflection; using System.Runtime.InteropServices; using System.Windows.Forms; namespace ZgkeLib { 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 /// <summary> /// 获取图形 /// </summary> /// <param name="MyControl"></param> /// <returns></returns> public static Bitmap GetImage(Control MyControl) { Point ScrollMaxInfo=GetScrollPoint(MyControl); Size ControlMaxSize = GetControlSize(MyControl, ScrollMaxInfo); Bitmap ControlImage = new Bitmap(ControlMaxSize.Width, ControlMaxSize.Height); Graphics MainGraphics = Graphics.FromImage(ControlImage); Bitmap TempImage = new Bitmap(MyControl.Width-16, MyControl.Height-16); int StepWidth = GetScrollNumb(MyControl.Width-16, ScrollMaxInfo.X); int StepHeight = GetScrollNumb(MyControl.Height-16, ScrollMaxInfo.Y); int LogWidth = 0; int LogHeigh = 0; MoveBar(0, 0, MyControl); for (int i = 0; i != StepWidth; i++) { MoveBar(1, 0, MyControl); LogHeigh = 0; for (int z = 0; z != StepHeight; z++) { MyControl.DrawToBitmap(TempImage, new Rectangle(0, 0, MyControl.Width-16, MyControl.Height-16)); MainGraphics.DrawImage(TempImage, LogWidth, LogHeigh); MoveBar(1, MyControl.Height-16+LogHeigh, MyControl); LogHeigh=GetScrollPoint(1, MyControl); } MoveBar(0, MyControl.Width-16 + LogWidth, MyControl); LogWidth = GetScrollPoint(0, MyControl); } MainGraphics.Dispose(); TempImage.Dispose(); return ControlImage; } /// <summary> /// 获取目前滚动条位置 /// </summary> /// <param name="Bar"></param> /// <param name="MyControl"></param> /// <returns></returns> public static int GetScrollPoint(int Bar, Control MyControl) { SCROLLINFO ScrollInfo = new SCROLLINFO(); ScrollInfo.cbSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(ScrollInfo); ScrollInfo.fMask = (uint)ScrollBarInfoFlags.SIF_ALL; GetScrollInfo(MyControl.Handle, Bar, ref ScrollInfo); return ScrollInfo.nPos; } /// <summary> /// 获取循环几次获得图形 /// </summary> /// <returns></returns> private static int GetScrollNumb(int MyControlNumb, int ScrollMaxInfoNumb) { double Step = (double)ScrollMaxInfoNumb / (double)MyControlNumb; Step++; if ((int)Step == Step) { return (int)Step; } else { return (int)Step+1; } } /// <summary> /// 获得控件不需要滚动条的宽和高(最终图形大小) /// </summary> /// <param name="MyControl"></param> /// <param name="ScrollMaxInfo"></param> /// <returns></returns> private static Size GetControlSize(Control MyControl, Point ScrollMaxInfo) { return new Size(MyControl.Size.Width + ScrollMaxInfo.X-16, MyControl.Size.Height+ScrollMaxInfo.Y-16); } /// <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转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
zgke
贡献的其它代码
(
46
)
.
让程序只保证一个进程的类
.
获取PictureBox的SizeMode为Zoom图形的大小
.
获取RICHTEXTBOX所有图形的位置和大小
.
实现系统热键盘注册的类.
.
操作CUR的类
.
读写 Photoshop PSD文件 操作类
.
获取系统鼠标指针
.
隐藏滚动条
.
实现BCD码
.
获取EXCEL所有表名
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3