|
-
Oct 12th, 2011, 08:00 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] label transparency
i'm trying to place a label with "backcolor = color.transparent" over a progressbar, but it seems that the progressbar becomes transparent too, how can i avoid this?
-
Oct 12th, 2011, 08:09 AM
#2
Fanatic Member
If debugging is the process of removing bugs, then programming must be the process of putting them in.
-
Oct 12th, 2011, 08:16 AM
#3
Thread Starter
Fanatic Member
Re: label transparency
i replied to the other topic by accident
progress bar is not a container, therefore this doesn't work. (just tested, apparently it changes the forecolor to blue..)
-
Oct 12th, 2011, 09:10 AM
#4
New Member
Re: label transparency
Hello, new guy here but I have been coding for a year now on my own time so work with me 
Only way you can do this is too draw it on the progressbar.
Code:
Private Sub SetProgressBarText(ByVal Target As System.Windows.Forms.ProgressBar, ByVal Text As String, ByVal Location As ProgressBarTextLocation, ByVal TextColor As System.Drawing.Color, ByVal TextFont As System.Drawing.Font)
If Target Is Nothing Then
Throw New ArgumentException("Null Target")
End If
If String.IsNullOrEmpty(Text) Then
Dim percent As Integer = CInt(Math.Truncate((CDbl(Target.Value - Target.Minimum) / CDbl(Target.Maximum - Target.Minimum)) * 100))
Text = percent.ToString() & "%"
End If
Using gr As Graphics = Target.CreateGraphics()
gr.DrawString(Text, TextFont, New SolidBrush(TextColor), New PointF(If(Location = ProgressBarTextLocation.Left, 5, ProgressBar1.Width / 2 - (gr.MeasureString(Text, TextFont).Width / 2.0F)), ProgressBar1.Height / 2 - (gr.MeasureString(Text, TextFont).Height / 2.0F)))
End Using
End Sub
Public Enum ProgressBarTextLocation
Left
Centered
End Enum
Example:
Code:
SetProgressBarText(ProgressBar1, "50%", ProgressBarTextLocation.Centered, Color.Black, New Font(Font.Name, 12, FontStyle.Regular))
'Note it will not work on form load
-
Oct 12th, 2011, 09:30 AM
#5
Thread Starter
Fanatic Member
Re: label transparency
welcome to the forum, willrulz188!
this is one way of doing it, but if the progress bar updates too quickly, the numbers will get mixed up with previous numbers... is there a way to fix that?
-
Oct 12th, 2011, 10:00 AM
#6
New Member
Re: label transparency
Well, seeing how your drawing on the progressbar it will always be a little slower but I can cut it down so it is a little faster.
Code:
Private Sub SetProgressBarText(ByVal Location As ProgressBarTextLocation)
Using gr As Graphics = ProgressBar1.CreateGraphics()
gr.DrawString(ProgressBar1.Value & "%", New Font(Font.Name, 10, FontStyle.Regular), New SolidBrush(Color.Black), New PointF(If(Location = ProgressBarTextLocation.Left, 5, ProgressBar1.Width / 2 - (gr.MeasureString(ProgressBar1.Value, New Font(Font.Name, 10, FontStyle.Regular)).Width / 2.0F)), ProgressBar1.Height / 2 - (gr.MeasureString(ProgressBar1.Value, New Font(Font.Name, 10, FontStyle.Regular)).Height / 2.0F)))
End Using
End Sub
Public Enum ProgressBarTextLocation
Left
Centered
End Enum
I had too merge most of the code making it just run instead of trying to find the values.
Code:
SetProgressBarText(ProgressBarTextLocation.Centered)
'wouldn't let me cut it down any more
What I would do is declare setprogressbartext first (before giving progressbar1 its value) to give it time to load.
It's about 30% faster.
This is the fastest I can make it sorry.
-
Oct 12th, 2011, 11:34 AM
#7
Thread Starter
Fanatic Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|