Results 1 to 26 of 26

Thread: putting text to progressbar

  1. #1

    Thread Starter
    Hyperactive Member gaouser's Avatar
    Join Date
    Mar 2022
    Location
    Near the User32.dll
    Posts
    386

    putting text to progressbar

    how to put text to progressbar (not value,im making progress button i need to put string)

  2. #2
    Fanatic Member Delaney's Avatar
    Join Date
    Nov 2019
    Location
    Paris, France
    Posts
    845

    Re: putting text to progressbar

    create a user control with a progress bar and a label...
    The best friend of any programmer is a search engine
    "Don't wish it was easier, wish you were better. Don't wish for less problems, wish for more skills. Don't wish for less challenges, wish for more wisdom" (J. Rohn)
    “They did not know it was impossible so they did it” (Mark Twain)

  3. #3

    Thread Starter
    Hyperactive Member gaouser's Avatar
    Join Date
    Mar 2022
    Location
    Near the User32.dll
    Posts
    386

    Re: putting text to progressbar

    man theres no transparent on .net labels,i can do it in only com based vb6

  4. #4
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,458

    Re: putting text to progressbar

    Quote Originally Posted by gaouser View Post
    man theres no transparent on .net labels,i can do it in only com based vb6
    A label has a transparent background on .Net, I am really not understanding your problem here.

  5. #5

    Thread Starter
    Hyperactive Member gaouser's Avatar
    Join Date
    Mar 2022
    Location
    Near the User32.dll
    Posts
    386

    Re: putting text to progressbar

    PlausiblyDamp i use 2010 ( most compatible vb with win7)(i use win7 and im sending message on it)

  6. #6
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,711

    Re: putting text to progressbar

    Then I have great news for you! I consulted the documentation and the Label class exposes the BackColor property as early as .NET 1.1 and the Color struct also exposes Color.Transparent property as early as .NET 1.1.

    So Delaney's original advice is perfectly applicable:
    Quote Originally Posted by Delaney View Post
    create a user control with a progress bar and a label...
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  7. #7
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,531

    Re: putting text to progressbar

    Personally I would have (or at least tried to) create a new class, inherit the progress bar, add a new property to hold the text, and then draw the text onto the progbar ...

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  8. #8
    Fanatic Member Peter Porter's Avatar
    Join Date
    Jul 2013
    Posts
    532

    Re: putting text to progressbar

    Gaouser, I'm guessing you want to display the percentage of progress over a progress bar. The only way to do this is to create your own custom progress bar.

    Add a class to your project and name it "CustomProgressBar", and place this code inside it:
    Code:
    Inherits ProgressBar
    
        Public Sub New()
    
            Me.SetStyle(ControlStyles.UserPaint Or ControlStyles.AllPaintingInWmPaint, True)
        End Sub
    
        Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
            Dim rect As Rectangle = Me.ClientRectangle
            Dim g As Graphics = e.Graphics
            ProgressBarRenderer.DrawHorizontalBar(g, rect)
    
            If Me.Value > 0 Then
                Dim rect2 As Rectangle = New Rectangle(rect.X, rect.Y, CInt(Math.Round((CSng(Me.Value) / Me.Maximum) * rect.Width)), rect.Height)
                ProgressBarRenderer.DrawHorizontalChunks(g, rect2)
            End If
    
            Using f As Font = New Font(FontFamily.GenericMonospace, 10)
                Dim size As SizeF = g.MeasureString(String.Format("{0} %", Me.Value), f)
                Dim location As Point = New Point(CInt(((rect.Width / 2) - (size.Width / 2))), CInt(((rect.Height / 2) - (size.Height / 2) + 2)))
                g.DrawString(String.Format("{0} %", Me.Value), f, Brushes.Black, location)
            End Using
        End Sub
    Now build or rebuild your project, and CustomProgressBar will show in your toolbox for use like the regular progress bar, except it will display the percentage of progress.

    Name:  customprogressbar.jpg
Views: 595
Size:  9.5 KB

    So you know it works:

    Name:  customprogressbar2.jpg
