|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
clear backstyle for lable control?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 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 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----- label controls of type >Yes it is possible. Add a new user control file to your project and >copy/replace the following code. You now can create Show quoteHide quote >'TransparentLabel' which will be transparent: disposing As Boolean)> > >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 > If disposing Then System.ComponentModel.IContainer> 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 > Windows Form Designer> 'NOTE: The following procedure is required by the Show quoteHide quote > 'It can be modified using the Windows Form Designer. Property AutoSize() As > '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 >Boolean Object, ByVal e As > 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 >System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint e.Graphics.MeasureString(Txt, > Try > If AutoSze = True Then > Dim Siz As Drawing.SizeF = >Font) (Color.DeepPink), New Rectangle(0, > 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 >0, Me.Width, Me.Height)) (Me.ForeColor), 0, 0)> G.DrawString(Txt, Font, New SolidBrush > Dim Pth As New Drawing2D.GraphicsPath() (X, Y, 1, 1))> 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 > End If (Me.ForeColor), New Rectangle(0, > Next > Next > G.FillRectangle(New SolidBrush >0, Me.Width, Me.Height)) Me.Width, Me.Height))> e.Graphics.DrawImage(B, 0, 0) > Dim Rgn As New Region(New Rectangle(0, 0, > Rgn.Exclude(Pth) As System.EventArgs)> Me.Region = Rgn > B.Dispose() > G.Dispose() > Catch > End Try > End Sub > > Protected Overrides Sub OnForeColorChanged(ByVal e > Me.Refresh() System.Object, ByVal e > End Sub > > Private Sub TransparentLabel_Load(ByVal sender As Show quoteHide quote >As System.EventArgs) Handles MyBase.Load > setstyle(ControlStyles.AllPaintingInWmPaint, True) > setstyle(ControlStyles.DoubleBuffer, True) > setstyle(ControlStyles.UserPaint, True) > End Sub >End Class > > > > > > >. > 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
Serialization questions
Code Execution Just Stops two dlls + arguments Cannot compile program written by another user on my PC Opening a file over the internet Hyperlinks Does anyone help me convert vb.net to c# Database filepath got overrided by OpenFiledialog??? formatting Dates? A few GDI+ U/I questions |
|||||||||||||||||||||||