日期:2014-05-19  浏览次数:21014 次

想给进度条上面加点文字
想给进度条上面加点文字,于是在上面放了个label,背景颜色设成透明,结果发现放到进度条上面透明效果没有了,还是把进度条遮住了,怎么能解决呢

------解决方案--------------------
up
------解决方案--------------------
一種笨的辦法:
將進度條的高度調得高過label的高度,則label只遮住部分
------解决方案--------------------
用程序自己画一个进度条,之后在上面写字
------解决方案--------------------
重绘...OnPaint...
------解决方案--------------------
用画上去的就不会了
------解决方案--------------------
自己写一个
------解决方案--------------------
计算比例画一个矩形,
然后再滚动条中间画一个文字就OK了
------解决方案--------------------
Taskvison中有几个技巧,综合一下就能出来了.
------解决方案--------------------
平滑渐变效果,有点类似于windows安装程序中的进度条
Private Sub dr(ByVal Wid As Integer,byval gr As Graphics )
Dim bmp As Bitmap = New Bitmap(Me.Width, Me.Height)
Dim bgr As Graphics = Graphics.FromImage(bmp)
bgr.Clip = New Region(New Rectangle(2, 2, Me.Width - 4, Me.Height - 4))
Mwidth = Wid
bgr.Clear(Me.BackColor)
If Wid <> 0 And Me.Height <> 0 Then
Dim rect As New Rectangle(0, 0, Wid, Me.Height / 2)
Dim lgb As New LinearGradientBrush(rect, Me.DarkColor, Me.HighColor, 90.0F)
bgr.FillRectangle(lgb, rect)
Dim rect1 As New Rectangle(0, Me.Height / 2, Wid, Me.Height / 2)
Dim lgb1 As New LinearGradientBrush(rect1, Me.HighColor, Me.DarkColor, 90.0F)
bgr.FillRectangle(lgb1, rect1)
lgb.Dispose()
If Me.Height > 12 Then
Dim persent As String
If Me.MaxNum = 0 Then
persent = " "
Else
Try
persent = CInt((Me.Value / Me.MaxNum) * 100) & "% "
Catch ex As Exception
MsgBox(ex.ToString)
End Try

End If
Dim sformat As New StringFormat
sformat.Alignment = StringAlignment.Near
Dim ws As SizeF = bgr.MeasureString(persent, Me.Font, Int32.MaxValue, StringFormat.GenericTypographic)
bgr.DrawString(persent, Me.Font, Brushes.Blue, New PointF((Me.Width - ws.Width) / 2, (Me.Height - ws.Height) / 2), sformat)
End If
End If
gr.DrawImage(bmp, 0, 0)
bgr.Dispose()
gr.DrawLine(Me.UpPen, 0, 0, Me.Width, 0)
gr.DrawLine(Me.UpPen, 0, 0, 0, Me.Height)
gr.DrawLine(Me.DownPen, 0, Me.Height, Me.Width, Me.Height)
gr.DrawLine(Me.DownPen, Me.Width, Me.Height, Me.Width, 0)
gr.Dispose()
bmp.Dispose()
End Sub

------解决方案--------------------
标记,备用。
------解决方案--------------------
Mark 学习了
------解决方案--------------------
另一种实现方法,不用继承ProgressBar

from
http://blog.sina.com.cn/u/589d32f5010009zk

using System.Runtime.InteropServices;

[DllImport( "user32.dll ")]
static extern IntPtr GetWindowDC(IntPtr hWnd);

[DllImport( "user32.dll ")]
static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);

public class SubWindow : NativeWindow