473,406 Members | 2,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

clear backstyle for lable control?

JD
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
Nov 21 '05 #1
3 2108
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(DesignerSerializat ionVisibility.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


Nov 21 '05 #2
JD
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 andcopy/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 SubInitializeComponent()
'
'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() AsBoolean
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 AsSystem.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 eAs System.EventArgs) Handles MyBase.Load
setstyle(ControlStyles.AllPaintingInWmPaint, True) setstyle(ControlStyles.DoubleBuffer, True)
setstyle(ControlStyles.UserPaint, True)
End Sub
End Class


.

Nov 21 '05 #3
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
Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Lukelrc | last post by:
Hi, I have a listfield that displays a list of 'Themes' stored in a database. The listfield's lable is Themenames and it's value is UniqueThemeID. The page that i'm designing allows the user to...
1
by: Christopher Shanahan | last post by:
Hello, I've built a data entry form for a survey database that appears to make the entire form flicker when I mouse over anyn of the label controls. I suspect that it has to do with the...
1
by: John Phelan-Cummings | last post by:
When I add the name of a new individual in a, bound form, it will not display that person’s name in a label control of a second unbound form. I have a scheduling program that I am working on. ...
1
by: Prashwee | last post by:
Hi All Just a small problem. I am using DataGridView control for my project implementing in VB 2005. I need to resize my column header lable withd dyamically so that the user can see the lable...
5
by: iKiLL | last post by:
Hi All, I am trying to Bulid Windows Mobile Forms Control with C# in VS2005 using CF2. On this control A lable is created and some text set for the control. My problem is that i dont know how...
0
by: Ryan Liu | last post by:
Hi, In VS 2005, in design view, if I put a lable on a windows form, and set label Text to "", then this label will totally invisiable. This is right at runtime, but I remember in VS 2003, it...
0
by: Wayne | last post by:
The tab control "backstyle" property refuses to work when set to "transparent" in an A2003 database if Windows themes controls are being used. I've seen references to this in a few places, but no...
2
by: ravindarjobs | last post by:
Hi friends i want to generate UPS label from my asp.net C# code. i have UPS account, online tools information with me. but dont know where to start to develop. can any one plz give a link that...
12
NeoPa
by: NeoPa | last post by:
I have a project I'm working on where I want to disable editing on a form in certain circumstances. To avoid confusing the operator, I would like to change the appearance of the form so that is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.