There are two issues here: one is what you feel, the other is what you do.
What you do is the easier of the two to control. There are a number of tricks you can use to help you with this. I can list a few, and you can make up more of your own, what's important is to find what works for you. When you're feeling one emotion, imagine feeling a different one, and force yourself to act according to the different one. You may have experience with this at work with a difficult customer or client, who you can't yell at, so you say, "thank you, sir" in your most polite voice. Or, imagine you're an actor, whose job it is to portray a certain emotion in your actions. An actor does this even when they don't feel that emotion, or when they feel a different one, and so can you. When I was in high school, I had a girlfriend who could be a bit difficult or frustrating at times. When I felt like yelling and strangling her, I would instead give her a hug and say, "I love you," (reaction formation) and you know what, it calmed us both down. You can imagine a different emotion and act accordingly, and the more you do it, the better you get at it. Think of it as a "fake it until you make it" approach. How would a happy person act right now?- then do that. Or ask yourself how Clint Eastwood would handle this, and do your best Clint Eastwood. Next thing you know, it's handled the way you think it should be. (Feel free to substitute James Bond, Hannibal Lecter, Axl Rose, Gecko45, Micky Mouse, or whoever else you think would handle the situation best.) The best idea, though, is to picture an ideal version of yourself, the person who would handle everything exactly the way you wish you could. Spend time with this character until you know him inside and out, until you can predict his every move, and approve of each one. Then, act like him, as best you can, every moment. Keep it up, and you'll find yourself getting closer and closer to the person you want to be.
To list just two competing psychological theories of human motivation and behavior, one states that human behavior is teleological (that is, driven by its goals) while the other states that behavior is driven from behind, by whatever force (emotion) pushed it. Now you can see the difference, between people acting in order to get something they want versus people acting because of how something makes them feel. Rather than debate which theory is correct from a descriptive standpoint, think of them as two options, between which you are free to choose. Now you can act a certain way because it will get you what you want, or you can act a certain way because of how you feel. Which of the two is most likely to give the outcome that will make you happiest?
It can be difficult to control your emotions at times, but you are always in control of your actions.
Controlling your actions can have a beneficial effect on your emotions.
As far as controlling your emotions, which is more difficult, you can still do it, you just have to understand them. One way is just to take the emotion you're feeling and look at it. Take it out of your head and examine it, like it's a thing in your hands. Doing this will help you feel it less, and will help you understand it more. Once you're done examining it, you can toss it out the window if you don't want it anymore, or you can take it back inside yourself if you like - that's up to you.
There are two ways that emotions take hold of us. Sometimes they creep in slowly, a little bit at a time, other times they just show up at once, fully formed and everywhere. Either way, when you feel an emotion taking control of you, you can stop it. Really, you can. It's yours, and it can't even exist, let alone do anything, without your permission. Once you realize this, and revoke permission to an emotion you don't want, you'll see that you are the one in control. After that it's just practice and technique.