zoukankan      html  css  js  c++  java
  • c#中拖动图片的例子

    这个问题来自论坛提问,并没有什么难度,也不需要重画内容。当然还有一种方法是通过api发送WM_SysCommand 和SC_MOVE,也就是拖动无标题窗体的方法 ,但是效果没有这个好。

    using  System;
    using  System.Drawing;
    using  System.Windows.Forms;
    namespace  WindowsApplication2
    {
        
    public   partial   class  Form1 : Form
        
    {
            
    static   string  strDown  =   @" AAACAAEAICAAAAsACQAwAQAAFgAAACgAAAAgAAAAQAAAAAEAAQAAAAAAAAIAAAAA
                           AAAAAAAAAAAAAAAAAAAAAAAA////AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
                           AAAAAAAAAAf4AAAD8AAAA/AAAAPwAAAH+AAAD/gAAB/8AAA//AAAN/wAACf+AAAH
                           9gAADbQAAA2wAAAJsAAAAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
                           AAAAAAAA////////////////////////////////////////////8AP///gH///4
                           B///+Af///AD///gA///wAH//4AB//+AAf//gAD//4AA///AAP//4AH//+AH///g
                           D////j////////////////////////////////////////////8=
    " ;
            
    static   string  strUp  =   @" AAACAAEAICAAAAoACAAwAQAAFgAAACgAAAAgAAAAQAAAAAEAAQAAAAAAAAIAAA
                            AAAAAAAAAAAAAAAAAAAAAAAAAA////AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
                            AAAAAAAAAAAAAf4AAAD8AAAA/AAAAPwAAAH+AAAD/gAAB/8AAA//AAAd/wAAGf+
                            AAAH9gAADbYAAA2yAAAZsAAAGbAAAAGAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
                            AAAAAAAAAAAAA////////////////////////////////////////////8AP///
                            gH///4B///+Af///AD///gA///wAH//4AB//8AAf//AAD//4AA///gAP//4AD//
                            8AF///AB///5A////5///////////////////////////////////////8=
    " ;

            Cursor curUp 
    =   new  Cursor( new  System.IO.MemoryStream(Convert.FromBase64String(strUp)));
            Cursor curDown 
    =   new  Cursor( new  System.IO.MemoryStream(Convert.FromBase64String(strDown)));
            
    public  Form1()
            
    {
                InitializeComponent();
                
    this .pictureBox1.Cursor  =  curUp;
            }


            
    bool  bDragging  =   false ;
            Point pClicked;

            
    private   void  pictureBox1_MouseDown( object  sender, MouseEventArgs e)
            
    {

                bDragging 
    =   true ;
                pClicked 
    =   new  Point(e.X, e.Y);
                
    this .pictureBox1.Cursor  =  curDown;
            }


            
    private   void  pictureBox1_MouseMove( object  sender, MouseEventArgs e)
            
    {
                
    if  (bDragging)
                
    {
                    Point oMoveToPoint;
                    oMoveToPoint 
    =   this .PointToClient(pictureBox1.PointToScreen( new  Point(e.X, e.Y)));
                    oMoveToPoint.Offset(pClicked.X 
    *   - 1 , pClicked.Y  *   - 1 );
                    pictureBox1.Location 
    =  oMoveToPoint;
                }

            }

            
    private   void  pictureBox1_MouseUp( object  sender, MouseEventArgs e)
            
    {
                bDragging 
    =   false ;
                
    this .pictureBox1.Cursor  =  curUp;
            }

        }

    }
     
  • 相关阅读:
    [再寄小读者之数学篇](2014-07-17 一阶中值)
    对流体力学做出巨大贡献的杰出历史人物
    理科生毁灭世界
    [再寄小读者之数学篇](2014-07-17 行列式的计算)
    [再寄小读者之数学篇](2014-07-16 高阶导数的一个表达式)
    [再寄小读者之数学篇](2014-07-16 与对数有关的不等式)
    [再寄小读者之数学篇](2014-07-16 凹函数与次线性性)
    [再寄小读者之数学篇](2014-07-16 二阶中值)
    [再寄小读者之数学篇](2014-07-16 任意阶导数在零处为零的一个充分条件)
    对PostgreSQL xmin的深入学习
  • 原文地址:https://www.cnblogs.com/cl1024cl/p/6204957.html
Copyright © 2011-2022 走看看