Join 136,076 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 1,581 people online right now. Registration is fast and FREE... Join Now!
Hi there, im designing a calculator for WM6 using .NET 2.0 and would like to have a sliding notepad sorta panel come into view from the right when the user clicks a button, and obviously to slide back out of sight at a later time, i am just wondering if there is anyone out there whos attempted a similar sliding animated effect and how they chose to do it, if not how would you go about this?
Im thinking something related to the tan function so that it starts slow, quickly speeds up and the is slow at the end.
*edit* i know that with the tan function i will be changing the value of panel.Location.x to make it slide, what i want help with is what sort of time should i be using for this so that it takes maybe 0.5sec to get from 239 to 0 and how exactly to use the timer and tan function together effectively to acomplish this without eating resources and still having the two panels contents drawn? i have turned autoscroll off for the below panel */edit*
This post has been edited by bstdnator: 10 Apr, 2008 - 02:45 AM
what you will have to do is first figure out how for it will move each time. (i.e.. from 239 to 191.2 would be -47.8) -47.8 would be how far you need to move in a second 47.8 * 5 = 239. Now remember you can work in Milliseconds. 1000 Milliseconds = 1 second.
So, what I would do is create a method on a separate thread that movies the panel as far as I want it to move each time and then having the thread sleep for a time in Milliseconds then have it move again. By doing this the user will see the panel move for right to left sense you what to go from 239 to 0;
Excellent flow, but I would have to make 1 modification. Since you cannot modify a GUI control from outside the thread that initially created the control, which would be the applications main thread, he would need to use a delegate to marshal the call onto the GUI thread in order to access the control itself for modification, ie; sliding it
Since you cannot modify a GUI control from outside the thread that initially created the control, which would be the applications main thread, he would need to use a delegate to marshal the call onto the GUI thread in order to access the control itself for modification, ie; sliding it
?? Sorry PsychoCoder i have no idea what you just said, all i got from that was that i cant do it from the thread that im in, and something about a delegate which im not too farmiliar with but know that its a way of calling a method?
zakary - The sliding motion you suggest would have the panel move equal distances each time, i would *Love* to see this linked into some sort of sin/cos/tan function so that the panels moved distance is a function of time or how far it is from its start/goal.
ie. i want the panel to initially begin to move slowly, then get faster and faster, at half way be at maximum speed, then slowly begin to slow down, slowing much faster towards the end so that at the end it is moving very slowly again maybe a diagram would help...
Well, something like that... Also what is the command to get the current time in MS? im guessing at System.CurrentTimeMili() ? or do i use new Date(System.Now) or something like that?
int milliseconds = System.DateTime.Now.Millisecond;
so to speed this up and slow it down you will need to increase and decrease your thread sleep time Like
csharp
int milliseconds = 100; System.Thread.Sleep(milliseconds); milliseconds += 100;// or some other number that increase System.Thread.Sleep(milliseconds)// milliseconds will be 200 milliseconds -= 100;//decreases by 100 System.Thread.Sleep(milliseconds)// milliseconds will be 100
to be honest with you, you havent answered my question at all. i want the distance moved to change not the time between movements. and i want to link this to a tangental function to make the movements fluid and pretty. I am not that great with trigonometry and wouldnt know where to start with sensible values for the tangent function to be adjusting the distance moved by. i guess what i need is some sort of function that is going to take as an argument the distance from the start position, put this into a tangental function and return the distance for the next step to move the panel. if you could help me out with this function i would be very grateful. Also what PsychoCoder said about delegates and not being able to call the gui changes from the parent control or something? that makes no sense to me.
First of all you will have to write your own tangential method I believe a Tangential is nothing more than a System.Random number, so you will have to use that to increase and decrease your size. So, you will have to create a variable
csharp
float number = 0; System.Random random = new System.Random();
do { number += random.Next(239); }while(number >=239);
a delegate is similar to a function pointer in C or C++. Using a delegate allows you to encapsulate a reference to a method inside a delegate object.
here is and example using delegates I got from "http://www.akadia.com/services/dotnet_delegates_and_events.html"
csharp
using System;
namespace BasicDelegate { // Declaration public delegate void SimpleDelegate();
class TestDelegate { public static void MyFunc() { Console.WriteLine("I was called by delegate ..."); }
public static void Main() { // Instantiation SimpleDelegate simpleDelegate = new SimpleDelegate(MyFunc);
thanks for the help with the delegate, i will give it a try, not quite sure what PhychoCoder means and where i should be doing what with that though.
As for the tangent Math.Tan(angle) where angle is in radians and between 0 and 2*Math.PI, the idea of the tangent thing is to make it smoothly travel across the screen with varying degrees of movement between steps (and then maybe when its within 20 pixels to snap into place) but i am not sure what sort of sensible values to use for it to have the full motion from off screen (x=239) to fully ocupying the screen (x=0) happen in roughly 1/4 to 1/2 a second, basically i need help with the maths to acomplish this . The idea being to use that somehow to have the distance moved between steps change in a gradual but fluid way. i dont know there might be a better function to use but between -PI/2(-90degrees) and PI/2(90 degrees) that is pretty much how i would like the motion to be if you know what i mean?
*EDIT* maybe sin between - and 180degrees would be much easier as it is going from 0 to 1 and back.
This post has been edited by bstdnator: 10 Apr, 2008 - 10:54 AM
I wrote a tutorial on cross thread communication, using a delegate to marshal a call onto the UI thread for accessing UI controls. This is required because, as I stated in my original post, you cannot access a UI control from a thread other than the thread that created the UI control (the main application thread).
This is important for what you're trying to do simply because in order to make it work it will need to be in a separate thread, so it can do it's work without locking the UI up and making it unusable. Second, since the processing will be taking place in a thread other than the main thread (the one that created the UI control), this is the only way you can access that UI control.
thanks guys, your help is much appreciated. sadly however i didnt realise this would be such a big task, was hoping to have the new panel sliding and put a TabControl into it with 4 tabs with inputboxes, have those saving to file when the panel closed (on a menubutton) and have save as and open dialogs implemented by now. basically im out of time, and adding the aformentioned parts to make 4 serialised notes panels is going to be put into future work for my project now i also wanted to have history items saved and loaded for the calculators all done but i think that is something i will be doing before the end of the report (report and code to be completed by 24th of this month) as well as my other project report & code (5th may) and presentation (29th april).
so i guess unless somebody would like to write it for me its not going to be done on time, nevermind all is not lost, i've still done a shed load on the calculator as it is now on with the reports. again, thankyou for your help