最近做專案有這樣的要求
在picturebox中畫出座標系統和曲線,
曲線的旁邊要有標註
而且標註可以移動,當然是座標範圍內
以便調整到適當位置列印出來
查了一些資料
現在整理一下
對於移動標籤
網上資料很多
主要思想是 mousedown 的時候判斷是否選中控制項
mousemove的時候給滑鼠位置變數 賦當前滑鼠的位置
mouseup的時候放棄移動
dim whetherselected as boolean = false
dim mousepoint as new point
private sub label_mousedown(byval sender as system.object, byval e as system.windows.forms.mouseeventargs) handles label1.mousedown
whetherselected = true
mousepoint.x = e.x
mousepoint.y = e.y
end sub
private sub label_mouseup(byval sender as system.object, byval e as system.windows.forms.mouseeventargs) handles label1.mouseup
whetherselected = false
end sub
private sub label_mousemove(byval sender as system.object, byval e as system.windows.forms.mouseeventargs) handles label5.mousemove
dim label as label
label = ctype(sender, label)
if (whetherselected = true) then
mousepoint.x = e.x
mousepoint.y = e.y
dim p as point
p = control.mouseposition
p.offset(e.x - mousepoint.x, e.y - mousepoint.y)
dim c as control
c = sender
c.location = c.parent.pointtoclient(p)
end if
vb版的在這邊
對於限制滑鼠位置
網上很多用api 的clipcursor
但是.net 本身就有很方便的方法
參考http://msdn2.microsoft.com/en-us/library/system.windows.forms.cursor.clip.aspx
JQuery實現滑鼠拖動元素移動位置
jquery實現元素移動位置有很多種方法,其中乙個是根據滑鼠在指定區域內隨意移動,還有一種的是根據方向鍵在一定區域內上下左右平移。這二種只能說各有優劣,通過方向鍵平移,實現相對簡單,操作也更具備可控性,但是就是移動效率相對較低,每次平移量過大造成不夠精準,平移量過小則會使移動過程更為繁瑣。跟隨滑鼠自...
Jquery滑鼠滑動到標籤當前位置後,固定在頂部
滑鼠滑動到標籤當前位置後,固定在頂部。需要固定的 html height 1000px width 500px border 1px solid red div 為了離頂部有一定距離 height 100px background yellowgreen class need fix div jqu...
滑鼠拖動層 可任意繫結DIV標籤 的兩種實現方法
實現方法一 這個用子標籤操作父標籤 呼叫方法 var i new endrag hand movediv 0,0 第乙個引數為源標籤物件或物件id屬性 第二個引數為要移動的目標物件或物件id屬性 第3 4個引數為偏移值,供最後調整用 滑鼠指標在紅色區域才有效 這個用自標籤操作自己 呼叫方法 var ...