這個(gè)類繼承自Panel,把它加到你的項(xiàng)目里面,先運(yùn)行一下,然后從工具箱里把它拖到窗體上,然后再向里面添加其它控件就可以了,支持Shift加選,Alt減選
讓客戶滿意是我們工作的目標(biāo),不斷超越客戶的期望值來自于我們對(duì)這個(gè)行業(yè)的熱愛。我們立志把好的技術(shù)通過有效、簡(jiǎn)單的方式提供給客戶,將通過不懈努力成為客戶在信息化領(lǐng)域值得信任、有價(jià)值的長(zhǎng)期合作伙伴,公司提供的服務(wù)項(xiàng)目有:空間域名、網(wǎng)絡(luò)空間、營銷軟件、網(wǎng)站建設(shè)、平魯網(wǎng)站維護(hù)、網(wǎng)站推廣。
Imports?System.Linq
Imports?System.Collections
Public?Class?MyPanel
Inherits?Panel
'?選擇模式,相交還是包含
Enum?SelectMode
Intersects
Contains
End?Enum
Dim?down?As?New?Point(-1,?-1)
Dim?rect?As?Rectangle
Dim?selected?As?New?List(Of?Control)
Dim?editting?As?IEnumerable(Of?Control)
Dim?mode?As?SelectMode?=?SelectMode.Contains
Dim?shift,?alt?As?Boolean
Public?Sub?New()
Me.DoubleBuffered?=?True
End?Sub
Protected?Overrides?Sub?OnMouseDown(e?As?MouseEventArgs)
MyBase.OnMouseDown(e)
down?=?e.Location
editting?=?selected.ToArray().ToList()
OnMouseMove(e)
End?Sub
Protected?Overrides?Sub?OnMouseMove(e?As?MouseEventArgs)
MyBase.OnMouseMove(e)
If?e.Button?=?Windows.Forms.MouseButtons.Left?Then
Dim?loc?As?New?Point(Math.Min(down.X,?e.X),?Math.Min(down.Y,?e.Y))
Dim?size?As?New?Size(Math.Abs(down.X?-?e.X),?Math.Abs(down.Y?-?e.Y))
rect?=?New?Rectangle(loc,?size)
Dim?cs?As?New?List(Of?Control)
For?Each?c?In?Controls
cs.Add(c)
Next
Dim?a?=?cs.Where(Function(n?As?Control)?(mode?=?SelectMode.Contains?And?rect.Contains(n.Bounds))?Or?(mode?=?SelectMode.Intersects?And?rect.IntersectsWith(n.Bounds)))
If?shift?Then?editting?=?a.Union(selected)?Else?If?alt?Then?editting?=?selected.Except(a)?Else?editting?=?a
Invalidate()
End?If
End?Sub
Protected?Overrides?Sub?OnMouseUp(e?As?MouseEventArgs)
MyBase.OnMouseUp(e)
down?=?New?Point(-1,?-1)
selected?=?editting.ToList()
editting?=?Nothing
Invalidate()
End?Sub
Protected?Overrides?Function?ProcessKeyPreview(ByRef?m?As?Message)?As?Boolean
Dim?KeyCode?As?Keys?=?CInt(m.WParam)?And?CInt(Keys.KeyCode)
Dim?d?As?Boolean
If?m.Msg?=?H100?Or?m.Msg?=?H104?Then?d?=?True?Else?If?m.Msg?=?H101?Or?m.Msg?=?H105?Then?d?=?False?Else?Return?MyBase.ProcessKeyPreview(m)
If?KeyCode?=?Keys.ShiftKey?Then
shift?=?d
ElseIf?KeyCode?=?Keys.Menu?Then
alt?=?d
End?If
Return?MyBase.ProcessKeyPreview(m)
End?Function
Protected?Overrides?Sub?OnPaint(e?As?PaintEventArgs)
MyBase.OnPaint(e)
For?Each?c?As?Control?In?IIf(editting?Is?Nothing,?selected,?editting)
e.Graphics.DrawRectangle(New?Pen(Color.Gray)?With?{.DashStyle?=?Drawing2D.DashStyle.DashDot},?c.Left?-?1,?c.Top?-?1,?c.Width?+?1,?c.Height?+?1)
Next
If?(down.X??0)?Then?e.Graphics.DrawRectangle(New?Pen(Color.Gray)?With?{.DashStyle?=?Drawing2D.DashStyle.DashDot},?rect)
End?Sub
End?Class
[1] private rectWidth As double ,rectHeight As double
[2] return rectWidth
[3] rectWidth=value
[4] return rectHeight
[5] rectHeight=value
[6]這個(gè)在注釋語句里我也不清楚要怎么填,不會(huì)是題目搞錯(cuò)了吧。-_-|||
[7] return 2 *( rectWidth+ rectHeight)
[8] return rectWidth * rectHeight
[9] ,[10] 應(yīng)該是對(duì)rectl的width 和height 屬性賦值。
messagebox。show(“長(zhǎng)方形rect1的周長(zhǎng)是:” rectl.GetSize “長(zhǎng)方形rect2的面積是:” rectl.GetArea)
vb.net中控件都是矩形的,如果一定要看起來是其他形狀的,只能用背景圖片,一般要三個(gè)背景圖片,正常時(shí)候、鼠標(biāo)移上時(shí)候、按下時(shí)候的。分別在按鈕的四個(gè)事件:MouseHover MouseLeave MouseDown MouseUp的時(shí)候更換成相應(yīng)的背景圖片
'我給你找到了,設(shè)置region屬性就可
Private?Sub?PictureBox1_DoubleClick(sender?As?System.Object,?e?As?System.EventArgs)?Handles?PictureBox1.DoubleClick
If?PictureBox1.Region?Is?Nothing?Then
Dim?path?As?New?System.Drawing.Drawing2D.GraphicsPath
path.AddEllipse(0,?0,?200,?200)
PictureBox1.Region?=?New?Region(path)
Else
PictureBox1.Region?=?Nothing
End?If
End?Sub
'這個(gè)雙擊圖片框使其變形,通過GraphicsPath對(duì)象可以作出各種形態(tài)來,比如可作出文字形狀
Dim?stringText?As?String?=?"我是誰"
Dim?family?As?New?FontFamily("Arial")
Dim?myfontStyle?As?Integer?=?CInt(FontStyle.Italic)
Dim?emSize?As?Integer?=?86
Dim?origin?As?New?Point(20,?20)
Dim?format?As?StringFormat?=?StringFormat.GenericDefault
path.AddString(stringText,?family,?myfontStyle,?emSize,?_
origin,?format)
PictureBox1.Region?=?New?Region(path)