473,418 Members | 2,090 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,418 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 18807
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
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.