private void button1_Click(object sender, EventArgs e)
        {
            Point ScrollMaxInfo = GetScrollPoint(panel1);
            Size ControlMaxSize = GetControlSize(panel1, ScrollMaxInfo);

Bitmap ControlImage = new Bitmap(ControlMaxSize.Width, ControlMaxSize.Height);
            Graphics MainGraphics = Graphics.FromImage(ControlImage);
            Bitmap TempImage = new Bitmap(panel1.Width - 16, panel1.Height - 16);

int StepWidth = GetScrollNumb(panel1.Width - 16, ScrollMaxInfo.X);
            int StepHeight = GetScrollNumb(panel1.Height - 16, ScrollMaxInfo.Y);

int LogWidth = 0;
            int LogHeigh = 0;
            MoveBar(0, 0, panel1);

for (int i = 0; i != StepWidth; i++)
            {
                MoveBar(1, 0, panel1);
                LogHeigh = 0;
                for (int z = 0; z != StepHeight; z++)
                {
                    panel1.DrawToBitmap(TempImage, new Rectangle(0, 0, panel1.Width - 16, panel1.Height - 16));
                    MainGraphics.DrawImage(TempImage, LogWidth, LogHeigh);
                    MoveBar(1, panel1.Height - 16 + LogHeigh, panel1);
                    LogHeigh = GetScrollPoint(1, panel1);
                }
                MoveBar(0, panel1.Width - 16 + LogWidth, panel1);
                LogWidth = GetScrollPoint(0, panel1);
            }
            MainGraphics.Dispose();
            TempImage.Dispose();
            ControlImage.Save(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "123.png");
        }

#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="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);
            }
        }

winfrom中将panel另存为图片的更多相关文章

  1. angular调用WCF服务,读取文件夹下图片显示列表,下载另存为图片

    读取文件夹下的文件 public string ReadImagesPaths() { string result = string.Empty; try { string path = System ...

  2. Qt开发小工具之gif转换器(使用QMovie截取每一帧为QImage,然后用QFile另存为图片文件)

    最近,QQ上好多各种gif表情.每一个都很经典呀..于是我就想把它转换成一张张静态图片...没学过ps.于是写了几行代码.完工.核心代码如下 主要是借助QMovie类.文件读取模式选择QMovie:: ...

  3. winfrom datagridview ,picturebox,显示图片,以及删除问题

     private void write_listview(DataSet ds)         {             DataTable dt = ds.Tables[0];          ...

  4. C#winfrom listview 设置显示图片

    ListView控件有5种显示图片方式:LargeIcon(大图标),Detail(详细),SmallIcon(小图标),List(列表),Tile,常用前4种.  这里说一下设置方式:LargeIc ...

  5. unity中将多个图片进行椭圆排序

    //保存需要排序的精灵容器 public GameObject[] Sprites; public Transform centrePoint;//椭圆的中心点 ;//每个方块间的角度偏移 //保存位 ...

  6. Winfrom 设置Panel添加滚动条

    AutoScroll是自动滚动的属性. 把AutoScroll设置为True;

  7. Chrome浏览器 无需安装插件将整个网页另存为图片

    步骤1 ctrl+shift+i 步骤2 ctrl+shift+p 步骤3 输入full 回车确定 感谢先辈们的无私奉献!原文https://blog.csdn.net/wumingid/articl ...

  8. winfrom自定义滚动条

    panel或图片什么的跟着鼠标走,这里panel自己可以加背景图或直接搞个图就行了.为了演示清楚,有个滚动条控件做对比,与自定义的同步. using System; using System.Coll ...

  9. 初学c# -- 学习笔记(五) winfrom自定义滚动条

    找了些例子,要么庞大.要么搞个安装组件什么的,我要求能用就行了.实在找例子修改麻烦,就做了一个.其实实现挺简单,就是panel或图片什么的跟着鼠标走就行了. 这里panel自己可以加背景图或直接搞个图 ...

随机推荐

  1. angularJS绑定数据中对标签转义的处理

    一.问题 默认情况下,angularJS绑定的数据为字符串文本,不会对其中包含的html标签进行转义生成格式化的文本.在实际工作时碰到接口返回的数据带有html格式时该如何处理. 二.解决办法 1.引 ...

  2. 轻量级操作系统FreeRTOS的内存管理机制(一)

    本文由嵌入式企鹅圈原创团队成员朱衡德(Hunter_Zhu)供稿. 近几年来,FreeRTOS在嵌入式操作系统排行榜中一直位居前列,作为开源的嵌入式操作系统之一,它支持许多不同架构的处理器以及多种编译 ...

  3. CTR预估中的贝叶斯平滑方法(二)参数估计和代码实现

    1. 前言 前面博客介绍了CTR预估中的贝叶斯平滑方法的原理http://www.cnblogs.com/bentuwuying/p/6389222.html. 这篇博客主要是介绍如何对贝叶斯平滑的参 ...

  4. Anaconda配置多spyder多python环境

    作者:桂. 时间:2017-04-17  22:02:37 链接:http://www.cnblogs.com/xingshansi/p/6725298.html  前言 最近在看<统计学习方法 ...

  5. 我的Python---1

    在学习Python两周后的今天,第一次做下总结.在昨天,我发现了这个博客,并且风也似的注册.申请,然后成功了,感谢管理员. 实际上,现在回想起来我第一次接触编程时在高一的计算机课上.那时候只有语数外理 ...

  6. 查询表达式和LINQ to Objects

    查询表达式实际上是由编译器“预处理”为“普通”的C#代码,接着以完全普通的方式进行编译.这种巧妙的发式将查询集合到了语言中,而无须把语义改得乱七八糟 LINQ的介绍 LINQ中的基础概念 降低两种数据 ...

  7. mysql分页查询优化

    由于MySql的分页机制:并不是跳过 offset 行,而是取 offset + N 行,然后返回放弃前 offset 行,返回N 行, 所以当 offset 特别大的时候,效率就非常的低下,要么控制 ...

  8. 【算法系列学习】[kuangbin带你飞]专题十二 基础DP1 F - Piggy-Bank 【完全背包问题】

    https://vjudge.net/contest/68966#problem/F http://blog.csdn.net/libin56842/article/details/9048173 # ...

  9. angular2项目添加ng2-bootstrap

    1. 先webstome创建一个空的工程.例如test File--> New -->Project --> Empty Project 2.然后命令行(Alt+F12)下执行以下命 ...

  10. 调用startActivityForResult后,onActivityResult为什么立刻响应

    现象      今天在编写代码的时候,涉及到两个Activity通过Intent来传值的问题.具体描述为:activity A调用startActivityForResult()函数启动Activit ...