Quick WindowsForms Tip
Ok, I saw basically the same question posted twice over at GDN and I just don't understand. Instead of complaining about it, I'll post it as a quick tip.
If you have a Form that needs to check a certain condition when it's loading and see if it should continue to load to close itself, don't bother. When programming, you should be thinking about every little drop of efficiency that you can squeeze out of your programs no matter how small. Don't get lazy just because it's not a big deal and won't use many resources. Do it right the first time. I'm not perfect at this by any means, but if you always strive for perfection, you'll be one step closer.
So if you have a Form that needs to do that, and for some reason, Me.Close isn't working...don't keep searching for an answer or a work around...sit back and think: Is what I'm doing the best and most efficient way to do it anyway? More times than not, the answer will be no and there is an easier way to do what you want and skip over your problem all together in the first place.
In this particular case, the answer is to not load up the form at all. Check for the condition before loading up the Form. If it is not met, then show a message and don't even load up the Form at all. If the condition is met, load up the Form and execute whatever code you were going to execute if the condition was met in the first place.
Sorry this was so long for such a small solution. I just sometimes get a little irked (sp?). Wait...Eriked? Woohoo, I'm a verb!
Anyway, the best advice I can ever give is to think, think, think...all the time, no exceptions. Think about what you're doing. Think about what you've already done. Keep the end result in your head all the time and constantly consider how what you're doing right now will affect the end result in a positive or negative way.
*gets up on soap box*
Master the art of evaluating situations, conditions, problems that need solving and there won't be a damn thing you can't do!
*gets down off of soap box*
0 Comments