Hi Dave
Nachtrag:
habe nun mal folgendes erstellt (über Sinnhaftigkeit läßt sich streiten):
Imports System.Runtime.CompilerServices
Module ControlExtensions
<Extension()>
Public Sub abrunden(ByVal ctl As Control, ByVal radius As Integer)
Dim gp As System.Drawing.Drawing2D.GraphicsPath = _
New System.Drawing.Drawing2D.GraphicsPath()
gp.AddLine(ctl.Left + radius, ctl.Top, ctl.Left + ctl.Width - radius, _
ctl.Top)
gp.AddArc(ctl.Left + ctl.Width - radius, ctl.Top, radius, radius, 270, _
90)
gp.AddLine(ctl.Left + ctl.Width, ctl.Top + radius, ctl.Left + _
ctl.Width, ctl.Top + ctl.Height - radius)
gp.AddArc(ctl.Left + ctl.Width - radius, ctl.Top + ctl.Height - radius, _
radius, radius, 0, 90)
gp.AddLine(ctl.Left + ctl.Width - radius, ctl.Top + ctl.Height, _
ctl.Left + radius, ctl.Top + ctl.Height)
gp.AddArc(ctl.Left, ctl.Top + ctl.Height - radius, radius, radius, 90, _
90)
gp.AddLine(ctl.Left, ctl.Top + ctl.Height - radius, ctl.Left, ctl.Top + _
radius)
gp.AddArc(ctl.Left, ctl.Top, radius, radius, 180, 90)
gp.CloseFigure()
ctl.Region = New System.Drawing.Region(gp)
gp.Dispose()
End Sub
<Extension()>
Public Sub ControlSize(ByVal ctl As Control, Optional ByVal x As Double = _
-1, Optional ByVal y As Double = -1, Optional ByVal w As Double = -1, _
Optional ByVal h As Double = -1)
If y <> -1 Then
ctl.Top = CInt(y)
End If
If x <> -1 Then
ctl.Left = CInt(x)
End If
If w <> -1 Then
ctl.Width = CInt(w)
End If
If h <> -1 Then
ctl.Height = CInt(h)
End If
End Sub
End Module Ich rufe dann folgendes auf:
Label1.Controlsize(10,10,100,100) 'klappt
Label1.abrunden(20) 'klappt nicht Wenn ich die Funktion "abrunden" für Label aufrufe, dann klappt das nicht, sprich das Label verschwindet.
Mach ich das selbe für ein Label mache, was ich selbst gebaut habe und dort in der Klasse auch die Funktion eingegeben habe, dann funktioniert es einwandfrei.
Beim durchbuggen der Funktion von oben, sind die Werte aber ok. Ist es wegen dem "zeichnen", das er als Extension-Funktion nicht macht?
Gruss Caddy |