I think lots of us are sympathetic to your weight gain. I know I gained weight because I decreased activity over time as the pain increased. Then, I took meds that plumped me up even more. At that point, it's really easy to throw in the towel and eat the cheeseburgers.
BUT! You really can keep your weight under control and it will take concerted effort on your part. Like, buying and preparing low-calorie, filling snacks. And eating them rather than cookies! I make a sack of snacks either the night before or morning of my day and my rule is that I only eat what's in that sack until dinner time.
I also reduced my calorie intake a bit given my reduced activity. That simple math really (sadly?) does the trick. I've added in protein shakes - not super delicious, but they really reduce my cravings for unhealthy snacks.
I use a website to track my daily calories and protein/carb/fat balance. There are several good ones out there and they're worth the about $5-10/month they charge. So for example, if you have a big, rich restaurant lunch, you can see that you might want to go lighter at dinner. Starving doesn't work.
Plain old common sense and maybe some self-forgiveness have helped me lose 10 lbs in the last 2 months. It's not quick, but I do enjoy my jeans fitting a little better!
Best of luck to you - you are not alone in this struggle!