?
Solved

vb.net custom progressbar, how to overlay an image in pbar?

Posted on 2009-06-30
4
Medium Priority
?
940 Views
Last Modified: 2013-11-26
How would I go about stretching an image as a progressbar?  Meaning I have an image that I want to put inside of a progressbar and have it get longer and longer until 100%
0
Comment
Question by:bluedragon99
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 15

Expert Comment

by:Solar_Flare
ID: 24750314
if you set the height/width properties of an image then the browser should stretch the image to fit.

<img src="1.jpg" width="10px">

<img src="1.jpg" width="100px">
0
 
LVL 15

Expert Comment

by:Solar_Flare
ID: 24750319
whoops, i think you also need to set the height to stop the browser simply scaling the entire image


<img src="1.jpg" width="10px" height="20px">

<img src="1.jpg" width="100px" height="20px">
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 24750376
For WinForms, just create a UserControl with a PictureBox inside of it.  Set the SizeMode of the PB to StretchImage and then simply adjust the size of the PB to stretch the image...

Something like:
(if you add UserControl class first and then build the project you should get your new usercontrol in the ToolBox)
Public Class Form1
 
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        PictureProgressBar1.Image = New Bitmap("C:\Users\Mike\Pictures\AmericanFlag.jpg")
    End Sub
 
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Button1.Enabled = False
 
        For i As Integer = 0 To 100
            PictureProgressBar1.Percentage = i
            Application.DoEvents()
            System.Threading.Thread.Sleep(100)
        Next
 
        Button1.Enabled = True
    End Sub
 
End Class
 
Public Class PictureProgressBar
    Inherits UserControl
 
    Private P As Integer = 0
    Private PB As New PictureBox
 
    Public Property Image() As Image
        Get
            Return PB.Image
        End Get
        Set(ByVal value As Image)
            PB.Image = value
        End Set
    End Property
 
    Public Sub New()
        PB.BorderStyle = Windows.Forms.BorderStyle.None
        PB.Location = New Point(0, 0)
        PB.Size = New Size(0, Me.ClientRectangle.Height)
        PB.SizeMode = PictureBoxSizeMode.StretchImage
        PB.BackColor = Color.Red
        Me.Controls.Add(PB)
        Me.Percentage = 0
        Me.BorderStyle = Windows.Forms.BorderStyle.FixedSingle
    End Sub
 
    Public Property Percentage() As Integer
        Get
            Return P
        End Get
        Set(ByVal value As Integer)
            If value >= 0 AndAlso value <= 100 Then
                P = value
                Me.Refresh()
            End If
        End Set
    End Property
 
    Private Sub PictureProgressBar_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
        UpdateProgessSize()
    End Sub
 
    Private Sub PictureProgressBar_SizeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.SizeChanged
        UpdateProgessSize()
    End Sub
 
    Private Sub UpdateProgessSize()
        PB.Size = New Size(P / 100 * Me.ClientRectangle.Width, Me.ClientRectangle.Height)
    End Sub
 
 
End Class

Open in new window

0

Featured Post

Is Your Team Achieving Their Full Potential?

74% of employees feel they are not achieving their full potential. With Linux Academy, not only will you strengthen your team's core competencies but also their knowledge of of the newest IT topics.

With new material every week, we'll make sure that you stay ahead of the game.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question