"…And Yosef was in Mitzrayim (Shemot 1:5)."
Yosef's preceding of B'nei Yisrael down to Mitzrayim, was Hashem preparing the cure before the blow. Yosef descended to Mitzrayim as a slave which is an aspect of bitterness and sadness, which is an aspect of slavery. He then withstood his test and strengthened himself even there (in Mitzrayim) with happiness, as the verse says, "And Yosef was a man of success." The Midrash tells us that this means that he was constantly singing and dancing.
For in the bitterness of the exile when the bitterness strengthens itself very much, this is the primary advice, to do silly and fun things (like singing and dancing) in order to cheer up your soul during the bitterness. Just like it is written with regards to King David that he changed his appearance (behavior) before Avimelech, for at that time he was in great danger and in a great exile, so in order to save himself he began to act crazy and he let his spit drip down on his beard, etc. Therefore our main existence in Mitzrayim and our eventual departure from there was all because of "Yosef who was in Mitzrayim," therefore, Hashem sent Yosef Hatzadik down there first.
(Likkutei Halachot on the Parasha)
This was not only the secret of Yosef Hatzadik and David Hamelech, it is also our weapon in order to enable ourselves to cope during the tough times. Rebbe Nachman teaches that clapping hands and dancing has the ability to literally mitigate any harsh decrees that might be upon us or Am Yisrael (see Likkutei Moharan, lesson 10). The real truth is that there is nothing bad ever happening, and that everything is really for the good. We, because of our limited physical sight cannot see things in this broader perspective, which is why we can experience something as bad. Through the practice of clapping and dancing as well as thanking Hashem for the apparent bad situation we are in, we allow ourselves to go above the level of our own limited understanding and we open up the possibility of letting in Hashem's miraculous salvations. You see, once we can be happy and thank Hashem, then we have passed the test of faith which was the very reason why Hashem concealed himself and the good in the first place. May we all be blessed with being able to see the true good in everything, but until then, we have the Rebbe's classic advice of, "Fake it 'till you make it!"
(Picture taken from http://www.chabad.org/)