jin katama

hello friends

may i know how to add text on progresssion bar while it displayed




Re: Visual Basic Express Edition display text on progression bar

HanneSThEGreaT

You can use e.Graphics.DrawString in the ProgressBar's Paint event

Here is a sample ( ok, it's much more than you need, because it shows how to make a gradient ProgressBar, along with the progression text displayed on it ), but you will get what I mean.

All you need to do, is to copy & paste this into your form :

Code Block

Imports System.Drawing

Imports System.Drawing.Drawing2D

Public Class Form1

Private Perc, perc3 As Single

Private message As String

Private Sub SetPercentComplete(ByVal percent As Single)

If percent < 0 Then percent = 100

Dim width As Integer = Math.Floor((Panel1.ClientRectangle.Width * percent) / 100)

Dim Height As Integer = Panel1.ClientRectangle.Height

If width > 0 AndAlso Height > 0 Then

If percent < 60 Then

Panel1.Invalidate(New Rectangle(Panel1.ClientRectangle.X, Panel1.ClientRectangle.Y, Panel1.Width, Panel1.Height))

Application.DoEvents()

End If

Panel1.Invalidate(New Rectangle(Panel1.ClientRectangle.X, Panel1.ClientRectangle.Y, width, Height))

End If

End Sub

Private Sub Panel1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint

If e.ClipRectangle.Width = 0 Then Exit Sub

Dim brBackground As New LinearGradientBrush(e.ClipRectangle, System.Drawing.Color.FromArgb(255, 0, 0), Color.FromArgb(0, 0, 255), LinearGradientMode.Horizontal)

Dim msg As String

Dim pos As Integer

e.Graphics.FillRectangle(brBackground, e.ClipRectangle)

If Perc < 0 Then

msg = message

Else

msg = Format(Perc, "0.00") & "%"

End If

pos = (msg.Length * Panel1.Font.SizeInPoints) / 2

e.Graphics.DrawString(msg, Panel1.Font, Brushes.White, (Panel1.Width / 2) - pos, (Panel1.Height / 2) - 10)

End Sub

Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick

If Perc < 0 Then

perc3 = perc3 + 10

If perc3 > 100 Then perc3 = 0

message = perc3.ToString() & "%"

SetPercentComplete(perc3)

Else

SetPercentComplete(Perc)

message = Perc.ToString() & "%"

End If

End Sub

Private Sub Form1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Click

Timer1.Enabled = True

End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Timer1.Interval = 100

Timer1.Enabled = False

message = "Ready"

Perc = -1

SetPercentComplete(Perc)

End Sub

I hope my reply was useful to you & everyone

Have a nice day!

Hannes





Re: Visual Basic Express Edition display text on progression bar

_Nightblade_

jin

what is the text sepose to represent.

amout of % of loading of both

or else

provide some more detail

Nightblade






Re: Visual Basic Express Edition display text on progression bar

jin katama

here is an example asume that my project get a installed fonts from the font folder

while geting the name of the font the

progression bar should display get font font name






Re: Visual Basic Express Edition display text on progression bar

HanneSThEGreaT

As I said Jin, use e.Graphics.DrawString inside the Paint event of your ProgressBar :

Code Block

e.Graphics.DrawString("Get Font Name", Panel1.Font, Brushes.White, (Panel1.Width / 2) - pos, (Panel1.Height / 2) - 10)





Re: Visual Basic Express Edition display text on progression bar

jin katama

no HanneSThEGreaT

it not working






Re: Visual Basic Express Edition display text on progression bar

HanneSThEGreaT

Ooops, yeah. As you can see in my first reply to this thread, I made a "custom progressbar", if you want to call it that. I've made use of a Panel to display the progression, similar to the progressbar. Have you tried my code in the first post All you needed to do was to copy & paste it. In there you will see that I actually was talking about the Panle's paint event, where you can use the DrawString method





Re: Visual Basic Express Edition display text on progression bar

_Nightblade_

Hannes

I have bin looking at your code do you know how i can use this code

that you have made to overide vista's progressbar so i imply it in

my projects and get that radient progressbar insted the green Vista.

i also noted that this progressbar is taking 10% steps and i have not

found out how to change it to 1% like the normal procedure for

progressbars.

It is working and I like the colors plus it it's changeble to what type of

color i want aswel. Something i wassent able to make unles i turned off

visualstyle but then about a gross off other item's are affected as wel.

Nightblade






Re: Visual Basic Express Edition display text on progression bar

HanneSThEGreaT

Hello Nightblade!

Thanx for you wonderful comments & questions

Let me answer as best as I can.

Code Block

The reason why this "progressbar" is stepping 10 % at a time is because of this sub :

Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick

If Perc < 0 Then

perc3 = perc3 + 10

If perc3 > 100 Then perc3 = 0

message = perc3.ToString() & "%"

SetPercentComplete(perc3)

Else

SetPercentComplete(Perc)

message = Perc.ToString() & "%"

End If

End Sub

If you were to look at the bolded line : perc3 = perc3 + 10

you will notice that I increment the perc3 variable with 10, once it reaches 100, it starts over again. If you were to change that statement to perc3 = perc3 + 1 you will step 1 % at a time. Yes, perc3 is not very descriptive variable name, sorry Smile

Concerning the Vista progressbar issue. Vista's progressbars are quite amazing, I should say. What I like most about them is that if you look closely, you'll see that it seems as if the "yellow" goes back and forth. With this next segment, I tried something similar ( it should be enough to get you started, because the whole logic would be more / less the same )

Put this into a UserControl, and add 1 label to the usercontrol. You can also Customize the background of the ProgressBar & Lable by setting the appropriate Properties. Once you have that in place, add this code :

Code Block

Imports System.Drawing

Imports System.Drawing.Drawing2D

Public Class DanaProgressBar

Inherits System.Windows.Forms.UserControl

Private min As Integer = 0 ' Minimum value for progress range

Private max As Integer = 100 ' Maximum value for progress range

Private val As Integer = 0 ' Current progress

Private GradForeColor As Color = Color.Orange ' Color of progress meter

Private GradBackColor As Color = Color.White 'background color

Private Perc As Integer = 0

Private LinMode As LinearGradientMode = LinearGradientMode.BackwardDiagonal

Private maxreached As Boolean = False

Private minreached As Boolean = True

Public Sub SetPercentComplete(ByVal percent As Integer)

Dim width As Integer = Math.Floor((Me.ClientRectangle.Width * percent) / 100)

Dim Height As Integer = Me.ClientRectangle.Height

If width > 0 AndAlso Height > 0 Then

Me.Invalidate(New Rectangle(Me.ClientRectangle.X, Me.ClientRectangle.Y, width, Height))

Label1.Text = Perc.ToString() & "%"

End If

End Sub

Protected Overrides Sub OnResize(ByVal e As EventArgs)

' Invalidate the control to get a repaint.

Me.Invalidate()

End Sub

Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)

