例項108滑鼠畫圓

2021-10-05 21:55:46 字數 1492 閱讀 8866

windows.forms命名空間f定義的rectangle類主要用於表示繪圖的矩形區域。該類有乙個方法contains,用於判斷指定的點在不在矩形區域內部。contains方法的主要形式如下所示:

overloads public function contains  (point)as boolean

overloads public function conta/ns (rectangle)  as boolean

對話方塊form類的方法中,包括creategraphics,即建立與對話方塊關聯的圖形裝置物件。

不需新增任何控制項

public class form1

dim mygraph as graphics

dim mybrush as new solidbrush(color.blue)

dim circlerect as new rectangle

private sub form1_load(byval sender as object, byval e as system.eventargs) handles me.load

mygraph = me.creategraphics

end sub

private sub form1_mousedown(byval sender as object, byval e as system.windows.forms.mouseeventargs) handles me.mousedown

if e.button = mousebuttons.left then

circlerect.x = e.x

circlerect.y = e.y

end if

end sub

private sub form1_mouseup(byval sender as object, byval e as system.windows.forms.mouseeventargs) handles me.mouseup

if e.button = mousebuttons.left then

circlerect.width = e.x - circlerect.x

circlerect.height = e.y - circlerect.y

mygraph.drawellipse(new pen(brushes.red, 5), circlerect)

dim c as integer

c = int(rnd() * 15)

mybrush.color = drawing.colortranslator.fromwin32(qbcolor(c))

mygraph.fillellipse(mybrush, circlerect)

end if

end sub

end class

例項107滑鼠畫線

控制項的mousedown事件處理過程青兩個引數,乙個是sender,乙個是mouseeventargs類的事件。mouseeventargs類是定義在system windows forms中的乙個類,它由同乙個命名空間下的eventargs繼承而來。mouseeventargs類的主要屬性有 g...

Wpf 滑鼠拖動元素例項

1.wpf中滑鼠捕獲和釋放 以矩形為例 建立滑鼠捕獲 mouse.capture rectone 釋放滑鼠捕獲 rectone.releasemousecapture 2.wpf中在定位布局canvas下獲取或設定元素的位置 在指定元素的滑鼠事件中例如,mouseleftbuttondown,mou...

Javascript事件物件 滑鼠拖動例項

window.event 屬性 1.srcelement 獲取事件源 2.keycode 獲取鍵盤資訊 3.clientx,clienty,滑鼠相對於視窗左上角的座標 4.screenx,screeny 滑鼠相對於螢幕左上角的座標 5.returnvalue 事件返回值 6.cancelbubble...