国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

.net中PictureBox中圖片的拖動

2024-07-10 12:55:45
字體:
來源:轉載
供稿:網友
中國最大的web開發資源網站及技術社區,
 

.net中picturebox中圖片的拖動
首先在form窗體上放一個picturebox,并指定一個圖片顯示

定義一系列變量處理圖片拖動
 '處理圖片拖動
        private m_leftx as integer
        private m_lefty as integer
        dim m_mouseposx as integer
        dim m_mouseposy as integer
        dim m_driftx as integer
        dim m_drifty as integer
并給賦初值,可以在form初始化時做
  me.m_leftx = me.picturebox1.location.x
        me.m_lefty = me.picturebox1.location.y

定義處理鼠標按下的事件

 '當鼠標按下時,將鼠標變成手形,并且記錄下當前鼠標的位置
  private sub picturebox1_mousedown(byval sender as object, byval e as system.windows.forms.mouseeventargs) handles picturebox1.mousedown

            me.cursor = system.windows.forms.cursors.hand
            m_mouseposx = e.x
            m_mouseposy = e.y

        end sub
定義處理鼠標抬起的事件
 '處理鼠標按鍵抬起的事件,根據鼠標按下時保存的鼠標位置,和當前鼠標的位置,計算鼠標移動偏移量,借此調用移動圖片的函數,移動圖片
        private sub picturebox1_mouseup(byval sender as object, byval e as system.windows.forms.mouseeventargs) handles picturebox1.mouseup
          
            m_driftx = m_mouseposx - e.x
            m_drifty = m_mouseposy - e.y
         
            m_leftx = m_leftx - m_driftx
            m_lefty = m_lefty - m_drifty
          
            picturemove(sender, e)
            me.cursor = system.windows.forms.cursors.arrow

        end sub


 '根據偏移量計算出的圖片位置,重畫圖片
        private sub picturemove(byval sender as object, byval e as system.windows.forms.mouseeventargs)
            dim mybit as new system.drawing.bitmap(picturebox1.image)

            dim mypicgrh as system.drawing.graphics = me.picturebox1.creategraphics
            mypicgrh.clear(me.picturebox1.backcolor)
           
            mypicgrh.drawimageunscaled(mybit, m_leftx - 152, m_lefty)

            mybit.dispose()
            mypicgrh.dispose()


        end sub


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 盖州市| 西宁市| 长岭县| 乳山市| 乌兰浩特市| 广水市| 巴彦淖尔市| 拉孜县| 秭归县| 泸水县| 大厂| 衡山县| 张家界市| 池州市| 从化市| 巴马| 志丹县| 新竹县| 荔浦县| 庄河市| 海伦市| 靖远县| 资中县| 无棣县| 四会市| 开江县| 盘山县| 蚌埠市| 晴隆县| 宜春市| 多伦县| 陆良县| 章丘市| 扶风县| 大厂| 台州市| 连南| 东平县| 七台河市| 万全县| 祁门县|