|
Hey all, in my application, I came up with an idea. I want to be able to shake the window to be able to perform a common function that would normally require atleast a few mouse clicks. And depending on how long the user shook the window, the resulting function will differ, accordingly. I've already started coding (The planning stage made it even harder, so I decided to get my hands a little dirty). But the code that I have now, is so cra& that I'm too embarrassed to put it here for everyone to see lol.
Here's what I've trying to accomplish:
Determine whether the user shook, or moved the window.
If shook: then see how long it was shaken for.
if shaken for less than one second: perform function 1.
if shaken for 2seconds: perform function 2.
if shaken for 3seconds: perform function 3.
If the window did not shake, instead it was just moved to another spot, then don't do anything.
I'm not asking for code, but if somebody does know of any tutorials, samples, or articles that may be of help, please do share I have searched on Google etc, and I've only been able to find one article and about 50trillion sites that refer to that one article (and I can't use it since it only work on Windows 7) I've tried it and the bugger just won't work on XP. (or my other computer that runs Vista).
I'd appreciate any help I can get. Thanks everyone.
Regards,
Jason Pezzimenti.
|
|
|
|
|
You want to handle the event when the form moves, and then track movement to determine if it's a shake and use a timer to work out when the shaking stops.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Thank you Christian, I had something similar to that, but I didn't use a timer. I'll give your suggestion a whirl and see how things go.
Regards,
Jason Pezzimenti.
|
|
|
|
|
Any notes on the velocity or vigorousness with which the window would get shaken?
As for the checking if it was shaken, you may want to check if the window is within X pixels of it's original location.
ResizeStart and ResizeEnd should work good.
Ninja (the Nerd)
Confused? You will be...
|
|
|
|
|
Thank you for the advice Ninja-The-Nerd, I'm a little confused as to why I would need to use ResizeStart and ResizeEnd.. Aren't they only for when the form is resized? Or am I wrong about that?
Ninja-the-Nerd wrote: Any notes on the velocity or vigorousness with which the window would get shaken?
Well, The shake needs to be quick. Kind of like when you have to shake a Juice bottle before opening it.
Regards,
Jason Pezzimenti.
|
|
|
|
|
ResizeStart will only fire when the user starts to drag the edges (or you use the keyboard "shortcut" of alt+space, s, and arrow keys) and ResizeEnd fires when the user lets go.
How to determine whether it was a shake or not, I would judge if the average velocity was, um...
If the user was moving it one way then the other then...no, ehh
On reflection it might be wiser to simply check if the window is within, say, 20 pixels of it's start location.
ResizeStart: note the position, start the timer.
ResizeEnd: stop the timer, compare the position, execute the function.
Edit.
In fact, just ignore this.
It's late, I've been coding for several hours. I failed to notice that resize != move.
I'll just get my coat and leave...
Ninja (the Nerd)
Confused? You will be...
|
|
|
|
|
Hmmm... Good work Ninja! That was very easy to understand and helpful. I'm workiing on it now and will post the code here once I'm done. Thank you
Edit: Hahaha, sounds like you need some sleep :P Thanks for your help anyways, it was much appreciated.
Regards,
Jason Pezzimenti.
|
|
|
|
|
OK sorry for the previous ludicrous suggestion.
I once had a borderless window, and to handle the movement, I had added a button which, when dragged, would take the window with it. I know you're trying to reduce clicks but this could work.
MouseDown:
- set "moving" to true
- store mouse-coords in "lastLoc"
- store window position to "startPos"
- start a timer
MouseMove:
- if moving,
- move window by delta (current location - lastLoc)
- update lastLoc
MouseUp:
- set "moving" to false
- stop the timer
- compare startPos with current position, etc.
Ninja (the Nerd)
Confused? You will be...
|
|
|
|
|
|
Nope, I get it. After many re-reads... :P
What's timer1's Interval set to?
You could try to determine if the location has changed since the last Tick event. If it hasn't, the drag is over and it should just tidy up/do nothing.
I'd try just now, however that sleep I hoped for is beckoning.
Ninja (the Nerd)
Confused? You will be...
|
|
|
|
|
Hehe,
Ninja-the-Nerd wrote: timer1's Interval
Interval: 100; (Default)
Ninja-the-Nerd wrote: if the location has changed since the last Tick event. If it hasn't, the drag is over and it should just tidy up/do nothing.
Thanks doing it now
Ninja-the-Nerd wrote: I'd try just now, however that sleep I hoped for is beckoning.
...Yeah, I like sleeping. Although I have about 10 hours to go til I can sleep again :P
Thanks for all your help, and if you're goin to sleep now, I'll keep yah updated in this thread thingy-ma-bob
Regards,
Jason Pezzimenti.
|
|
|
|
|
I've two classes, here is an example of 'em
class A
{
string prop1;
public string Propery1
{
set { prop1 = value; PropertyChanged(); }
}
protected vitual void PropertyChanged()
{ }
}
class B : A
{
A instanceOf_A;
protected override PropertyChanged()
{
}
}
now, I want that when any property(of base class) of B changes then it should change the same propery of instanceOf_A . I can do this if I pass a property name as param from every property and then change value using PropertyInfo in PropertyChanged . But I was wondering that is there any way to know which property changed or which property called PropertyChanged , something like callstack...
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKQUFK[M`UKs*$GwU#QDXBER@CBN%
R0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
-----------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
Xmen W.K. wrote: A instanceOf_A;
Is this required? B is derived from A and when B is instantiated, A will also get instantiated.
|
|
|
|
|
N a v a n e e t h wrote: Is this required?
yes...its for keeping the actual data in it so that it can be retrieve when require. In the previous version of that class I used a physical file to keep the data but now I need it in class.
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKQUFK[M`UKs*$GwU#QDXBER@CBN%
R0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
-----------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
Doesn't the PropertyNam e property of the PropertyChangedEventArgs class gives the name of the property thats changed?
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|
|
yes but it needs to be initiate from every property with PropertyName and I think thats the only way
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKQUFK[M`UKs*$GwU#QDXBER@CBN%
R0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
-----------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
I wonder how can i convert 0x10 to 0x11 inside the array. I need u guys help.
byte[] data = {0x47, 0x55, 0x03, 0x10, 0x00, 0x81, 0x00, 0x0b};
|
|
|
|
|
|
or byte[] data = {0x47, 0x55, 0x03, 0x11, 0x00, 0x81, 0x00, 0x0b};
or data[3]++;
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
YEap, that helps me alot ..but if i run my program again, hwo to make my program start from 0x11 instead of 0x10;
|
|
|
|
|
Hi,
you may want to ask a clear question, that should help in getting a clear answer. as my sig says.
Most of us aren't very good at reading someone's mind.
if your problem were that you want your program to behave differenly each time it runs, you need to persist some state outside the process, maybe in a file, or in the registry.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
for(; ; )
if (0x10 == byte }
byte = 0x11
|
|
|
|
|
how could I make double (key events) In C# programming language
I mean
when the user click(press) on the keyboard (a && b)together (maybe 3 or 4 keyevents)
how could I respond to all of them
plz help..
|
|
|
|
|
You may want to refer back to the orignal answers you got here[^], but never responded to.
Don't repost the same question over again. The answers you get will not change.
|
|
|
|
|
how i can create query wizard in c sharp and sort that in datagridview
|
|
|
|
|