![](/img/trans.png)
[英]How to get contents of a directory without including system/hidden files in vb.net?
[英]vb.NET - How to Get boundary of GraphicsPath without including Bezier handle locations
我正在嘗試圍繞 GraphicsPath 設置邊界以便於調整組大小。 這很好用,但是當我將其中一個點轉換為貝塞爾曲線時,它包括邊界內貝塞爾曲線圖柄的位置,從而使選擇矩形比預期的大得多。
這是第一次創建路徑時的樣子,默認情況下,點只是沒有貝塞爾曲線的線。 選擇矩形按預期工作。
當我雙擊一個點時,它會自動將點轉換為貝塞爾曲線(或者如果是貝塞爾曲線,則切換回直線),然后選擇矩形也會在路徑中反映手柄點。
如您所見,它應該在貝塞爾曲線下方的矩形停止,但它似乎也擴展到手柄。
這是做矩形周邊的代碼。
公共重寫 Sub DrawSelectionRectangle(ByVal g As Graphics) SelectionRectangle = New RectangleF(0, 0, 0, 0)
將 GP 調暗為 GraphicsPath = _lastGp 'DAVE
If GP IsNot Nothing Then If _lastGp.PointCount > 1 Then Try Dim BH As New Single: Dim TH As New Single: Dim LW As New Single: Dim RW 作為新單曲
TH = GP.PathPoints(0).Y
LW = GP.PathPoints(0).X
For i = 0 To GP.PathPoints.Length - 1
With GP.PathPoints(i)
If .Y < TH Then TH = .Y
If .X < LW Then LW = .X
If .Y > BH Then BH = .Y
If .X > RW Then RW = .X
End With
Next i
'DAVE - This code won't work as it doesn't factor in for space made by the actual bezier curves, GP path must be followed. BUT! this is a tidier solution.
'SelectionRectangle = New RectangleF(0, 0, 0, 0)
'If _pointArray IsNot Nothing Then
' If _pointArray.Count > 1 Then
' Try
' Dim BH As New Single : Dim TH As New Single : Dim LW As New Single : Dim RW As New Single
' LW = _pointArray(0).P.X
' TH = _pointArray(0).P.Y
' For i = 0 To _pointArray.Count - 1
' With _pointArray(i).P
' If .Y < TH Then TH = .Y
' If .X < LW Then LW = .X
' If .Y > BH Then BH = .Y
' If .X > RW Then RW = .X
' End With
' Next i
'=================================
SelectionRectangle = New RectangleF(New PointF(LW, TH), New SizeF(RW - LW, BH - TH))
Dim r As RectangleF = DrawRectangle.GetNormalizedRectangle(SelectionRectangle)
Dim gpen As Pen = New Pen(Color.Gray, MyBase.StrokeWidth)
gpen.DashStyle = DashStyle.Dash
g.DrawRectangle(gpen, r.X, r.Y, r.Width, r.Height)
gpen.Dispose()
Catch ex As Exception
ErrH.Log("DrawSelectionRectangle", "Draw", ex.ToString(), ErrH._LogPriority.Info)
End Try
End If
萬一
結束子
對簡單解決方案的任何幫助將不勝感激。 :)
我試過使用實際的點數組作為參考,但這並沒有考慮到貝塞爾曲線拋出的曲線。 如果運行上述注釋代碼,請參見示例。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.