這個類繼承自Panel,把它加到你的項目里面,先運行一下,然后從工具箱里把它拖到窗體上,然后再向里面添加其它控件就可以了,支持Shift加選,Alt減選
創(chuàng)新互聯(lián)公司堅持“要么做到,要么別承諾”的工作理念,服務領域包括:成都網(wǎng)站制作、成都網(wǎng)站設計、外貿(mào)營銷網(wǎng)站建設、企業(yè)官網(wǎng)、英文網(wǎng)站、手機端網(wǎng)站、網(wǎng)站推廣等服務,滿足客戶于互聯(lián)網(wǎng)時代的江城網(wǎng)站設計、移動媒體設計的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(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
這問題有點籠統(tǒng),軟糖來說說把:
圖像處理由System.Drawing命名空間負責。
主要是Bitmap類和Graphics類。
Bitmap表示一個位圖,可以是BMP,JPG,PNG等文件。
裝載位圖
Dim?位圖?As?Bitmap?=?Bitmap.FromFile("C:\Image1.PNG")
Graphics表示一張畫紙,能夠進行繪制操作。
它可以被窗體、控件、位圖調(diào)用CreateGraphics()方法來創(chuàng)建。
然后調(diào)用Graphics.Draw開頭的一系列函數(shù)來繪制圖像和圖形,F(xiàn)ill開頭的填充圖形。
創(chuàng)建畫紙并繪制位圖
Dim?畫紙?As?Graphics?=?Me.CreateGraphics()
畫紙.DrawImage(位圖,?100,?100,?256,?256)
可以將上面三行放到Form1_Load中測試,把路徑改一下,
還可以把Me改為能在上面繪圖的控件的名稱。
更多內(nèi)容請看MSDN的System.Drawing命名空間。
如滿意,請采納,謝謝。
下面的例子通過重載Form 窗體的OnPaint()方法繪制GDI圖形Protected Overrides Sub onpaint(ByVal e As System Windows Forms PaintEventArgs)注釋 /////////////繪制任意直線Dim g As Graphics = e GraphicsDim mypen As Pen = New Pen(Color Red )g DrawLine(mypen )注釋 /////////////繪制矩形(任意直線構(gòu)成的封閉圖形)Dim point As PointF = New PointF( F F)Dim point As PointF = New PointF( F F)Dim point As PointF = New PointF( F F)Dim point As PointF = New PointF( F F)Dim curvepoints As PointF() = {point point point point }g DrawPolygon(New Pen(Color Blue ) curvepoints)注釋 ////////////文本表示Dim FFamily As FontFamily = New FontFamily( Arial )Dim font As Font = New Font(FFamily FontStyle Bold FontStyle Italic GraphicsUnit Pixel)Dim text As String = I love you! Dim solidbrush As SolidBrush = New SolidBrush(Color Red)Dim pr As PointF = New PointF( )e Graphics DrawString(text font solidbrush pr)注釋 ////////////平面繪制Dim rec As RectangleF = New RectangleF( )g DrawPie(mypen rec )注釋 ///////////封閉圖形 應該是個圓g DrawClosedCurve(mypen curvepoints Drawing Drawing D FillMode Alternate)注釋 ///////////大家自己試試看吧g DrawArc(mypen )g DrawCurve(mypen curvepoints)g DrawBezier(mypen )g DrawBeziers(mypen curvepoints)注釋 //////////這可是一個圓Dim rec As RectangleF = New RectangleF( )g DrawEllipse(mypen rec )注釋 //////////這是一個橢圓Dim rec As RectangleF = New RectangleF( )g DrawEllipse(mypen rec )End Sub 這些是我自己試驗出來的 當然了 還有好多 我只是開了一個頭 大家要是發(fā)現(xiàn)什么好東東 別忘了通知一下 ) lishixinzhi/Article/program/net/201311/11800
不用PictureBoxTest.Image屬性,直接把圖形繪制到PictureBoxTest上面就可以了。
Dim?button?As?Integer?=?0
Private?Sub?Button1_Click(ByVal?sender?As?Object,?ByVal?e?As?EventArgs)?_
Handles?Button1.Click
Using?g?As?Graphics?=?Graphics.FromHwnd(PictureBoxTest.Handle)
Dim?penRed?As?Pen?=?New?Pen(Color.Red,?1)?????'定義紅色畫筆??
Dim?penblue?As?Pen?=?New?Pen(Color.Blue,?1)?'定義藍色畫筆?
If?button?=?0?Then
g.DrawLine(penRed,?0,?0,?100,?100)
button?=?1
ElseIf?button?=?1?Then
g.DrawLine(penblue,?100,?100,?200,?200)
button?=?0
End?If
End?Using
End?Sub
button , OpenFileDialog , PictureBox , textbox 控件,我把圖片顯示在 picturebox 中,而路
徑存放在 textbox 中,不知道這樣行不行。
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim filename As String
OpenFileDialog1.Filter = "jpg files (*.jpg)|*.jpg"
OpenFileDialog1.FilterIndex = 1
If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
filename = OpenFileDialog1.FileName
Else
End
End If
If Not (PictureBox1.Image Is Nothing) Then
PictureBox1.Image.Dispose()
PictureBox1.Image = Nothing
End If
'PictureBox1.Image = System.Drawing.Image.FromFile(filename)
去掉注釋后就顯示圖片
TextBox1.Text = filename
End Sub
picturebox中只記錄文件存放的路徑,我找了一個 ImageLocation 函數(shù)
PictureBox1.ImageLocation = filename 不過還是會顯示圖片
你好哦樓主~
很高興看到你的問題。
但是又很遺憾到現(xiàn)在還沒有人回答你的問題。也可能你現(xiàn)在已經(jīng)在別的地方找到了答案,那就得恭喜你啦。
可能是你問的問題有些專業(yè)了,沒人會。或者別人沒有遇到或者接觸過你的問題,所以幫不了你。建議你去問題的相關論壇去求助,那里的人通常比較多,也會比較熱心,能快點幫你解決問題。
希望我的回答能夠幫到你!
祝你好運。。