As others have said, the company makes a big difference and can either negate or cause further frustration. I think perspective and attitude has a lot to do with it as well though. I've tried to continually get better at thinking ahead, taking the "every hand starts at 0" approach, and not being results-oriented. I'm definitely not tilt-proof, but I think I've gotten better at accepting the volatility of the game and the fact that sick things happen every so often no matter how you play (and you have to appreciate this, even when on the receiving end of a beat, because that's part of the entertainment value that attracts so many players, particularly the long-term losing gambler types).
Whether I win or lose over the course of a session, I always try to reflect and analyze my decisions and think about how I can improve. I think this is partially the math teacher in me - I like to think of the game as an intricate puzzle with many variables, some of which I can interact with and some I can't, and how I can "solve" a certain hand, an approach against a certain player, or my overall strategy. It's also probably a little of the track athlete in me. When you're as mediocre as I was at it you focus more on self-improvement than actually winning gold medals. In a way I think I approach poker as a competition against myself just as much as the other players, and this gives me the ability to pat myself on the back when I played fine but still lost, or punch myself in the nuts when I know I played poorly but got lucky.
If you haven't been enjoying playing with a certain group lately I would say take a little break from that particular game, or maybe rethink how your strategy for that group might need to be tweaked compared to your default gameplan. Accept chance and be ready for sickness, but control the things that you can to the best of your abilities. Don't worry so much about winning and losing and concentrate on just playing better and making the right decisions, regardless of the outcome. When all else fails, watch bad beat videos of pros losing bajillions of dollars or think about all the other amazing things in life outside of this stupid game.