Considering that we do not know God's ultimate plan, and we know that things that seem good now can actually turn out to be for the better down the road, we must also assume that things that seem good now can also turn out to be bad down the road. Thus, how can we thank God for anything good that happens to us if it could really be a mixed blessing, or even a curse in disguise?
- Anybody can ask a question
- Anybody can answer
- The best answers are voted up and rise to the top
Thus, for bad events we should also be thanking God, but since brachos look at what just happened we instead make the bracha "dayan HaEmes". Nevertheless, it should be said with joy since "al is for the good". (Rambam Hil Berachos 10;3 from Berachpos, ibid)
Also see Rabbi Sacks has an interesting lecture on this topic and differentiates between the perspective of Halacha and Agaddah.
Though not to detract from @Yoni's answer, which was great and authoritative, I would like to offer a perspective that is more general in principle. Man needs to praise and bless the Creator, always, because He is the Creator and we are not. At the same point, blessing the Creator effects a change in man as well; it changes our consciousness to a sort of awareness of the divine. It is true that all the Creator wills is for the good, so we can rest assured that even though we might attach a blessing to something particular, we are also blessing Him for His greatness. This way, when something goes wrong, we have the proper consciousness to understand that the Blessed One is behind everything and has our best in mind for the outcome.