Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 10-01-2009
Member
 
Join Date: Jan 2009
Posts: 25
Custom control implementation of a progress bar

hi
i am working on project where i want tips to create custom control progress bar . i tried to work on it but not well so please any one can help me to overcome of this. please help me .
thank you .
Reply With Quote
  #2  
Old 10-01-2009
Member
 
Join Date: Jan 2008
Posts: 1,515
Re: Custom control implementation of a progress bar

hi
Custom Progress Bar Using Visual Basic

Lightweight progress bar design:

A Label is one of the simplest Visual Basic controls. It is a graphical lightweight control, which requires fewer system resources than other Visual Basic controls. Lets build our progress bar using two Label controls.

Place the following Label controls at your Form:

1. The lblBack Label control will represent progress bar background. It is absolutely static. All properties for this control can be set at design time.
2. The lblFace Label control will represent face of our progress bar. Top, Left and Height properties should be the same as corresponding properties of the lblBack Label control. The Width property of the lblFace should be set to 0 at design time. It will be changed dynamically at runtime.

Set the following properties for both Label controls:

1. Appearance: 0 - Flat
2. BorderStyle: 1 - Fixed Single

You can choose other properties like Font, BackColor, ForeColor, etc. of these Label controls depending of your taste.
Progress bar implementation and Visual Basic code

Our progress bar will use a range, which can be specified by Min and Max Long integer values during initialization process, and internal counter, which will be used for progress visualization. Progress bar internal counter value is represented with the Long integer type variable and can be an integer value from 1 to 2,147,483,647. An absolute value of the range cannot exceed that value.

First of all we need to create some form level variables that will keep our progress bar state during calculations:

1. m_iMin - minimal range value. We will need it to calculate current progress position correctly.
2. m_iValue - current progress bar counter value, i.e. current progress position.
3. m_iMaxValue - maximal progress bar counter value. It will be calculated during initialization from the Min and Max range values.
4. m_sWidth - progress bar control width. It is the lblBack.Width value.

Private m_iMin As Long
Private m_iValue As Long
Private m_iMaxValue As Long
Private m_sWidth As Single

Now we need to create initialization code. Lets create InitProgress sub procedure. It takes two ByVal arguments that are minimal and maximal values of the progress range:

Private Sub InitProgress(ByVal iMin As Long, ByVal iMax As Long)

Save progress bar control width value and minimal range value:

m_sWidth = Me.lblBack.Width
m_iMin = iMin

Calculate maximal progress bar counter value. Minimal counter value is 1.

If iMin = 1 Then
m_iMaxValue = iMax
Else
m_iMaxValue = Abs(iMax - iMin)
If iMin < 1 Then
m_iMaxValue = m_iMaxValue + 1
End If
End If
m_iValue = 1
End Sub

We don't need any additional initialization steps.

Lets create SetProgress sub procedure, which will display current progress bar state. It takes one ByVal argument, which is a value from the range specified during the initialization. It is the current position within the range.

Private Sub SetProgress(ByVal iValue As Long)

Normalize current progress value, i.e. shift it to the diapason from 1 to m_iMaxValue:

m_iValue = Abs(iValue - m_iMin) + 1

Draw progress bar, i.e. calculate current width of the lblFace Label control depending on the current progress value:

With Me.lblFace
.Width = (m_iValue * m_sWidth) / m_iMaxValue
.Caption = CStr(Int(m_iValue * 100 / m_iMaxValue)) & "%"
End With

Let the operating system to redraw form and to process other events:

DoEvents
End Sub

That's all!
Reply With Quote
  #3  
Old 10-01-2009
Member
 
Join Date: Oct 2005
Posts: 2,389
Re: Custom control implementation of a progress bar

hi
for best ill suggest you to simply visit here good direction you will get ..
http://www.codeproject.com/KB/progre...ssBarEver.aspx
Reply With Quote
  #4  
Old 10-01-2009
Member
 
Join Date: Jan 2009
Posts: 25
Re: Custom control implementation of a progress bar

hi
thank you very much for helping.
Reply With Quote
  #5  
Old 10-01-2009
lucas999
 
Posts: n/a
Re: Custom control implementation of a progress bar

Quote:
Originally Posted by Reegan View Post
hi
for best ill suggest you to simply visit here good direction you will get
No, avoid these (newbie) samples.
See rather the original MS samples from which it's (poorly) copied...
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Custom control implementation of a progress bar"
Thread Thread Starter Forum Replies Last Post
Custom theme to control light color in Sony Xperia U Nitye Portable Devices 2 29-05-2012 04:30 PM
Does Need for Speed: The Run have Custom control layout Badsah Video Games 3 20-11-2011 11:16 AM
MSP custom field formula to track project progress M0m1 Microsoft Project 1 30-04-2011 03:40 AM
Can I create a custom control in Windows Phone 7 mANICKAVASAN Portable Devices 3 27-10-2010 11:56 AM
Collection Content Property in custom control wpf Nurhan Software Development 3 04-08-2009 12:32 PM


All times are GMT +5.5. The time now is 05:15 AM.