473,386 Members | 1,621 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Workin with progress bars

People, I want to do same things with a progress bar but I don't know how.
So, how do I change it to make it a solid bar, not a step byt step as the
default? And how do I make it a vertical bar? Also, how do I put a progress
bar withing a button?

TIA,
Scirious.
Jun 23 '06 #1
9 2312
"Scirious" <sc******@scirious.com> wrote in message
news:v-******************************@giganews.com...
People, I want to do same things with a progress bar but I don't know how.
So, how do I change it to make it a solid bar, not a step byt step as the
default? And how do I make it a vertical bar? Also, how do I put a
progress
bar withing a button?


1) Launch your Internet browser (e.g. IE, FireFox, Netscape, Opera etc)

2) Navigate to http://www.google.com

3) Enter the text below in the box:

"C#" "progress bar"

4) Hit the button
Jun 23 '06 #2
> 1) Launch your Internet browser (e.g. IE, FireFox, Netscape, Opera
etc)

2) Navigate to http://www.google.com

3) Enter the text below in the box:

"C#" "progress bar"

4) Hit the button


It would have been more polite from you if you could point me to right
place.
Jun 23 '06 #3
Well, I've found the answers to almost all of my questions, but how to put
the progress bar within a button haven't been answered. Actually, to make
my question clear, is it possoble to put any control inside any other
control?

TIA,
Scirious.
Jun 23 '06 #4
Scirious <sc******@scirious.com> wrote:
1) Launch your Internet browser (e.g. IE, FireFox, Netscape, Opera
etc)

2) Navigate to http://www.google.com

3) Enter the text below in the box:

"C#" "progress bar"

4) Hit the button


It would have been more polite from you if you could point me to right
place.


It would have been more polite of you to save us the effort, by checking
Google first. To understand some of the perspective of people who answer
replies on newsgroups, try these two resources:

http://www.catb.org/~esr/faqs/smart-questions.html

http://www.slash7.com/pages/vampires

-- Barry

--
http://barrkel.blogspot.com/
Jun 23 '06 #5
"Scirious" <sc******@scirious.com> wrote in message
news:bN******************************@giganews.com ...
It would have been more polite from you if you could point me to right
place.


Maybe you'd have liked me to write the code for you too...?
Jun 23 '06 #6
Ok, sorry for the preveious behavior. I've already search Google and some
foruns for this but there is yet one question unanswered. How do I add a
progress bar to a button? Would Windows Buttons behave like a container
itself and allow me to add other components to it the same way SWING or QT
do?

TIA,
Scirious.
Jun 24 '06 #7
Scirious <sc******@scirious.com> wrote:
Ok, sorry for the preveious behavior. I've already search Google and some
foruns for this but there is yet one question unanswered. How do I add a
progress bar to a button? Would Windows Buttons behave like a container
itself and allow me to add other components to it the same way SWING or QT
do?


You can add a control to a button, but the control will (by default) eat
mouse clicks etc., which is probably not what you want.

If you want the control to be just a decorator, you need to change how
the control reacts by overriding its response to the WM_NCHITTEST
message.

Try this code out:

---8<---
using System;
using System.Windows.Forms;
using System.Drawing;

class App
{
class SimpleProgressBar : Panel
{
private double _percent;

public double Percent
{
get { return _percent; }
set
{
if (value < 0)
_percent = 0;
else if (value > 100)
_percent = 100;
else
_percent = value;
Invalidate();
}
}

protected override void OnPaint(PaintEventArgs e)
{
int width = (int) (Width * _percent / 100.0);

Rectangle erase = ClientRectangle;
erase.Offset(width, 0);
e.Graphics.FillRectangle(SystemBrushes.Window, erase);
Rectangle selected = ClientRectangle;
selected.Width = width;
e.Graphics.FillRectangle(SystemBrushes.Highlight, selected);

base.OnPaint(e);
}

protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case 0x0014: // WM_ERASEBKGND
m.Result = new IntPtr(0);
break;

case 0x0084: // WM_NCHITTEST
m.Result = new IntPtr(-1); // HTTRANSPARENT
break;

default:
base.WndProc(ref m);
break;
}
}
}

static void Main()
{
Form form = new Form();

Button button = new Button();
button.Parent = form;
button.Size = new Size(200, 200);

SimpleProgressBar bar = new SimpleProgressBar();
bar.Parent = button;
bar.Size = new Size(100, 10);
bar.Location = new Point(50, 95);

Timer tick = new Timer();
tick.Interval = 20;
tick.Tick += delegate
{
bar.Percent = (bar.Percent + 1) % 101;
};
tick.Enabled = true;

Application.Run(form);
}
}
--->8---

