PC Review


Reply
Thread Tools Rate Thread

clear backstyle for lable control?

 
 
JD
Guest
Posts: n/a
 
      3rd Apr 2005
Is it possible to have a clear backstyle for a lable
control? I want to write some text on a lable and I want
the background of the label to match the color of the
control I am placing the label on where the color of that
control will be changing will be changing. Is this
doable? If not, is there a control I can do this with? to
have a clear/see through backstyle?

Thanks,
JD
 
Reply With Quote
 
 
 
 
Qwert
Guest
Posts: n/a
 
      3rd Apr 2005
Yes it is possible. Add a new user control file to your project and
copy/replace the following code. You now can create label controls of type
'TransparentLabel' which will be transparent:


Imports System.ComponentModel

Public Class TransparentLabel
Inherits System.Windows.Forms.UserControl

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'UserControl1 overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
'
'TransparentLabel
'
Me.BackColor = System.Drawing.Color.DeepPink
Me.Name = "TransparentLabel"
Me.Size = New System.Drawing.Size(256, 46)

End Sub

#End Region

Private Txt As String
Private AutoSze As Boolean = True

<Bindable(True), Category("Appearance"), _
DesignerSerializationVisibility(DesignerSerializationVisibility.Visible),
_
Browsable(True)> _
Public Overrides Property Text() As String
Get
Return Txt
End Get
Set(ByVal Value As String)
Txt = Value
Me.Refresh()
End Set
End Property
<Category("Behavior"), DefaultValue(True)> Public Property AutoSize() As
Boolean
Get
Return AutoSze
End Get
Set(ByVal Value As Boolean)
AutoSze = Value
Me.Refresh()
End Set
End Property

Private Sub TransparentLabel_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
Try
If AutoSze = True Then
Dim Siz As Drawing.SizeF = e.Graphics.MeasureString(Txt,
Font)
Me.Width = Siz.Width + 1
Me.Height = Siz.Height + 1
End If
Dim B As New Bitmap(Me.Width, Me.Height)
Dim G As Graphics = Graphics.FromImage(B)
G.FillRectangle(New SolidBrush(Color.DeepPink), New Rectangle(0,
0, Me.Width, Me.Height))
G.DrawString(Txt, Font, New SolidBrush(Me.ForeColor), 0, 0)
Dim Pth As New Drawing2D.GraphicsPath()
Dim X, Y As Short
For X = 0 To Me.Width - 1
For Y = 0 To Me.Height - 1
If B.GetPixel(X, Y).ToArgb.ToString =
Color.DeepPink.ToArgb.ToString Then
Pth.AddRectangle(New Rectangle(X, Y, 1, 1))
End If
Next
Next
G.FillRectangle(New SolidBrush(Me.ForeColor), New Rectangle(0,
0, Me.Width, Me.Height))
e.Graphics.DrawImage(B, 0, 0)
Dim Rgn As New Region(New Rectangle(0, 0, Me.Width, Me.Height))
Rgn.Exclude(Pth)
Me.Region = Rgn
B.Dispose()
G.Dispose()
Catch
End Try
End Sub

Protected Overrides Sub OnForeColorChanged(ByVal e As System.EventArgs)
Me.Refresh()
End Sub

