Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Transparent Form
- All Borders/Control Boxes to None
- .StartPosition = Manual
- .TransparncyKey = WhiteSmoke
- .BackColor = WhiteSmoke
- .ShowInTaskbar = False
- Public Class TForm
- Private _Text As String
- Private TextPosition As Point
- Private _Brush As SolidBrush = New SolidBrush(Color.White)
- Private _Flags As StringFormatFlags = StringFormatFlags.NoWrap
- Public Enum Alignment
- Left = 0
- Right = 1
- Center = 2
- End Enum
- Public Sub New()
- InitializeComponent()
- End Sub
- Public Overrides Property Text() As String
- Get
- Return Me._Text
- End Get
- Set(ByVal value As String)
- _Text = value
- Me.Invalidate()
- End Set
- End Property
- Public Property OverlayPosition As Alignment
- Private Sub TForm_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
- e.Graphics.TextRenderingHint = Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit
- e.Graphics.TextContrast = 12
- Dim _Size As SizeF = e.Graphics.MeasureString(Me._Text, Me.Font,
- New SizeF(Me.Width, Me.Height),
- New StringFormat(Me._Flags))
- e.Graphics.DrawString(Me._Text, Me.Font, Me._Brush, New RectangleF(TextAlign(_Size.Width), _Size))
- End Sub
- Private Sub TForm_ForeColorChanged(sender As Object, e As EventArgs) Handles Me.ForeColorChanged
- Me._Brush = New SolidBrush(Me.ForeColor)
- Me.Invalidate()
- End Sub
- Public Sub Reposition(ParentPosition As Point, ParentSize As Size)
- Select OverlayPosition
- Case Alignment.Left
- Me.Location = New Point(ParentPosition.X + 20, ParentPosition.Y + 40)
- Case Alignment.Right
- Me.Location = New Point(ParentSize.Width - Me.Width - 20, ParentPosition.Y + 40)
- Case Alignment.Center
- Me.Location = New Point(ParentPosition.X + 20 + (ParentSize.Width \ 2) - (Me.Width \ 2), ParentPosition.Y + 40)
- End Select
- End Sub
- Private Function TextAlign(TextWidth As Single) As PointF
- Select Case OverlayPosition
- Case Alignment.Left
- Return New PointF(1, 1)
- Case Alignment.Right
- Return New PointF((Me.Width - TextWidth) - 1, 1)
- Case Alignment.Center
- If TextWidth > Me.Width Then TextWidth = Me.Width - 2
- Return New PointF(CSng((Me.Width - TextWidth) / 4) - 1, 1)
- End Select
- End Function
- End Class
- ----------------------------------------------------------------------
- Changes to the Hosting Form:
- Public Class Form1
- Private Overlay As New TForm
- Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
- Me.MinimumSize = New Size(200, 100)
- Overlay.Size = Me.MinimumSize
- Overlay.OverlayPosition = TForm.Alignment.Center
- Overlay.Reposition(Me.Location, Me.Size)
- //Set the Text Property to show the Overlay Title
- Overlay.Text = "Picture Title"
- Overlay.Show(Me)
- Overlay.Visible = False
- End Sub
- Private Sub Form1_Move(sender As Object, e As EventArgs) Handles Me.Move
- Overlay.Reposition(Me.Location, Me.Size)
- End Sub
- Private Sub Form1_Resize(sender As Object, e As EventArgs) Handles Me.Resize
- Overlay.Reposition(Me.Location, Me.Size)
- End Sub
- Private Sub Form1_Shown(sender As Object, e As EventArgs) Handles Me.Shown
- ShowOverlay(300)
- End Sub
- Private Async Sub ShowOverlay(Delay As Integer)
- Await Task.Delay(Delay)
- Overlay.Visible = True
- Me.Focus()
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment