Rubrik: Oberfläche · Effekte | VB-Versionen: VB2008, VB2010, VB2012 | 10.04.13 |
Ergänzung zum Tipp: Einsatz einer DimmingForm Der Tipp beinhaltet eine Ergänzung des Tipps "Einsatz einer Dimmingform" und zwar dahingehend, dass mittels eines Texturebrush eine eigene Bitmap gewissermaßen "tiled" in den Hintergrund gezeichnet wird. | ||
Autor: Dietrich Herrmann | Bewertung: | Views: 6.962 |
ohne Homepage | System: WinXP, Win7, Win8, Win10, Win11 | Beispielprojekt auf CD |
Wenn Sie meinen Tipp Einsatz einer Dimmingform kennen und eventuell anwenden, dann ist diese Ergänzung sicher interessant. Im Weiteren schreibe ich die Ergänzungen des Formcodes in Bezug auf die entsprechenden Coderegionen auf.
Bitte ergänzen Sie in:
Region "Enumeration" ... Texture ...
Region "Variables" ... Private theTexBitmap As Bitmap = Nothing Private theRotation As RotateFlipType = Nothing ...
Region "Public properties" ... Public Property textureBitmap() As Bitmap Get Return theTexBitmap End Get Set(value As Bitmap) theTexBitmap = value End Set End Property Public Property textureBitmapRotation() As RotateFlipType Get Return theRotation End Get Set(value As RotateFlipType) theRotation = value End Set End Property ...
Region "Public methods" ... Case ShadowMode.Texture Dim rect As New Rectangle(New Point(0, 0), Me.ClientSize) Dim image As New Bitmap(Me.ClientSize.Width, Me.ClientSize.Height) Dim gr As Graphics = Graphics.FromImage(image) ' Initialisieren color matrix ' mit Wert 0.8 in Zeile 4, Spalte 4 wird das Image mit Wert von theOpacityMax transparent Dim matrixItems As Single()() = { _ New Single() {1, 0, 0, 0, 0}, _ New Single() {0, 1, 0, 0, 0}, _ New Single() {0, 0, 1, 0, 0}, _ New Single() {0, 0, 0, theOpacityMax, 0}, _ New Single() {0, 0, 0, 0, 1}} Dim colorMatrix As New ColorMatrix(matrixItems) ' erstellen von ImageAttributen zur color matrix Dim imageAtt As New ImageAttributes() imageAtt.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap) ' Bitmap als TextureBrush Dim img As Image = New Bitmap(textureBitmap) If Not IsNothing(theRotation) Then img.RotateFlip(theRotation) Dim theTBrush As New TextureBrush(img, New Rectangle(0, 0, img.Width, img.Height), imageAtt) theTBrush.WrapMode = WrapMode.Tile gr.FillRectangle(theTBrush, rect) gr.Dispose() theTBrush.Dispose() Me.BackgroundImage = image ...
Diese Code-Snippets an den entsprechenden Stellen des Form-Codes einfügen.
Zur Anwendung benötigt man natürlich eine entsprechende Bitmap, die als Texture für das Zeichnen verwendet wird. Am Besten man nimmt oder macht sich selbst eine, die eine Größe von 24x24 Bit hat. Ich liefere mit diesem Tipp eine Bitmap mit, die ein dunkles Streifenmuster erzeugt.
Man bereitet dann den Einsatz vor mit bspw.:
Randomize(Now.Ticks) Dim rot() As RotateFlipType = [Enum].GetValues(GetType(RotateFlipType)) With myDimmingForm .Owner = theSpecForm .ActiveShadowMode = .ShadowMode.Texture ' (meine Bitmap habe ich in den Resources des Projekts gespeichert) .textureBitmap = My.Resources.diag .textureBitmapRotation = rot(CInt(Math.Floor((rot.Length + 1) * Rnd()))) .Show() End With
Da man als Eigenschaft für die Dimmingform auch die Rotation der vorgegebenen Bitmap einstellen kann, habe ich im Beispiel die Rotation mal zufällig eingestellt.