473,387 Members | 1,463 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,387 software developers and data experts.

allowing a user to click on a progressbar

Eps
Hi there,

Is there a way to get the progressbar value when a user clicks on it ?

I am using wpf at the moment but windows forms solutions would be
welcome too.

I get the the x and y positions of the mouse click but I don't know how
to translate that into the value of the progressbar.

any help appreciated.

--
Eps
Oct 13 '07 #1
8 6529
"Eps" <ep*@mailinator.comwrote:
Is there a way to get the progressbar value when a user clicks on it
?
Unless I'm missing something in your problem description, you don't
need to do anything with x- and y-co-ordinates. Just handle the
ProgressBar's own Click event.

private void progressBar1_Click(object sender, EventArgs e)
{
MessageBox.Show(((ProgressBar) sender).Value.ToString());
}

Eq.
Oct 13 '07 #2
Eps
Paul E Collins wrote:
Unless I'm missing something in your problem description, you don't
need to do anything with x- and y-co-ordinates. Just handle the
ProgressBar's own Click event.

private void progressBar1_Click(object sender, EventArgs e)
{
MessageBox.Show(((ProgressBar) sender).Value.ToString());
}

Eq.
hmmm, the wpf progress bar does not seem to have a Click event

anyone know how to do this in wpf ?

--
Eps
Oct 13 '07 #3
Liz

"Eps" <ep*@mailinator.comwrote in message
news:u0**************@TK2MSFTNGP03.phx.gbl...
Paul E Collins wrote:
hmmm, the wpf progress bar does not seem to have a Click event

anyone know how to do this in wpf ?

there are all kinds of Mouse events exposed: MouseUp, MouseDown,
MouseLeftButtonUp, etc ..... one of them should fit your needs

clicking on a ProgressBar seems a bit counter-intuitive though, no? if the
numeric value is important why don't you just post it on the form at an
appropriate interval? what I don't understand about the PB is why there is
no ValueChanged event .. (there is in WPF but it refers to the max and min
range values)

L
Oct 13 '07 #4
Eps
Liz wrote:
there are all kinds of Mouse events exposed: MouseUp, MouseDown,
MouseLeftButtonUp, etc ..... one of them should fit your needs

clicking on a ProgressBar seems a bit counter-intuitive though, no? if the
numeric value is important why don't you just post it on the form at an
appropriate interval? what I don't understand about the PB is why there is
no ValueChanged event .. (there is in WPF but it refers to the max and min
range values)

L
I am trying to use the progress bar to represent the playing of a mp3, I
guess its a bit of a hack to try and allow the user to change the value
of a progressbar by clicking with the mouse, not what the progress bar
is for.

I am sure there is some maths i could do to get an approximate value
using the X position of the mouse cursor, so I will look in to that.

--
Eps
Oct 13 '07 #5
Liz

"Eps" <ep*@mailinator.comwrote in message
news:uW**************@TK2MSFTNGP04.phx.gbl...
I am trying to use the progress bar to represent the playing of a mp3, I
guess its a bit of a hack to try and allow the user to change the value of
a progressbar by clicking with the mouse, not what the progress bar is
for.

I am sure there is some maths i could do to get an approximate value using
the X position of the mouse cursor, so I will look in to that.
yeah, you could do that with some simple arithmetic using x,y .. pixel
length of the progress bar, etc ... should work ..; meanwhile, you might
look at doing it with the TrackBar control, which is designed to get input
values along a continuous range ... but it doesn't have quite the same
aesthetics to it ...

thing with this is that I don't think I'd want a discrete click to trigger
changes in the value of the Prog Bar; imo, I think you really want to use
the MouseMove event .. the problem you need to solve there is that the mouse
does not have to be down for the event to fire, which is bound to lead to
unintended changes in track position

I think it'll be a little tough with progress bar because the player (WMP??)
will not likely respond immediately to the calculated change in track
position; you need to defer the re-positioning of the track until the user
has stopped "turning the dial" .. like maybe wait 300 ms until a track
position change is effected

