FlowLayoutPanel Box选择帮助。 [英] FlowLayoutPanel Box selection help.
问题描述
$
所以我有一个flowLayoutPanel,可以加载目录中的所有文件,我希望能够点击并绘制一个框,或者使用一个新生成的表单,面板或使用.net框架的绘图功能,看起来类似于Windows资源管理器选择
框。
我已经尝试过解决方案从这里: https://stackoverflow.com/questions/32022010/how-to-draw-a-semi-transparent-rectangle-on-panel-containing-some-user-controls
第一个例子在一个鼠标移动方向上工作。
如果你们有什么建议请告诉我:)
问候郎
James
这是一个新的在Visual Basic中允许在任何方向上选择鼠标的示例。
如图所示,有一个流程面板和四个标签。所选标签会突出显示。
您可以根据具体需要对其进行修改。
Public Class Form6
Private mdPt,mmPt As Point
Private mdStatus As Integer
Private selectionRect As Rectangle
Private Sub Form6_Load(sender as Object ,e As EventArgs)Handles MyBase.Load
FlowLayoutPanel1.Padding = New Padding(10,20,10,20)
Label1.BackColor = Color.AliceBlue
Label2.BackColor = Color.AliceBlue
Label3.BackColor = Color.AliceBlue
Label4.BackColor = Color.AliceBlue
End Sub
Private Sub FlowLayoutPanel1_Paint(sender As Object,e As PaintEventArgs)处理FlowLayoutPanel1 .Paint
e.Graphics.FillRectangle(New SolidBrush(Color.FromArgb(100,Color.Red)),selectionRect)
End Sub
Private Sub FlowLayoutPanel1_MouseMove(sender As Object,e As MouseEventArgs)Handle FlowLayoutPanel1.MouseMove
mmPt = e.Location
如果mdStatus = 1则
GetSelection()
FlowLayoutPanel1.Invalidate()
End if
End Sub
Private Sub FlowLayoutPanel1_MouseDown(sender As Object,e As MouseEventArgs)处理FlowLayoutPanel1 .MouseDown
mdPt = e.Location
mdStatus = 1
End Sub
Private Sub FlowLayoutPanel1_MouseUp(sender As Object,e As MouseEventArgs)Handle FlowLayoutPanel1.MouseUp
mdStatus = 0
FlowLayoutPanel1.Invalidate()
End Sub
Private Sub GetSelection()
'从任何方向为点创建正确的rect和大小
Dim sz As New Size(mmPt.X - mdPt.X,mmPt.Y - mdPt.Y)
将thisRect调暗为矩形
如果mdStatus = 1则
Dim X As Integer = mdPt.X
Dim X1 As Integer = sz.Width
如果X1< 0然后
X1 = Math.Abs(X1)
X - = X1
结束如果
Dim Y As Integer = mdPt.Y
Dim Y1如Integer = sz.Height
如果Y1< 0然后
Y1 = Math.Abs(Y1)
Y - = Y1
结束如果
thisRect =新矩形(X,Y,X1,Y1)
其他
thisRect = selectionRect
结束如果
selectionRect = thisRect
'突出显示所选标签
For Each ctrl As Flow在FlowLayoutPanel1.Controls
如果selectionRect.IntersectsWith(ctrl.Bounds)那么
'ctrlList.Add(ctrl.Text& vbLf)
ctrl.BackColor = Color.Goldenrod
Else
ctrl.BackColor = Color.AliceBlue
End if
ctrl.Refresh()
Next
End Sub
End Class
hey guys!
so I have a flowLayoutPanel that loads up all the files in a directory and I want to be able click and draw a box either using a newly generated form, panel or using drawing capabilities of the .net framework that looks similar to the windows explorer selection
box.
I have already tried the solution from here: https://stackoverflow.com/questions/32022010/how-to-draw-a-semi-transparent-rectangle-on-panel-containing-some-user-controls
the first example works in one mouse movement direction.
If you guys have any suggestions please let me know :)
Regards
James
Here is a new example in Visual Basic that allows mouse selection in any direction.
There is a flow panel and four labels as shown. The selected labels are highlighted.
You can modify it for your exact needs.
Public Class Form6 Private mdPt, mmPt As Point Private mdStatus As Integer Private selectionRect As Rectangle Private Sub Form6_Load(sender As Object, e As EventArgs) Handles MyBase.Load FlowLayoutPanel1.Padding = New Padding(10, 20, 10, 20) Label1.BackColor = Color.AliceBlue Label2.BackColor = Color.AliceBlue Label3.BackColor = Color.AliceBlue Label4.BackColor = Color.AliceBlue End Sub Private Sub FlowLayoutPanel1_Paint(sender As Object, e As PaintEventArgs) Handles FlowLayoutPanel1.Paint e.Graphics.FillRectangle(New SolidBrush(Color.FromArgb(100, Color.Red)), selectionRect) End Sub Private Sub FlowLayoutPanel1_MouseMove(sender As Object, e As MouseEventArgs) Handles FlowLayoutPanel1.MouseMove mmPt = e.Location If mdStatus = 1 Then GetSelection() FlowLayoutPanel1.Invalidate() End If End Sub Private Sub FlowLayoutPanel1_MouseDown(sender As Object, e As MouseEventArgs) Handles FlowLayoutPanel1.MouseDown mdPt = e.Location mdStatus = 1 End Sub Private Sub FlowLayoutPanel1_MouseUp(sender As Object, e As MouseEventArgs) Handles FlowLayoutPanel1.MouseUp mdStatus = 0 FlowLayoutPanel1.Invalidate() End Sub Private Sub GetSelection() 'create proper rect from any direction for point and size Dim sz As New Size(mmPt.X - mdPt.X, mmPt.Y - mdPt.Y) Dim thisRect As Rectangle If mdStatus = 1 Then Dim X As Integer = mdPt.X Dim X1 As Integer = sz.Width If X1 < 0 Then X1 = Math.Abs(X1) X -= X1 End If Dim Y As Integer = mdPt.Y Dim Y1 As Integer = sz.Height If Y1 < 0 Then Y1 = Math.Abs(Y1) Y -= Y1 End If thisRect = New Rectangle(X, Y, X1, Y1) Else thisRect = selectionRect End If selectionRect = thisRect 'highlight selected labels For Each ctrl As Label In FlowLayoutPanel1.Controls If selectionRect.IntersectsWith(ctrl.Bounds) Then 'ctrlList.Add(ctrl.Text & vbLf) ctrl.BackColor = Color.Goldenrod Else ctrl.BackColor = Color.AliceBlue End If ctrl.Refresh() Next End Sub End Class
这篇关于FlowLayoutPanel Box选择帮助。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!