If e.ClipRectangle.Width > 0 Then

If Perc > 0 Then

Dim brBackground As New LinearGradientBrush(e.ClipRectangle, GradBackColor, _

GradForeColor, LinMode)

e.Graphics.FillRectangle(brBackground, e.ClipRectangle)

Else

e.Graphics.FillRectangle(Brushes.White, e.ClipRectangle)

End If

End If

End Sub

Public Property GradMode() As LinearGradientMode

Get

Return LinMode

End Get

Set(ByVal Value As LinearGradientMode)

LinMode = Value

End Set

End Property

Public Property Minimum() As Integer

Get

Return min

End Get

Set(ByVal Value As Integer)

' Prevent a negative value.

If (Value < 0) Then

min = 0

End If

' Make sure that the minimum value is never set higher than the maximum value.

If (Value > max) Then

min = Value

min = Value

End If

' Make sure that the value is still in range.

If (val < min) Then

val = min

End If

' Invalidate the control to get a repaint.

Me.Invalidate()

End Set

End Property

Public Property Maximum() As Integer

Get

Return max

End Get

Set(ByVal Value As Integer)

' Make sure that the maximum value is never set lower than the minimum value.

If (Value < min) Then

min = Value

End If

max = Value

' Make sure that the value is still in range.

If (val > max) Then

val = max

End If

' Invalidate the control to get a repaint.

Me.Invalidate()

End Set

End Property

Public Property Percentage() As Integer

Get

Return Perc

End Get

Set(ByVal Value As Integer)

Dim PercGraph As Graphics = Me.CreateGraphics

If Not maxreached Then

Perc = Perc + Value

If Perc >= max Then

Perc = 100

PercGraph.Clear(Color.White)

SetPercentComplete(Value)

maxreached = True

minreached = False

End If

Else

Perc = Perc - Value

If Perc <= min Then

Perc = 0

PercGraph.Clear(Color.White)

SetPercentComplete(Value)

minreached = True

maxreached = False

End If

End If

End Set

End Property

Public Property Value() As Integer

Get

Return val

End Get

Set(ByVal Value As Integer)

Dim oldValue As Integer = val

' Make sure that the value does not stray outside the valid range.

If (Value < min) Then

val = min

ElseIf (Value > max) Then

val = max

Else

val = Value

End If

' Invalidate only the changed area.

Dim percent As Decimal

Dim newValueRect As Rectangle = Me.ClientRectangle

Dim oldValueRect As Rectangle = Me.ClientRectangle

