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 3 2127
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
'TransparentLab el' which will be transparent:
Imports System.Componen tModel
Public Class TransparentLabe l
Inherits System.Windows. Forms.UserContr ol
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeCompo nent()
'Add any initialization after the InitializeCompo nent() 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.Disp ose()
End If
End If
MyBase.Dispose( disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.Componen tModel.IContain er
'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.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()
'
'TransparentLab el
'
Me.BackColor = System.Drawing. Color.DeepPink
Me.Name = "TransparentLab el"
Me.Size = New System.Drawing. Size(256, 46)
End Sub
#End Region
Private Txt As String
Private AutoSze As Boolean = True
<Bindable(True) , Category("Appea rance"), _
DesignerSeriali zationVisibilit y(DesignerSeria lizationVisibil ity.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("Beha vior"), DefaultValue(Tr ue)> 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 TransparentLabe l_Paint(ByVal sender As Object, ByVal e As
System.Windows. Forms.PaintEven tArgs) Handles MyBase.Paint
Try
If AutoSze = True Then
Dim Siz As Drawing.SizeF = e.Graphics.Meas ureString(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.FromIm age(B)
G.FillRectangle (New SolidBrush(Colo r.DeepPink), New Rectangle(0,
0, Me.Width, Me.Height))
G.DrawString(Tx t, Font, New SolidBrush(Me.F oreColor), 0, 0)
Dim Pth As New Drawing2D.Graph icsPath()
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.ToStr ing =
Color.DeepPink. ToArgb.ToString Then
Pth.AddRectangl e(New Rectangle(X, Y, 1, 1))
End If
Next
Next
G.FillRectangle (New SolidBrush(Me.F oreColor), New Rectangle(0,
0, Me.Width, Me.Height))
e.Graphics.Draw Image(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 OnForeColorChan ged(ByVal e As System.EventArg s)
Me.Refresh()
End Sub
Private Sub TransparentLabe l_Load(ByVal sender As System.Object, ByVal e
As System.EventArg s) Handles MyBase.Load
setstyle(Contro lStyles.AllPain tingInWmPaint, True)
setstyle(Contro lStyles.DoubleB uffer, True)
setstyle(Contro lStyles.UserPai nt, True)
End Sub
End Class
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'TransparentLa bel' which will be transparent:
Imports System.Componen tModel
Public Class TransparentLabe l Inherits System.Windows. Forms.UserContr ol
#Region " Windows Form Designer generated code "
Public Sub New() MyBase.New()
'This call is required by the Windows Form
Designer. InitializeCompo nent()
'Add any initialization after the
InitializeCompo nent() 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.Disp ose() End If End If MyBase.Dispose( disposing) End Sub
'Required by the Windows Form Designer Private components As
System.Componen tModel.IContain er '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.Diagnos tics.DebuggerSt epThrough()> Private
SubInitializeComp onent() ' 'TransparentLab el ' Me.BackColor = System.Drawing. Color.DeepPink Me.Name = "TransparentLab el" Me.Size = New System.Drawing. Size(256, 46)
End Sub
#End Region
Private Txt As String Private AutoSze As Boolean = True
<Bindable(True) , Category("Appea rance"), _ DesignerSeriali zationVisibilit y
(DesignerSerial izationVisibili ty.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("Beha vior"), DefaultValue(Tr ue)> Public
Property AutoSize() AsBoolean Get Return AutoSze End Get Set(ByVal Value As Boolean) AutoSze = Value Me.Refresh() End Set End Property
Private Sub TransparentLabe l_Paint(ByVal sender As
Object, ByVal e AsSystem.Windows .Forms.PaintEve ntArgs) Handles MyBase.Paint Try If AutoSze = True Then Dim Siz As Drawing.SizeF =
e.Graphics.Meas ureString(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.FromIm age(B) G.FillRectangle (New SolidBrush
(Color.DeepPink ), New Rectangle(0,0, Me.Width, Me.Height)) G.DrawString(Tx t, Font, New SolidBrush
(Me.ForeColor), 0, 0) Dim Pth As New Drawing2D.Graph icsPath() 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.ToStr ing
=Color.DeepPink .ToArgb.ToStrin g Then Pth.AddRectangl e(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.Draw Image(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 OnForeColorChan ged(ByVal e
As System.EventArg s) Me.Refresh() End Sub
Private Sub TransparentLabe l_Load(ByVal sender As
System.Object, ByVal eAs System.EventArg s) Handles MyBase.Load setstyle(Contro lStyles.AllPain tingInWmPaint,
True) setstyle(Contro lStyles.DoubleB uffer, True) setstyle(Contro lStyles.UserPai nt, True) End Sub End Class .
JD,
Maybe this is easier to understand.
\\\
Panel1.BackColo r = Color.Yellow
Label1.BackColo r = Color.Transpare nt
Label1.ForeColo r = Color.Red
Label1.Text = "Hello JD"
////
I hope this helps,
Cor This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 add or
remove Themes to this list which updates the database.
When the user adds a theme i can use the UniqueThemeID (which is
passed when the form is submitted) to display a page saying that "The
theme *Themename* has been added to the...
|
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 standard hyperlink function embedded
all label control, even though I am not using it. The refresh/redraw flicker
is quite annoying and distracting, making data entry on a tablet difficult
for the user.
|
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. Included in the
application program is a data “GRID” which I believe was created using
Visual Basic, not standard Access. Its purpose is to display the
results of a range of “from-to-dates” of registrations for different
clients. The difficulty...
|
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 text as a whole when i enter headers text dynamically.
What is the property that i need to set here?
Thanks in advance
Prash
|
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 lond the text is going to be. so i need to
set the height and width of the label a cording to the data.
un fortunatly i have not been able to find a simple Auto Resize property
| |
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 used to show a place holder. Without
it, really hard to know there is a lable on there.
I am using Simplified Chinese version since I guess it might has better
support for Chinese characters I used in my application.
|
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
fix. If the A2003 database is opened using A2007 the property works
fine. Go figure. Does anyone know of a workaround?
|
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 helps me out.
thank you
Ravindar
|
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 visually different between the two modes. A sort of visual clue if you like.
I developed the following code, but I find that this won't compile (to my surprise) :
Private Sub chkLocked_AfterUpdate()
Dim ctl As Object 'Same problem if done...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |