I work in an office but the profession i am in (Social Work) means there is a real mix of clothes - from very casual to smart.
I probably verge more on the smart/casual, as opposed to smart proper office wear (no suits!)...I wear dresses with tights usually. But now that the better weather is here I will wear a mix of chinos/tops and dresses/leggings. Some of the dresses I wore with tights won't look right with leggings though. They are a little smarter - in my mind anyway. For court I would always wear a dress and tights. I don't own a suit but usually wear a jersey blazer.
I wouldn't wear leggings to a smart function, no. I would wear them on a night out though. Dinner and drinks with friends - yes.
Smart functions - including weddings, christenings etc I would usually wear a formal dress to just above my knee with tan and heels.
I think that's part of the issue - I don't wear heels during the day - maybe if I did I would feel more confident baring my legs!
So, running - when I say I replace tights with leggings it's not including very formal functions/settings. It's a cooler alternative as I find tights very warm. It's also a casual alternative.
I would never wear leggings as trousers. I would feel like I am out wearing tights and a top! But that's more to do with my weight than anything else. Friends have come out wearing the leather look leggings and look amazing 
Someone mentioned feeling overdressed and I often feel like that - I have very casual dresses that cost £12 which I wear with leggings, pumps, a nice scarf and nice jewellery. It's casual for me but seems quite dressy.
I should probably add - if I was a size 10 with perfect pins I probably wouldn't wear leggings!