Views: 666
Size:  9.7 KB
    Last edited by Peter Porter; Apr 22nd, 2022 at 08:38 AM.

  9. #9
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,684

    Re: putting text to progressbar

    If you don't mind adding a C# class project to your Visual Studio solution, check out the following C# class project. Once added to your solution, reference the project in your project, add the progress bar to your form.

    Sample VB usage

    Code:
    Public Class Form1
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    
            If TextProgressBar1.Value = 100 Then
                TextProgressBar1.ProgressColor = Color.LightGreen
                TextProgressBar1.Value = 0
            End If
    
            TextProgressBar1.Value = TextProgressBar1.Value + 10
    
            If TextProgressBar1.Value < 20 Then
                TextProgressBar1.CustomText = "Stage 1"
            ElseIf TextProgressBar1.Value > 30 AndAlso TextProgressBar1.Value < 50 Then
                TextProgressBar1.CustomText = "Stage 2"
            ElseIf TextProgressBar1.Value > 99 Then
                TextProgressBar1.CustomText = "Done"
                TextProgressBar1.ProgressColor = Color.Yellow
            End If
        End Sub
    End Class
    Then of course, why can't this be in VB.NET? Well convert using a C# to VB.NET converter but the progressbar works just fine as is or another member here may do the conversion. One of the great things about .NET is languages, C# and VB.NET work well together.

  10. #10
    Fanatic Member Peter Porter's Avatar
    Join Date
    Jul 2013
    Posts
    532

    Re: putting text to progressbar

    Quote Originally Posted by kareninstructor View Post
    If you don't mind adding a C# class project to your Visual Studio solution, check out the following C# class project. Once added to your solution, reference the project in your project, add the progress bar to your form.

    Sample VB usage

    Code:
    Public Class Form1
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    
            If TextProgressBar1.Value = 100 Then
                TextProgressBar1.ProgressColor = Color.LightGreen
                TextProgressBar1.Value = 0
            End If
    
            TextProgressBar1.Value = TextProgressBar1.Value + 10
    
            If TextProgressBar1.Value < 20 Then
                TextProgressBar1.CustomText = "Stage 1"
            ElseIf TextProgressBar1.Value > 30 AndAlso TextProgressBar1.Value < 50 Then
                TextProgressBar1.CustomText = "Stage 2"
            ElseIf TextProgressBar1.Value > 99 Then
                TextProgressBar1.CustomText = "Done"
                TextProgressBar1.ProgressColor = Color.Yellow
            End If
        End Sub
    End Class
    Then of course, why can't this be in VB.NET? Well convert using a C# to VB.NET converter but the progressbar works just fine as is or another member here may do the conversion. One of the great things about .NET is languages, C# and VB.NET work well together.
    I found what I posted from a YouTube video, but it was in C#. Just had to make a minor tweak to it while converting to VB, removing InitializeComponent() to get it to work.

    Love your progress bar!
    Last edited by Peter Porter; Apr 22nd, 2022 at 05:06 AM.

  11. #11

    Thread Starter
    Hyperactive Member gaouser's Avatar
    Join Date
    Mar 2022
    Location
    Near the User32.dll
    Posts
    386

    Re: putting text to progressbar

    @Peter Porter im having a problem on chunks

  12. #12
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,116

    Re: putting text to progressbar

    Quote Originally Posted by gaouser View Post
    @Peter Porter im having a problem on chunks
    Bidet or toilet paper?

  13. #13
    Fanatic Member Peter Porter's Avatar
    Join Date
    Jul 2013
    Posts
    532

    Re: putting text to progressbar

    Quote Originally Posted by gaouser View Post
    @Peter Porter im having a problem on chunks
    Your fault if you're all backed-up!

    You should've ate healthy!
    Last edited by Peter Porter; Apr 22nd, 2022 at 01:28 AM.

  14. #14
    Fanatic Member Peter Porter's Avatar
    Join Date
    Jul 2013
    Posts
    532

    Re: putting text to progressbar

    Quote Originally Posted by gaouser View Post
    @Peter Porter im having a problem on chunks
    Gaouser, what are you writing about? I'm not psychic!

    Chunks doesn't tell me anything! Why do you believe that it's enough?

    How is this related the progress bar problem?

    Did me and Karen solve the problem that this thread is about?
    Last edited by Peter Porter; Apr 22nd, 2022 at 06:21 AM.

  15. #15
    Fanatic Member Delaney's Avatar
    Join Date
    Nov 2019
    Location
    Paris, France
    Posts
    845

    Re: putting text to progressbar

    he cannot answer to you he has been banned
    The best friend of any programmer is a search engine
    "Don't wish it was easier, wish you were better. Don't wish for less problems, wish for more skills. Don't wish for less challenges, wish for more wisdom" (J. Rohn)
    “They did not know it was impossible so they did it” (Mark Twain)

  16. #16
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,531

    Re: putting text to progressbar

    Woah.. .what happened? Wha'd I miss?

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  17. #17
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,116

    Re: putting text to progressbar

    Quote Originally Posted by techgnome View Post
    Woah.. .what happened? Wha'd I miss?

    -tg
    I don't think it was a single thing that happened, I would imagine it was the totality of nonsense they were posting that made it abundantly clear that they would never be more than a significant annoyance on this site.

  18. #18
    Lively Member
    Join Date
    Apr 2022
    Posts
    65

    Re: putting text to progressbar

    Quote Originally Posted by techgnome View Post
    Personally I would have (or at least tried to) create a new class, inherit the progress bar, add a new property to hold the text, and then draw the text onto the progbar ...

    -tg
    Good practice I believe this is protected programming you are indicating.

  19. #19
    Lively Member
    Join Date
    Apr 2022
    Posts
    65

    Re: putting text to progressbar

    Quote Originally Posted by mmx88_ValidUser View Post
    Good practice I believe this is protected programming you are indicating.
    And proper rendering you want speed you ll learn some protected techniques with the controls.

  20. #20
    Fanatic Member Peter Porter's Avatar
    Join Date
    Jul 2013
    Posts
    532

    Re: putting text to progressbar

    Quote Originally Posted by mmx88_ValidUser View Post
    Quote Originally Posted by techgnome View Post
    Personally I would have (or at least tried to) create a new class, inherit the progress bar, add a new property to hold the text, and then draw the text onto the progbar ...

    -tg
    Good practice I believe this is protected programming you are indicating.
    ValidUser, use Google Translate to translate comments. Techgnome's comment doesn't indicate anything towards protected programming, so your reply to him doesn't make sense.
    Last edited by Peter Porter; Apr 23rd, 2022 at 04:43 PM.

  21. #21
    Fanatic Member Peter Porter's Avatar
    Join Date
    Jul 2013
    Posts
    532

    Re: putting text to progressbar

    Quote Originally Posted by mmx88_ValidUser View Post
    Quote Originally Posted by mmx88_ValidUser View Post
    Good practice I believe this is protected programming you are indicating.
    And proper rendering you want speed you ll learn some protected techniques with the controls.
    Do you also talk to yourself at home? I hope not!

  22. #22
    Fanatic Member Peter Porter's Avatar
    Join Date
    Jul 2013
    Posts
    532

    Re: putting text to progressbar

    D'oh! This comment was a copy of the previous before. Not sure how that happened.
    Last edited by Peter Porter; Apr 23rd, 2022 at 04:42 PM.

  23. #23
    Lively Member
    Join Date
    Apr 2022
    Posts
    65

    Re: putting text to progressbar

    Quote Originally Posted by Peter Porter View Post
    ValidUser, use Google Translate to translate comments. Techgnome's comment doesn't indicate anything towards protected programming, so your reply to him doesn't make sense.
    Are you trying to big fish your self into the penalty box mister.

  24. #24
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    Re: putting text to progressbar

    Quote Originally Posted by mmx88_ValidUser View Post
    Are you trying to big fish your self into the penalty box mister.
    What does that even mean? If it's a mixed metaphor it's so mixed as to have no meaning at all.
    My usual boring signature: Nothing

  25. #25

    Thread Starter
    Hyperactive Member gaouser's Avatar
    Join Date
    Mar 2022
    Location
    Near the User32.dll
    Posts
    386

    Re: putting text to progressbar

    hi everyone my ban lifted )) i read all from internet explorer (i didnt login from it) but i only check in 14:00 pm
    wow what happened here whatd i miss
    Last edited by gaouser; Apr 24th, 2022 at 03:39 PM.

  26. #26

    Thread Starter
    Hyperactive Member gaouser's Avatar
    Join Date
    Mar 2022
    Location
    Near the User32.dll
    Posts
    386

    Re: putting text to progressbar

    Quote Originally Posted by Peter Porter View Post
    Do you also talk to yourself at home? I hope not!
    AHAHAHAHAHAHHAHAHAHAHAHAHAAAAAAHAHAHAHHAHAHAHA i cant stop i laugh for 5 MINUTES

Posting Permissions

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



Click Here to Expand Forum to Full Width