Re: Control.Region setzen

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hallo Karsten,

ich habe mal den Code Deines UserControls etwas verändert (s. '
#################), was dann schon zeigt, wo die Zeit beim Laden der Form
mit vielen UCs bleibt.

' \\\ Code UserControl
' ########################
Private mLoading As Boolean = True
' ########################

Private _Angle As Single = 130
Private _Controlsize As New Size(120, 28)
Private _TranslateTransform As PointF

Private Sub UserControl1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Console.WriteLine("Call SetRegion")
Call SetRegion()

' ##############
' ##############
mLoading = False
' ##############
' ##############

End Sub

Private Sub UserControl1_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles Me.Paint
e.Graphics.TranslateTransform(_TranslateTransform.X,
_TranslateTransform.Y)
e.Graphics.RotateTransform(_Angle)
Dim BM As New Bitmap(_Controlsize.Width + 4, _Controlsize.Height +
4)
Call DrawControl(BM)
e.Graphics.DrawImage(BM, 0, 0)
BM.Dispose()
End Sub

Private Sub DrawControl(ByRef BM As Bitmap)
Dim G_BM As Graphics = Graphics.FromImage(BM)
G_BM.FillRectangle(Brushes.Black, 2, 2, _Controlsize.Width,
_Controlsize.Height)
G_BM.Dispose()
End Sub

Private Sub SetRegion()
Dim BM As New Bitmap(_Controlsize.Width + 4, _Controlsize.Height +
4)
Dim G_BM As Graphics = Graphics.FromImage(BM)
G_BM.FillRectangle(Brushes.Black, 2, 2, _Controlsize.Width,
_Controlsize.Height)
Dim GP As New Drawing2D.GraphicsPath
GP.AddRectangle(New Rectangle(0, 0, _Controlsize.Width + 4,
ControlSize.Height + 4))
Dim M As New Drawing2D.Matrix
M.Rotate(_Angle)
GP.Transform(M)
Dim BM_Dest As New Bitmap(CInt(Math.Ceiling(GP.GetBounds.Width)),
CInt(Math.Ceiling(GP.GetBounds.Height)))
Dim G_BM_Dest As Graphics = Graphics.FromImage(BM_Dest)








G_BM_Dest.TranslateTransform(-CSng(Math.Ceiling(GP.GetBounds.X)), -CSng(Math
..Ceiling(GP.GetBounds.Y)))
G_BM_Dest.RotateTransform(_Angle)
G_BM_Dest.DrawImage(BM, 0, 0)
Dim GP_REG As New Drawing2D.GraphicsPath
GetRegionPath(GP_REG, BM_Dest)
_TranslateTransform.X = -CSng(Math.Ceiling(GP.GetBounds.X)) -
GP_REG.GetBounds.X()
_TranslateTransform.Y = -CSng(Math.Ceiling(GP.GetBounds.Y)) -
GP_REG.GetBounds.Y()
M = New Drawing2D.Matrix
M.Translate(-GP_REG.GetBounds.X, -GP_REG.GetBounds.Y)
GP_REG.Transform(M)
Me.Region = New Drawing.Region(GP_REG)
BM.Dispose()
G_BM.Dispose()
BM_Dest.Dispose()
G_BM_Dest.Dispose()
GP.Dispose()
GP_REG.Dispose()
M.Dispose()
End Sub

Private Sub GetRegionPath(ByRef GP As Drawing2D.GraphicsPath, ByVal BM
As Bitmap)
Dim BMD As New Drawing.Imaging.BitmapData
BMD = BM.LockBits(New Rectangle(0, 0, BM.Width, BM.Height),
Imaging.ImageLockMode.ReadOnly, BM.PixelFormat)
Dim ptr As IntPtr = BMD.Scan0
Dim rgbValues(BM.Width * BM.Height * 4 - 1) As Byte
System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0,
BM.Width * BM.Height * 4)
BM.UnlockBits(BMD)
For Y As Integer = 0 To BM.Height - 1
For X As Integer = 3 To BM.Width * 4 Step 4
If rgbValues(Y * BM.Width * 4 + X) <> 0 Then
GP.AddRectangle(New Rectangle(X \ 4, Y, 1, 1))
End If
Next
Next
End Sub

Public Property Angle() As Single
Get
Console.WriteLine(Me.Name & ": Get Angle")
Return _Angle
End Get
Set(ByVal value As Single)
_Angle = value


' ##################
' ##################
If Not mLoading Then
Console.WriteLine(Me.Name & ": Set Angle")
SetRegion()
Me.Invalidate()
End If
' ##################
' ##################
End Set
End Property

Public Property ControlSize() As Size
Get
Console.WriteLine(Me.Name & ": Get ControlSize")
Return _Controlsize
End Get
Set(ByVal value As Size)
_Controlsize = value

' ##################
' ##################
If Not mLoading Then
Console.WriteLine(Me.Name & ": Set ControlSize")
SetRegion()
Me.Invalidate()
End If
' ##################
' ##################

End Set
End Property

' \\\ E N T E


Wenn Du mal die beiden

If Not mLoading then
End If

in den Property-Prozeduren ControlSize und Angle auskommentierst, sodass

SetRegion()
Me.Invalidate()

ungebremst immer ausgeführt werden, dann wird schon sehr deutlich, wo die
Zeit beim Laden bleibt.

Gruß aus St.Georgen
Peter Götz
www.gssg.de (mit VB-Tips u. Beispielprogrammen)



.



Relevant Pages

  • Re: Solving Triangles
    ... If I know the length of one side and the angle at each ... >>> To get the rest of the angles, use the Law of Sines... ... > Private Sub CalcSAS(ByVal SideB As Double, ... > Dim SideA As Double ...
    (comp.lang.basic.visual.misc)
  • Re: Control.Region setzen
    ... Private _Controlsize As New Size ... Private Sub UserControl1_Paint(ByVal sender As Object, ... Dim G_BM As Graphics = Graphics.FromImage ... Public Property ControlSize() As Size ...
    (microsoft.public.de.german.entwickler.dotnet.vb)
  • Re: Modules not Known
    ... Dim pCode$ ... Dim pCodeModule As CodeModule ... Private Sub VBIDEReference() ... Option Compare Database ...
    (comp.databases.ms-access)
  • A VB6 program to generate CONSTants for a user defined gradient
    ... EndProperty ... It may be used for amy moral purpose. ... Dim mGreen1 As Long ... Private Sub ColorDisplay_MouseDown(Button As Integer, Shift As Integer, _ ...
    (comp.lang.basic.visual.misc)
  • Re: access 2003
    ... Dim ctl As Control ... Dim rs As Recordset ... This sets the query definitions for choosing data to create an invoice using ... Event on combo box: Private Sub ChooseCust_AfterUpdate ...
    (microsoft.public.access.conversion)