Private Sub TransparentLabel_Load(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles MyBase.Load
setstyle(ControlStyles.AllPaintingInWmPaint, True)
setstyle(ControlStyles.DoubleBuffer, True)
setstyle(ControlStyles.UserPaint, True)
End Sub
End Class






 
Reply With Quote
 
JD
Guest
Posts: n/a
 
      4th Apr 2005
Thanks. Will I be able to write text to this label? Do
I have to add a property to the class for this?

>-----Original Message-----
>Yes it is possible. Add a new user control file to your

project and
>copy/replace the following code. You now can create

label controls of type
>'TransparentLabel' which will be transparent:
>
>
>Imports System.ComponentModel
>
>Public Class TransparentLabel
> Inherits System.Windows.Forms.UserControl
>
>#Region " Windows Form Designer generated code "
>
> Public Sub New()
> MyBase.New()
>
> 'This call is required by the Windows Form

Designer.
> InitializeComponent()
>
> 'Add any initialization after the

InitializeComponent() call
>
> End Sub
>
> 'UserControl1 overrides dispose to clean up the

component list.
> Protected Overloads Overrides Sub Dispose(ByVal

disposing As Boolean)
> If disposing Then
> If Not (components Is Nothing) Then
> components.Dispose()
> End If
> End If
> MyBase.Dispose(disposing)
> End Sub
>
> 'Required by the Windows Form Designer
> Private components As

System.ComponentModel.IContainer
>
> 'NOTE: The following procedure is required by the

Windows Form Designer
> 'It can be modified using the Windows Form Designer.
> 'Do not modify it using the code editor.
> <System.Diagnostics.DebuggerStepThrough()> Private

Sub
>InitializeComponent()
> '
> 'TransparentLabel
> '
> Me.BackColor = System.Drawing.Color.DeepPink
> Me.Name = "TransparentLabel"
> Me.Size = New System.Drawing.Size(256, 46)
>
> End Sub
>
>#End Region
>
> Private Txt As String
> Private AutoSze As Boolean = True
>
> <Bindable(True), Category("Appearance"), _
> DesignerSerializationVisibility

(DesignerSerializationVisibility.Visible),
>_
> Browsable(True)> _
> Public Overrides Property Text() As String
> Get
> Return Txt
> End Get
> Set(ByVal Value As String)
> Txt = Value
> Me.Refresh()
> End Set
> End Property
> <Category("Behavior"), DefaultValue(True)> Public

Property AutoSize() As
>Boolean
> Get
> Return AutoSze
> End Get
> Set(ByVal Value As Boolean)
> AutoSze = Value
> Me.Refresh()
> End Set
> End Property
>
> Private Sub TransparentLabel_Paint(ByVal sender As

Object, ByVal e As
>System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
> Try
> If AutoSze = True Then
> Dim Siz As Drawing.SizeF =

e.Graphics.MeasureString(Txt,
>Font)
> Me.Width = Siz.Width + 1
> Me.Height = Siz.Height + 1
> End If
> Dim B As New Bitmap(Me.Width, Me.Height)
> Dim G As Graphics = Graphics.FromImage(B)
> G.FillRectangle(New SolidBrush

(Color.DeepPink), New Rectangle(0,
>0, Me.Width, Me.Height))
> G.DrawString(Txt, Font, New SolidBrush

(Me.ForeColor), 0, 0)
> Dim Pth As New Drawing2D.GraphicsPath()
> Dim X, Y As Short
> For X = 0 To Me.Width - 1
> For Y = 0 To Me.Height - 1
> If B.GetPixel(X, Y).ToArgb.ToString

=
>Color.DeepPink.ToArgb.ToString Then
> Pth.AddRectangle(New Rectangle

(X, Y, 1, 1))
> End If
> Next
> Next
> G.FillRectangle(New SolidBrush

(Me.ForeColor), New Rectangle(0,
>0, Me.Width, Me.Height))
> e.Graphics.DrawImage(B, 0, 0)
> Dim Rgn As New Region(New Rectangle(0, 0,

Me.Width, Me.Height))
> Rgn.Exclude(Pth)
> Me.Region = Rgn
> B.Dispose()
> G.Dispose()
> Catch
> End Try
> End Sub
>
> Protected Overrides Sub OnForeColorChanged(ByVal e

As System.EventArgs)
> Me.Refresh()
> End Sub
>
> Private Sub TransparentLabel_Load(ByVal sender As

System.Object, ByVal e
>As System.EventArgs) Handles MyBase.Load
> setstyle(ControlStyles.AllPaintingInWmPaint,

True)
> setstyle(ControlStyles.DoubleBuffer, True)
> setstyle(ControlStyles.UserPaint, True)
> End Sub
>End Class
>
>
>
>
>
>
>.
>

 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      4th Apr 2005
JD,

Maybe this is easier to understand.

\\\
Panel1.BackColor = Color.Yellow
Label1.BackColor = Color.Transparent
Label1.ForeColor = Color.Red
Label1.Text = "Hello JD"
////

I hope this helps,

Cor


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I place downloaded lable templates into word lable wizzard =?Utf-8?B?U2FkaWU=?= Microsoft Word Document Management 1 13th Apr 2007 12:05 AM
Setting BackStyle to Transperant for control from toolbox =?Utf-8?B?eW95b3NoYQ==?= Microsoft Powerpoint 0 8th Jun 2006 09:52 AM
Transparent Backstyle in Tab Control Not Working =?Utf-8?B?Q2hyaXM=?= Microsoft Access Forms 5 8th Feb 2006 03:15 AM
Tab Control Backstyle not changing to transparrent John Baker Microsoft Access Forms 2 23rd Jun 2005 05:25 AM
Tab control, themes and backstyle property Tony Wainwright Microsoft Access Forms 1 15th Sep 2004 06:55 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:27 PM.