' Use a new value to calculate the rectangle for progress.

percent = (val - min) / (max - min)

newValueRect.Width = newValueRect.Width * percent

' Use an old value to calculate the rectangle for progress.

percent = (oldValue - min) / (max - min)

oldValueRect.Width = oldValueRect.Width * percent

Dim updateRect As Rectangle = New Rectangle

' Find only the part of the screen that must be updated.

If (newValueRect.Width > oldValueRect.Width) Then

updateRect.X = oldValueRect.Size.Width

updateRect.Width = newValueRect.Width - oldValueRect.Width

Else

updateRect.X = newValueRect.Size.Width

updateRect.Width = oldValueRect.Width - newValueRect.Width

End If

updateRect.Height = Me.Height

' Invalidate only the intersection region.

Me.Invalidate(updateRect)

End Set

End Property

Public Property ProgressBarForeColor() As Color

Get

Return GradForeColor

End Get

Set(ByVal Value As Color)

GradForeColor = Value

' Invalidate the control to get a repaint.

Me.Invalidate()

End Set

End Property

Public Property ProgressBarBackColor() As Color

Get

Return GradBackColor

End Get

Set(ByVal Value As Color)

GradBackColor = Value

' Invalidate the control to get a repaint.

Me.Invalidate()

End Set

End Property

Private Sub Draw3DBorder(ByVal g As Graphics)

Dim PenWidth As Integer = Pens.White.Width

g.DrawLine(Pens.DarkGray, _

New Point(Me.ClientRectangle.Left, Me.ClientRectangle.Top), _

New Point(Me.ClientRectangle.Width - PenWidth, Me.ClientRectangle.Top))

g.DrawLine(Pens.DarkGray, _

New Point(Me.ClientRectangle.Left, Me.ClientRectangle.Top), _

New Point(Me.ClientRectangle.Left, Me.ClientRectangle.Height - PenWidth))

g.DrawLine(Pens.White, _

New Point(Me.ClientRectangle.Left, Me.ClientRectangle.Height - PenWidth), _

New Point(Me.ClientRectangle.Width - PenWidth, Me.ClientRectangle.Height - PenWidth))

g.DrawLine(Pens.White, _

New Point(Me.ClientRectangle.Width - PenWidth, Me.ClientRectangle.Top), _

New Point(Me.ClientRectangle.Width - PenWidth, Me.ClientRectangle.Height - PenWidth))

End Sub

End Class

Sorry about the Formatting of the code, I'm still new here

Compile the UserControl. After you've compiled it, you can reference its DLL in other projects.

About completely overriding Vista's ProgressBars, I'm not sure that that is possible, but I'll try to find out for you.

I hope my comments were useful to you & anyone else reading this thread

Hannes





Re: Visual Basic Express Edition display text on progression bar

_Nightblade_

Hannes

Thanks for your time and help you have spent on this.

your gradient bar is working fine in 1% steps.

i have 1 problem left that i can't fix

when it move over the drawn surfes it flashes white every

7% increas normaly i would have fixed it like

me.doublebufferd = true

in the load event but it is not working it keeps flashing

is there a other way to stop the flash

(white stripes over the buttom off the panel)

for the rest al about this progressbar is just cool and

changeble something i realy like

thanks for the help.

----------------------------------------------

the new sample you paste is confusing me.

when i read it, it only asks for a label so i give it one.

then there is just 1 line i don't understand.

Inherits System.Windows.Forms.UserControl

it is giving me a lot off trouble and if comment it out

and run it.

I end up with a form White background and a label saying "Label1"

Sins the other works i must be doing something wrong here.

What am i doing wrong.

Nightblade






Re: Visual Basic Express Edition display text on progression bar

jin katama

HELLO FRIENDS I CANNOT UNDERSTAND

pls explain me or what the coding is






Re: Visual Basic Express Edition display text on progression bar

_Nightblade_

jin

I have told you before that if you place

some code people can help you.

The way you are learning VB is not good.

this rate you will never become independent.

Out of your responce i assume you can't

read the code and know what it is doing.

So why don't you start a new project

place some button's labels and panels.

Then open the paint event try to make a shape.

then come back with some code and we

understand you better.

and tell you what you don't know and take step by step

true the code and then you will learn to work on

your one this is the same way ReneeC introduced

paint and drawing my one shape on any tool

Just start on your one whit something simple

and work your way up. We wil help you.

Nightblade






Re: Visual Basic Express Edition display text on progression bar

HanneSThEGreaT

Can I attach a sample here

Or perhaps email an example





Re: Visual Basic Express Edition display text on progression bar

jin katama

pls send me a sample project to my mail address or post it




Re: Visual Basic Express Edition display text on progression bar

HanneSThEGreaT

sent. Smile