L
Oct 13 '07 #6
"Liz" <li*@tiredofspam.comwrote:
thing with this is that I don't think I'd want a discrete click to
trigger changes in the value of the Prog Bar; imo, I think you
really want to use the MouseMove event .. the problem you need to
solve there is that the mouse does not have to be down for the event
to fire, [...]
Unless WPF has really crippled everything beyond repair, you can look
at the MouseEventArgs.Buttons property.

Eq.
Oct 14 '07 #7
Liz

"Paul E Collins" <fi******************@CL4.orgwrote in message
news:sc*********************@bt.com...
"Liz" <li*@tiredofspam.comwrote:
>thing with this is that I don't think I'd want a discrete click to
trigger changes in the value of the Prog Bar; imo, I think you really
want to use the MouseMove event .. the problem you need to solve there is
that the mouse does not have to be down for the event to fire, [...]
Unless WPF has really crippled everything beyond repair, you can look at
the MouseEventArgs.Buttons property.
BINGO! ... with that information in hand, this seems to do what the OP was
looking for:

private void progressBar1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
decimal pos = 0M;
pos = ((decimal)e.X / (decimal)progressBar1.Width) * 100;
pos = Convert.ToInt32(pos);

if (pos >= progressBar1.Minimum && pos <= progressBar1.Maximum)
{
progressBar1.Value = (int)pos;

// info only:
label5.Text = e.X.ToString() + " / " +
progressBar1.Width.ToString() + " [" +
(Convert.ToInt32(pos).ToString()).ToString() + "]";
}
}
}
L
Oct 14 '07 #8
Eps
I had already implemented it as below, but thanks for suggesting the
mouse move event, it works even better now ! (I didn't think I would be
able to get it to support draging the progress bar).

private double SetProgressBarValue(double MousePosition)
{
double Length = m_mp3play.CurrentSongLength;

double ratio = MousePosition / progressBar1.ActualWidth;
double ProgressBarValue = ratio * progressBar1.Maximum;
m_mp3play.CurrentPosition = ProgressBarValue;
return ProgressBarValue;
}

private void progressBar1_MouseLeftButtonDown(object sender,
MouseButtonEventArgs e)
{
double MousePosition = e.GetPosition(progressBar1).X;
progressBar1.Value = SetProgressBarValue(MousePosition);
}

I have implemented the mouse move event like so...

private void progressBar1_MouseMove(object sender, MouseEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
double MousePosition = e.GetPosition(progressBar1).X;
progressBar1.Value = SetProgressBarValue(MousePosition);
}
}

This is all WPF code.

Thanks for your help.

--
Eps
Oct 14 '07 #9

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

Similar topics

1
by: VM | last post by:
Is it possible for the bound data in a web datagrid to be displayed in links? The grid will show the client's first name and last name and, when the user clicks on the first or last name, I want...
1
by: Eric Shi | last post by:
Hi, I use ASP.Net build a web application which requires users to login. The link is sent out to the user via email. The users then click the link in the email and the login page is...
4
by: feng | last post by:
Hi, In our asp.net app, we need to capture the event when user close the browser window by clicking on the "x" button. But it doesn't seem to be as easy as it sound. Can someone show me how to...
5
by: Mike Mascari | last post by:
I'd like to ensure that the creation of a department also implies the creation of two to eight projects; no more, no less: CREATE TABLE departments ( department text primary key not null ); ...
1
by: colleen1980 | last post by:
I create two fields in my old table. One is D_Status of type Yes/No Checkbox and the other is DDate of type Date. In my table there is already records in it. I set the default value of DDate as...
4
by: hi2Kamal | last post by:
I have a problem. I have developed a page which inserts data into database and redirects me to some other page. but when user click the back button from top its takes him to the last page and all the...
3
by: ghjk | last post by:
I have a web page which is used to enter user data. In there I have 4 buttons named as "Submit, Confirm,Edit,Cancel". User should enter data and click "Submit " button. Then I want to display all...
0
by: OrcA | last post by:
I have a custom control which have a button and a MonthCalender. When a user press onto the button it will shows up the MonthCalender and if the user click on any place of the parent form for this...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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.