Yes, intent and tone are important, as is your relationship with the other person. My rule of thumb is that if I think being proud of myself is likely to make someone else feel bad, I'll keep it to myself. Otherwise it's fine. I think it's not really "bragging" when you're not implicitly saying you're better than other people, though; that's just being proud of your accomplishments, which I agree is healthy. Posting something in public, like this thread, is also very different from discussing it in private. You have a lot more leeway around someone you're close to.
People can overcome their environment, yes. And if you had a shitty environment and grew up into a productive and successful person, then I wholeheartedly congratulate you, because that's difficult to do. But your environment has a huge impact on the kind of opportunities you have. Maybe you've overcome a disadvantaged situation, but a lot of people can't, and it's not their fault they started with less in life than others.
The problem with saying "grades are a result of your hard work, and my life was shitty and I turned out okay, so why can't everyone do the same" is that it ignores the very real impact that things outside of your control have on you. It's like the classic problem with the American Dream. "Just pull yourself up by your bootstraps," says the man who won the lottery.