-- Barry

--
http://barrkel.blogspot.com/
Jun 24 '06 #8
You can set a background image on the button, but would need to pre-build
the graphics and set them as progress bar changes.
WPF should give us many more options, such as make the button translucent
and put he PB behind the button, etc.
--
William Stacey [MVP]

"Scirious" <sc******@scirious.com> wrote in message
news:u9******************************@giganews.com ...
| Ok, sorry for the preveious behavior. I've already search Google and some
| foruns for this but there is yet one question unanswered. How do I add a
| progress bar to a button? Would Windows Buttons behave like a container
| itself and allow me to add other components to it the same way SWING or QT
| do?
|
| TIA,
| Scirious.
Jun 25 '06 #9
Scirious wrote:
Ok, sorry for the preveious behavior. I've already search Google and some
foruns for this but there is yet one question unanswered. How do I add a
progress bar to a button? Would Windows Buttons behave like a container
itself and allow me to add other components to it the same way SWING or QT
do?

TIA,
Scirious.


Hi Scirious,

I've written you a class, that may do what you want. Perhaps it will be of
some use.

You need to add using clauses for System.Drawing and System.Windows.Forms,
along with the usual System and whatnot.

///
public class ProgressButton : Button
{
private int _max;
private int _value;

public ProgressButton ( )
{
this.TextAlign = ContentAlignment.TopCenter;

_max = 100;
_value = 0;
}

public int MaximumProgressValue
{
get { return _max; }
set
{
_max = value;

if ( this.ProgressValue > _max )
this.ProgressValue = _max;
}
}

public int ProgressValue
{
get { return _value; }
set
{
_value = value;

if ( _value > _max )
_value = _max;
else if ( _value < 0 )
_value = 0;

this.Invalidate();
}
}

protected override void OnPaint ( PaintEventArgs pevent )
{
base.OnPaint( pevent );

const int padding = 6;
const int barHeight = 16;

Rectangle progressRect = new Rectangle( padding,
this.Height - padding - barHeight,
this.Width - ( padding * 2 ),
barHeight );

ProgressBarRenderer.DrawHorizontalBar( pevent.Graphics,
progressRect );

progressRect.Inflate( -3, -3 );
progressRect.Width = (int)
( progressRect.Width * ( (double) _value / _max ) );

ProgressBarRenderer.DrawHorizontalChunks( pevent.Graphics,
progressRect );
}
}
///

Normally, I don't like putting parameters on seperate lines, but to conform
to news group standards, I've done it.

To use, add the control to your form as you normally would.
+ MaximumProgressValue is the maximum value of your progress bar.
+ ProgressValue is the value of the progress bar.

It looks okay using Windows XP themes. I haven't tested it anywhere else.

--
Hope this helps,
Tom Spink
Jun 25 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Paul | last post by:
i have been working with vb6 for a while but never had the pleasure of using progress bars. That is until now, one of the programs i have written has just been modified so that large csv files of...
0
by: Martin Platt | last post by:
Hi, I'm looking into various options for a fairly simple backup utility for our application. I have no problems being able to backup, find restorable backup files, and restore then. What I'd...
1
by: Xarky | last post by:
Hi, I am trying to use progress bars, where the progress is seen as vertical. I am succeding to manage progess bars, where progress is increasing horizontally, but not vertically. Can someone...
5
by: Søren Reinke | last post by:
Hi there I am working on a program where the user should be able to import some CSV files. With my set of test data, it takes about 2 minutes to import, while it is importing the program sort...
6
by: Kyle | last post by:
I want to do a single pix update bar instead of the big block that progress bars usually use. I can't seem to find any info on how to do this. Thanks in advance for any help, Kyle
2
by: Robert Smith | last post by:
Hello, I have a problem with my progress bar, as shown in the attached code, the values on the bar are incremented within a threaded timer event. The timer works fine and ticks all the way...
5
by: Keith Rebello | last post by:
I have a couple of progress bars that indicate the progress of a math-intensive application. They are working well. The only problem is that the progress indicator is gray in color. Is it...
3
by: Ritesh Raj Sarraf | last post by:
Hi, I have a small application, written in Python, that uses threads. The application uses function foo() to download files from the web. As it reads data from the web server, it runs a progress...
0
by: Shaikh shahnawaz | last post by:
Hi, I have implement multiple file uploading progress bar with the help of flash and .net file is upload on my local machine but not working with server it's give error while uploading image on...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.