Page 1 of 2 12 LastLast
Results 1 to 20 of 40

Thread: Text inside a progressbar

  1. #1
    Master Zero is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Sep 2005
    Posts
    51
    Reputation
    85

    Text inside a progressbar


    Can anyone tell me how to put text inside a progressbar?

    For example, I want to embed the current percentage value of the progressbar within it.

    Thanks in advance!

  2. #2
    kulrom's Avatar
    kulrom is offline VB.NET Forum All-Mighty
    .NET Framework
    .NET 3.5
    Join Date
    May 2005
    Location
    Republic of Macedonia
    Posts
    2,855
    Reputation
    236
    are you asking about the vs.net built-in control or custom progressbar? There should not be much differences anyway. Say you can add label control over and set its background to transparent ... then simply show the percentage.

    Regards

  3. #3
    Master Zero is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Sep 2005
    Posts
    51
    Reputation
    85
    Thanks, I was talking about the built-in control. I’ll give your ideas a try, sound like it would work.

  4. #4
    kulrom's Avatar
    kulrom is offline VB.NET Forum All-Mighty
    .NET Framework
    .NET 3.5
    Join Date
    May 2005
    Location
    Republic of Macedonia
    Posts
    2,855
    Reputation
    236
    OK here we go ... make a new project selecting a "windows control library" from templates.
    Then draw a progress bar from the toolbar pane and just join next code in design view (just after 'Windows Form Designer generated code')

    Code:
     
    Property Value() As Integer
    Get
    Return ProgressBar1.Value
    End Get
    Set(ByVal Value As Integer)
    ProgressBar1.Value = Value
    UpdateLabel()
    End Set
    End Property
     
    
    Property Maximum() As Integer
    Get
    Return ProgressBar1.Maximum
    End Get
    Set(ByVal Value As Integer)
    ProgressBar1.Maximum = Value
    End Set
    End Property
     
    
    Property [Step]() As Integer
    Get
    Return ProgressBar1.Step
    EndGet
    Set(ByVal Value As Integer)
    ProgressBar1.Step = Value
    End Set
    End Property
     
    
    Public Sub PerformStep()
    ProgressBar1.PerformStep()
    UpdateLabel()
    End Sub
     
    
    PrivateSub UpdateLabel()
    Dim myString As String = ((ProgressBar1.Value * 100) \ ProgressBar1.Maximum).ToString()
    myString &= "% Done"
    Dim canvas As Graphics = Me.ProgressBar1.CreateGraphics
    canvas.DrawString(myString, New Font("Verdana", 8, FontStyle.Regular), New SolidBrush(Color.Red), 90, 4)
    canvas.Dispose()
    End Sub
    

    to test the control just add the new control inside new windows project and add timer control.


    timer control code:
    Code:
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    Status.PerformStep()
    If Status.Maximum = Status.Value Then Timer1.Enabled = False
    EndSub
    

    If you want to reset the timer just join next code to the button or something (i will use a button for the purpose)

    Code:
     
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    Timer1.Enabled = False
    Status.Value = 0
    Status.Maximum = 20
    Status.Step = 1
    Timer1.Enabled = True
    End Sub
    

    HTH
    Regards

    P.S. do not hesitate to ask for a demo project if you cannot realize it from the code above

  5. #5
    Brainbug's Avatar
    Brainbug is offline VB.NET Forum Newbie
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Dec 2005
    Location
    Hanover, Germany
    Posts
    17
    Reputation
    80

    Yes, please!

    I need a demo how to manage that new control and how to put it into a new project. By the way: why DOES the "transparent"-Backcolor NOT work with the Label and the ProgressBar (as I stated here: Transparent Labels)

    Brainbug

  6. #6
    kulrom's Avatar
    kulrom is offline VB.NET Forum All-Mighty
    .NET Framework
    .NET 3.5
    Join Date
    May 2005
    Location
    Republic of Macedonia
    Posts
    2,855
    Reputation
    236
    Ok this is a demo project as well as custom control code (project) ... ask if you need an additional help


    Regards
    Attached Images Attached Images
    Attached Files Attached Files

  7. #7
    Brainbug's Avatar
    Brainbug is offline VB.NET Forum Newbie
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Dec 2005
    Location
    Hanover, Germany
    Posts
    17
    Reputation
    80

    Thanks so far!

    Is it possible to get self-made controls in the toolbox, to pick and drapg&drop them to a form, when needed? How did you get your UserControl in there?

    Brainbug

  8. #8
    kulrom's Avatar
    kulrom is offline VB.NET Forum All-Mighty
    .NET Framework
    .NET 3.5
    Join Date
    May 2005
    Location
    Republic of Macedonia
    Posts
    2,855
    Reputation
    236
    Quote Originally Posted by Brainbug
    Is it possible to get self-made controls in the toolbox, to pick and drapg&drop them to a form, when needed? How did you get your UserControl in there?

    Brainbug
    just as you described. Through the toolbox "add/remove items..." ...just locate the .dll file inside bin folder of the 2nd attached project above and click OK. Now you can simply drag that to the form ...

    HTH
    Regards

  9. #9
    Brainbug's Avatar
    Brainbug is offline VB.NET Forum Newbie
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Dec 2005
    Location
    Hanover, Germany
    Posts
    17
    Reputation
    80

    finally found it...

    I'm using .net 2006 and there it says "choose items" and then you have to browse for the dll; now I managed it to use your control. Thank you very much for your support.

    Brainbug

  10. #10
    kulrom's Avatar
    kulrom is offline VB.NET Forum All-Mighty
    .NET Framework
    .NET 3.5
    Join Date
    May 2005
    Location
    Republic of Macedonia
    Posts
    2,855
    Reputation
    236
    Quote Originally Posted by Brainbug
    I'm using .net 2006 and there it says "choose items" and then you have to browse for the dll; now I managed it to use your control. Thank you very much for your support.

    Brainbug
    Is there 2006 version already? Then i am not very well informed ... JK .. suppose typo but, anyway you are wellcome for help ..anytime, if i am able to be of help ... Regards

  11. #11
    Nighty01 is offline VB.NET Forum Newbie
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Mar 2006
    Posts
    1
    Reputation
    0

    Cool Update (show Any texts)

    I changed a little bit, so you can set any kind of text in the progress bar.

    PrivateSub UpdateLabel(ByVal PB1 As ProgressBar, ByVal sInputString AsString, OptionalByVal oFont As Font = Nothing)
    Dim sString AsString
    Dim canvas As Graphics = PB1.CreateGraphics
    Dim iWidth AsInteger
    If IsNothing(oFont) Then
    oFont = New Font("Verdana", 8, FontStyle.Bold)
    EndIf
    sString = ((PB1.Value * 100) \ PB1.Maximum).ToString()
    sString &= "% " + sInputString
    iwidth = (PB1.Width - canvas.MeasureString(sString, oFont).Width) \ 2
    canvas.DrawString(sString, oFont,
    New SolidBrush(Color.White), iwidth + 1, 1) ' Not like a 3D effect, so please delete this line.
    canvas.DrawString(sString, oFont,
    New SolidBrush(Color.Red), iwidth, 0)
    canvas.Dispose()
    EndSub

    regrards

    Nighty


  12. #12
    qaball is offline VB.NET Forum Newbie
    .NET Framework
    .NET 1.1 (VS 2003)
    Join Date
    Oct 2006
    Posts
    2
    Reputation
    0

    Thumbs up Very cool, but how do I use it?

    I like the ability to add text to the progress bar but I have just 2 problems.

    1. How do I construct the control to allow me to pass the text to it as a parameter? I'm using the controil code from the examples above but I don't know enough about constructing custom controls to get this to work.

    2. How do I change the color of the progress bar? Nothing I do in the DEMO program included above lets me change the color of the progress. I can see how to change the font, size and color but not the bar behind it.

    Any help would be greatly appreciated!

    Thanks
    qaball

  13. #13
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    13,315
    Reputation
    1991
    qaball, a usercontrol is built by placing one or more common controls inside it. If you want properties of the usercontrol itself to access properties of the individual controls behind you must write these properties yourself, providing the link to and fro the usercontrol level and child control level. You may create all new properties of any your liking or override the behaviour of the existing overridable usercontrol properties.

  14. #14
    qaball is offline VB.NET Forum Newbie
    .NET Framework
    .NET 1.1 (VS 2003)
    Join Date
    Oct 2006
    Posts
    2
    Reputation
    0

    Thumbs up Almost got it.

    JohnH

    I have it working and cleaned up and it works like a charm now. I do have one question, since I've been working with the demo code that has been posted and used that as a starting point, does anyone know why the bars are green and not the blue of the progressbar control included with VB? Is that an affectation of it being a usercontrol?

    Thanks
    qaball

  15. #15
    [RTS]BN+VS*'s Avatar
    [RTS]BN+VS* is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Feb 2009
    Location
    BELGIUM - East Flanders
    Posts
    53
    Reputation
    43
    Hey,

    I'm using my own adaptation of this code, but I've run into a problem.
    If you draw the string onto the progressbar, it'll be removed on vista every x secs cause there is some refresh indicator going through the bar.

    Is there any event (or procedure used that is overidable), which occurs then, so the string can be redrawn?

    Either a solution to this question or a link to a working control that does not have this problem would be very much appreciated.

    Cheers
    BN

  16. #16
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    13,315
    Reputation
    1991
    You draw in Paint event and you use the provided graphics instance e.Graphics to draw with.

  17. #17
    [RTS]BN+VS*'s Avatar
    [RTS]BN+VS* is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Feb 2009
    Location
    BELGIUM - East Flanders
    Posts
    53
    Reputation
    43
    Yes, that's the logical approach. But apparently the pain event isn't fired every time this bar updates (I have already tried this out by putting a messagebox in it). So putting gfx creation there will have no result whatsoever except for startup

  18. #18
    [RTS]BN+VS*'s Avatar
    [RTS]BN+VS* is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Feb 2009
    Location
    BELGIUM - East Flanders
    Posts
    53
    Reputation
    43
    Could you provide me with a small example of how you would do it? Maybe I'm just handling it the wrong way.

    I've added my current code as attachment.
    Attached Files Attached Files

  19. #19
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    13,315
    Reputation
    1991
    You don't put message boxes in Paint event. I also forgot Progressbar doesn't have a Paint event for use, have a look at this example on hwo you can draw text to progressbar when WM_PAINT messages are received: post 5 of thread Draw Text with Blend to background

  20. #20
    [RTS]BN+VS*'s Avatar
    [RTS]BN+VS* is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Feb 2009
    Location
    BELGIUM - East Flanders
    Posts
    53
    Reputation
    43
    Hey,

    Your example helped me through this problem
    I tried overriding a whole bunch of look-like-they-have-something-to-do-with-the-paint-event methods, but had no idea WndProc was the correct one xD

    Cheers
    BN
    Last edited by [RTS]BN+VS*; 02-05-2009 at 3:23 PM.

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Search Engine Optimization by vBSEO