VB.Net WinForms Form OnPaint () Transparency Update

In short, I'm trying to write some toast-style pop-up notifications (similar to Growl) that should appear next to the system tray and stack, if necessary.

I can handle an instance of / location / etc ... but I want to add an option for non-rectangular toasts. I would also like to have Alpha transparency, so the translucent PNG background on the toast shape will blend in with the desktop or the windows behind it.

So ... To get an obvious opportunity:

Form.TransparencyKey is not enough for my needs, because it is an all-or-nothing transparency effect that I want to get as a background or background at 50/50 in some places, 0/100 in others, 100/0 in others, etc. .

My initial approach is to override the OnBackgroundPaint () method, comment out the call to MyBase.OnBackgroundPaint, and use the graphic in eventargs to draw exactly what I want for the form.

This seems to work for starters - for now, I'm just drawing some kind of rectangle for testing, so PNG can create new difficulties, but I haven't received it yet.

What I could not do was update the graphics. The first time the form is rendered, it looks great as I expected (no border, only some rectangles floating on the desktop). If I move the windows behind the transparent window, the transparent window does not refresh / repaint

, Me.Invalidate(), , , - , ?

?

: Me.Invalidate() , - , , opccurs OVER - , 50% , 75% (50% + 50% , )

, Invalidate() s - , Graphics.Clear(Color), , - , , , Colors.Transparent . , , , " ", ,

- , :

Imports System.Drawing
Public Class TransparentForm

    Private Timer As Timers.Timer

    Private Sub TransparentForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Timer = New Timers.Timer
        AddHandler Timer.Elapsed, AddressOf Timer_Tick
        Timer.Interval = 100
        Timer.Start()
    End Sub

    Protected Overrides Sub OnPaintBackground(ByVal e As System.Windows.Forms.PaintEventArgs)
        ''MyBase.OnPaintBackground(e)
        Console.WriteLine("BackgroundPainted")
        For x = 0 To 9
            e.Graphics.FillRectangle(
                New SolidBrush(Color.FromArgb(CInt(x / 10 * 255), 127, 127, 127)),
                CInt(x * Me.Width / 10),
                0,
                CInt(Me.Width / 10),
                Me.Height
            )
        Next
    End Sub

    Sub Timer_Tick(ByVal sender As Object, ByVal e As EventArgs)
        Me.Invalidate()
    End Sub

    Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
        MyBase.OnPaint(e)
        Console.WriteLine("Painted")
    End Sub

    Protected Overrides Sub OnInvalidated(ByVal e As System.Windows.Forms.InvalidateEventArgs)
        MyBase.OnInvalidated(e)
        Console.WriteLine("Invalidated")
    End Sub

End Class
+5
1

CodeProject, , png "". , 50/50, Form.TransparencyKey.

codeproject. VB , .


VB.NET CodeProject, .
http://www20.zippyshare.com/v/86701716/file.html

, , .

+1

All Articles