Transparence in labels

  • Thread starter Thread starter C?sar F. Q?eb Montejo via DotNetMonster.com
  • Start date Start date
C

C?sar F. Q?eb Montejo via DotNetMonster.com

This question already has been done previously (Sorry if this disturb to you).

Scenery:

I have created a class based on a Label class. In this class I had made a Overrides to the OnPaintBackGround event (for allow the transparence).

Problem:

The problem is that the final user has the possibility of dragging the label by all the area of design and at the time of the drag & to drop, the text of the label is not understood or the traces of the label are seen.

Question:

Exists a way to avoid this problem, and avoid that the traces become displayed?. The Invalidate() instrucction don't works (for me).

Thank You in advance!
 
Hi,

I would make a class that inherits from label and use setstyle to
make it support a transparent background. Here is a quick example.


Move label on form

Dim WithEvents lbl As TransparentLabel

Dim bMovelbl As Boolean = False

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

lbl = New TransparentLabel

With lbl

..Location = New Point(10, 10)

..Text = "Move Me"

..BackColor = Color.Transparent

End With

Me.BackColor = Color.Green

Me.Controls.Add(lbl)

End Sub

Private Sub lbl_MouseDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles lbl.MouseDown

bMovelbl = True

End Sub

Private Sub lbl_MouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles lbl.MouseUp

bMovelbl = False

End Sub

Private Sub lbl_MouseMove(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles lbl.MouseMove

Static oldX, oldY As Integer

If bMovelbl Then

lbl.Location = New Point(lbl.Left + e.X - oldX, lbl.Top + e.Y - oldY)

Else

oldX = e.X

oldY = e.Y

End If

End Sub



Transparent Label class



Public Class TransparentLabel

Inherits Label



Public Sub New()

Me.SetStyle(ControlStyles.SupportsTransparentBackColor, True)

End Sub

End Class



Ken

-----------------------

"C?sar F. Q?eb Montejo via DotNetMonster.com" <[email protected]>
wrote in message This question already has been done previously (Sorry if this disturb to
you).

Scenery:

I have created a class based on a Label class. In this class I had made a
Overrides to the OnPaintBackGround event (for allow the transparence).

Problem:

The problem is that the final user has the possibility of dragging the label
by all the area of design and at the time of the drag & to drop, the text of
the label is not understood or the traces of the label are seen.

Question:

Exists a way to avoid this problem, and avoid that the traces become
displayed?. The Invalidate() instrucction don't works (for me).

Thank You in advance!
 
Thank You Ken,

The code supplied works like a charm! Only small adaptations (to verify the button of mouse pressed, etc)

Best regards
Cesar
 
Back
Top