473,327 Members | 2,081 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,327 software developers and data experts.

Trackbar Mouse Click directly to Value

Ok, something that I thought would be easy is giving me fits.

Using .NET 2.0 and C# I've added a Trackbar to a form. Set some values:

trackVolume.Maximum = 100;
trackVolume.Minimum = 0;
trackVolume.TickFrequence = 25;
Then I added an event for the value:

private void trackVolume_ValueChanged(object sender, EventArgs e)
{
myPlayer.volume = trackVolume.Value;
lblVolume.Text = "Volume (" + trackVolume.Value.ToString() + "%)";
}
Up till now everything's great. Next I notice that if I click to the left or
right of the current position on the slider it only moves the Value by the
LargeChange amount. Ok fine, but what I want is to go directly to the value
that the user clicked on. By default LargeChange is set to 5. So if the
trackVolume.Value is at 10 and I click on 50 then the Value becomes 15 not
50. I checked the documentation and it says the Trackbar has a Click event
and a MouseClick event, but when I go to the events in VisualStudio 2005 I
don't have either one (apparently my documentation doesn't match my version
of VisualStudio, but that's another problem).

Can anyone help me to go directly to the value that was clicked on the
trackbar?

Thanks,
John
Jan 3 '07 #1
2 18777
Hi John

You can use the MouseDown event and capture where the mouse was clicked over
the control, then do some calculations based on mouse's X co-ordinate and
the size of your TrackBar to set it's value:

// trackVolume.Width = 200
// trackVolume.Maximum = 100
private void trackVolume_MouseDown(object sender, MouseEventArgs e)
{
trackVolume.Value = e.X / 2;
}

Regards
Dave
"John" <go*******@hotmail.comwrote in message
news:ex**************@TK2MSFTNGP06.phx.gbl...
Ok, something that I thought would be easy is giving me fits.

Using .NET 2.0 and C# I've added a Trackbar to a form. Set some values:

trackVolume.Maximum = 100;
trackVolume.Minimum = 0;
trackVolume.TickFrequence = 25;
Then I added an event for the value:

private void trackVolume_ValueChanged(object sender, EventArgs e)
{
myPlayer.volume = trackVolume.Value;
lblVolume.Text = "Volume (" + trackVolume.Value.ToString() + "%)";
}
Up till now everything's great. Next I notice that if I click to the left
or right of the current position on the slider it only moves the Value by
the LargeChange amount. Ok fine, but what I want is to go directly to the
value that the user clicked on. By default LargeChange is set to 5. So if
the trackVolume.Value is at 10 and I click on 50 then the Value becomes 15
not 50. I checked the documentation and it says the Trackbar has a Click
event and a MouseClick event, but when I go to the events in VisualStudio
2005 I don't have either one (apparently my documentation doesn't match my
version of VisualStudio, but that's another problem).

Can anyone help me to go directly to the value that was clicked on the
trackbar?

Thanks,
John

Jan 3 '07 #2
Dave,

Thanks for the help. I've generalized it a bit and it works great. Here's the code I'm using:

private void trackVolume_MouseDown(object sender, MouseEventArgs e)
{
double dblValue;

// Jump to the clicked location
dblValue = ((double) e.X / (double) trackVolume.Width) * (trackVolume.Maximum - trackVolume.Minimum);
trackVolume.Value = Convert.ToInt32(dblValue);
}
Thanks,
John

"Dave Shooter" <al****************@delete.me.googlemail.comwrot e in message news:OA***************@TK2MSFTNGP04.phx.gbl...
Hi John

You can use the MouseDown event and capture where the mouse was clicked over
the control, then do some calculations based on mouse's X co-ordinate and
the size of your TrackBar to set it's value:

// trackVolume.Width = 200
// trackVolume.Maximum = 100
private void trackVolume_MouseDown(object sender, MouseEventArgs e)
{
trackVolume.Value = e.X / 2;
}

Regards
Dave
"John" <go*******@hotmail.comwrote in message
news:ex**************@TK2MSFTNGP06.phx.gbl...
>Ok, something that I thought would be easy is giving me fits.

Using .NET 2.0 and C# I've added a Trackbar to a form. Set some values:

trackVolume.Maximum = 100;
trackVolume.Minimum = 0;
trackVolume.TickFrequence = 25;
Then I added an event for the value:

private void trackVolume_ValueChanged(object sender, EventArgs e)
{
myPlayer.volume = trackVolume.Value;
lblVolume.Text = "Volume (" + trackVolume.Value.ToString() + "%)";
}
Up till now everything's great. Next I notice that if I click to the left
or right of the current position on the slider it only moves the Value by
the LargeChange amount. Ok fine, but what I want is to go directly to the
value that the user clicked on. By default LargeChange is set to 5. So if
the trackVolume.Value is at 10 and I click on 50 then the Value becomes 15
not 50. I checked the documentation and it says the Trackbar has a Click
event and a MouseClick event, but when I go to the events in VisualStudio
2005 I don't have either one (apparently my documentation doesn't match my
version of VisualStudio, but that's another problem).

Can anyone help me to go directly to the value that was clicked on the
trackbar?

Thanks,
John
Jan 3 '07 #3

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

Similar topics

9
by: punkin | last post by:
I am trying to catch mouse position on the entire screen by dynamically generating mouse click event at every 100 ms. My code only works for IEs but not any Netscape or Gecko-based browsers. The...
3
by: Geoff Cox | last post by:
Hello, I am using Visual C++ 2005 Express Beta 2 and cannot sort out how to use the Scroll property value for a trackBar. Under Event properties the name for the Scroll property is...
4
by: Bernie Yaeger | last post by:
I'd like to allow the user to zoom a window using a trackbar, say from 80% to 120% the size of the original window. I'm trying to do this with the following code, but it fails pretty miserably:...
0
by: deko | last post by:
I'm using VS05/.NET 2.0 with a TrackBar control in a Windows Forms application. I need to be able to manually scroll the trackbar (hold down left mouse button and drag), but I need to prevent...
1
by: Kris | last post by:
Hi. We are developing an application in VS2005 in C#, .NET, that has lots of tabs. On one of these tabs, there is a horizontal trackbar. However, we are unable to set the background color of the...
1
by: martins | last post by:
hi how can I configure/set the trackbar control in order to scroll between decimal values i.e. between 0.5 and 1 for example
4
by: _DD | last post by:
TrackBar DoubleClick event is not accessible via the Control Properties event pane. So I tried adding the handler directly: this.ColTrackBar.DoubleClick += new...
2
by: mmdst23 | last post by:
I'm working on a video player app, and I want to implement a trackbar that behaves like the one in Media Player, that is the cursor position moves to where the user clicked instead of moving in...
0
by: mehafi | last post by:
Hi, When i click on ScrollBar, to change it value, the delegate function ScrollBar_Scroll is called 2 times? When I click on TrackBar the TrackBar_Scroll is called 1 time. What is the difference...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.