By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,865 Members | 1,304 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,865 IT Pros & Developers. It's quick & easy.

Moving Transparent Control

P: n/a
I wish to code a control that writes a text over a picturebox and that can
be dragged with mouse.

Here is what i've actually coded to obtain a similar effect, but as you can
see i've serious problems with trasparence

Create new project and add a button in the form and then insert a background
image to the form itself.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim NewTextLayer As New LayerText
With NewTextLayer
.Text = "Click Here!"
.ForeColor = Color.Blue
.Font = New Font("Arial Black", 20)
.Angle = 10

.Size = New System.Drawing.Size(200, 100)
.Location = New System.Drawing.Point(100, 30)
End With
End Sub
This is a class:
Imports System.Drawing
Imports System.Drawing.Drawing2D

Public Class LayerText : Inherits Control
Private _backBuffer As Bitmap
Private _angle As Single
Private dragPoint As Point

Public Property Angle() As Single
Return _angle
End Get
Set(ByVal Value As Single)
If _angle <> Value Then
_angle = Value
End If
End Set
End Property
Public Sub New()
SetStyle(ControlStyles.DoubleBuffer Or _
ControlStyles.AllPaintingInWmPaint Or
ControlStyles.UserPaint Or _
ControlStyles.Opaque, True)
End Sub
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
If BackgroundImage Is Nothing Then
If Not (Parent.BackgroundImage Is Nothing) Then
e.Graphics.DrawImage(Parent.BackgroundImage, _
New Rectangle(0, 0, Width, Height), _
Me.Left, Me.Top, Width, Height, GraphicsUnit.Pixel)
e.Graphics.FillRectangle(New SolidBrush(Parent.BackColor), _

New Rectangle(0, 0, Width, Height))
End If
End If

If _backBuffer Is Nothing Then
_backBuffer = New
End If

Dim nGraphics As Graphics = Nothing
nGraphics = Graphics.FromImage(_backBuffer)

With nGraphics

.SmoothingMode = SmoothingMode.HighQuality

.DrawString(Text, Font, New SolidBrush(ForeColor), New
End With

e.Graphics.DrawImageUnscaled(_backBuffer, 0, 0)
End Sub

Private Sub TextLayer_MouseDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) andles MyBase.MouseDown
If e.Button = MouseButtons.Left Then
dragPoint.X = e.X
dragPoint.Y = e.Y
End If
End Sub
Private Sub TextLayer_MouseMove(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
If e.Button = MouseButtons.Left Then
Location = New Point(Left + e.X - dragPoint.X, Top + e.Y -
End If
End Sub

End Class
Please any tips to enhance this code is welcomed
Thacks in andvance

Nov 20 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.