Trackbar events

D

David Glover

Hi all,

I have a trackbar in a .NETCF application. I wish for the following to
happen:

1) To allow the user to select a position in the track bar causing
another method to be called (a method in an imported native DLL)

and

2) To have the position of the track bar updated from another method
(a timer click most likely) and for the relevant position to be set.
This is actually implementing a slider to scroll through an MP3 to put
this work in context. However, I do not want the update from the timer
to cause the first trigger code to run.

My initial idea was to put the first block in the Scroll event of the
TrackBar, and then just call trackBar.value = ... from the timer
click. This appears to work when using an .NET app, however when I
write the code for a .NETCF app, the scroll method is not present.
This only event even close is ValueChanged - which will be called in
both cases (update from the user or programatic update).

Is there any way to seperate these two "triggers" using the trackBar
control? Do I have to write my own control? Does anyone know of such a
control?

Many thanks,

David Glover
 
P

Peter Foot [MVP]

When you are moving the control yourself, you can implement a Boolean flag
in your code so that you ignore the valuechanged event.

bool updatingTrackbar = false;

e.g. in your onvaluechanged method encase all you code in

if(!updatingTrackbar)
{
}

Then when you want to move the bar from code set the updatingTrackbar to
true (setting it back afterwards)

updatingTrackbar = true;
trackBar1.Value = x;
updatingTrackbar = false;


This way although the ValueChanged event still fires you are ignoring it if
the change was a result of your own code. User changes will be processed as
normal.

Peter

--
Peter Foot
Windows Embedded MVP

In The Hand
http://www.inthehand.com
 
D

David Glover

Thanks for that. This was going to be my next approach however I was
wondering if there was a different approach.

Why is the Scroll functionality missing in the first place? Is it
because you could argue a user cant scroll with a stylus, or is this
another case where the functionality has been trimmed from the control
to allow it to reduce the overall footprint of the .NET CF. Is there a
full list of the restrictions (at least on things like WFC stuffs and
possibly other .NET controls) anywhere?

Thanks again.

David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top