Mai avuto bisogno di una Form "particolare" ?
Su altro Forum questa mia soluzione ha avuto un certo successo, perciò eccola anche qui, per chiunque fosse interessato :
Public Class Form1
Public Sub New()
InitializeComponent()
Disegna()
End Sub
'Selezione e mouse
Private selezione As Boolean = False
Private eXSel As Integer = 0
Private eYSel As Integer = 0
Private Sub Disegna()
Dim rectArcoWidth As Integer = 60
Dim rectArcoHeight As Integer = 60
Dim contorno As New Drawing2D.GraphicsPath
contorno.StartFigure()
contorno.AddLine(CInt(rectArcoWidth / 2), 0, Me.Width - CInt(rectArcoWidth / 2), 0)
contorno.AddArc(Me.Width - rectArcoWidth, 0, rectArcoWidth, rectArcoHeight, -90, 90)
contorno.AddLine(Me.Width, CInt(rectArcoHeight / 2), Me.Width, Me.Height - CInt(rectArcoHeight / 2))
contorno.AddArc(Me.Width - rectArcoWidth, Me.Height - rectArcoHeight, rectArcoWidth, rectArcoHeight, 0, 90)
contorno.AddLine(Me.Width - CInt(rectArcoWidth / 2), Me.Height, CInt(rectArcoWidth / 2), Me.Height)
contorno.AddArc(0, Me.Height - rectArcoHeight, rectArcoWidth, rectArcoHeight, 90, 90)
contorno.AddLine(0, Me.Height - CInt(rectArcoHeight / 2), 0, CInt(rectArcoHeight / 2))
contorno.AddArc(0, 0, rectArcoWidth, rectArcoHeight, 180, 90)
contorno.CloseFigure()
Dim R As Region = New Region(New Rectangle(0, 0, Me.Width, Me.Height))
R.Intersect(contorno)
Me.Region = R
End Sub
Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
selezione = True
eXSel = e.X
eYSel = e.Y
End Sub
Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
If Me.selezione = True Then
Me.Left -= (Me.eXSel - e.X)
Me.Top -= (Me.eYSel - e.Y)
End If
End Sub
Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
Me.selezione = False
End Sub
End Class
1. Posso ottenere archi di curvatura anche ellittici, giocando con i due valori rectArcoWidth e rectArcoHeight. Unico requisito è avere la Form con FormBorderStyle = None. Il resto lo fa tutto il codice.
2. C'è già il codice per spostarla con il mouse.