473,517 Members | 2,837 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 6544
"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
4633
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 to get the cell the user clicked (thus getting the client he chose), and take the user to another separate page that will show that client's complete...
1
1326
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 displayed. Most of time, it works fine. And for the Hotmail users and the outlook webmail users sometime it does not work. The login page is still...
4
5505
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 do this? Thanks
5
2629
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 ); CREATE TABLE projects ( project text primary key not null, department text not null
1
1867
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 Date() (as I need the current date). My problem is when user open the form and click on D_Status in any old record, The record is not updated with the...
4
1338
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 details are resubmitted if user pressess submit button. does any body have idea how to stop user from re-submitting the last page or expire the...
3
4210
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 information he entered and when user click confirm button only it should submit to the DB. Could you please tell me what is the best way? Do I need to...
0
972
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 custom control, it will hide the MonthCalender. How can my custom control catch the click event on it's parent form so that my custom control will be...
0
7295
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7197
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7430
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7556
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5737
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3277
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1641
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
833
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
504
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.