 |
|
 |
I am more interested in a solution to a problem, and will not deign to suggest another approach. This one worked for me because I'm using it in a base class derived from UserControl, and further derived from by a number of other classes.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
 |
|
 |
John Simmons / outlaw programmer wrote: I am more interested in a solution to a problem, ... This one worked for me because I'm using it in a base class derived from UserControl, and further derived from by a number of other classes.
This is exactly why I still use this method in my forms and especially in the controls I've built, and this is why I haven't removed the article.
Thanks for your comment.
|
|
|
|
 |
|
 |
To test if the program is running under the IDE, use this test:
Process.GetCurrentProcess().ProcessName.Contains("vshost")
|
|
|
|
 |
|
 |
Thank you. That will be handy to know if we ever get VS2008 here.
|
|
|
|
 |
|
 |
"devenv" still works in VS2008, which means it will continue to work in VS2005 (and probably VS2003).
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
 |
|
 |
John Simmons / outlaw programmer wrote: "devenv" still works in VS2008, which means it will continue to work in VS2005 (and probably VS2003).
The most current version of VS I was using at work was VS2003, and yes, this method works with both VS2003 and VS2002.
How did your recent job search go? Successful, I hope. I just on Friday (12/12) joined the ranks of the laid-off, myself.
|
|
|
|
 |
|
 |
I found a job after about two weeks, and I've been there for about a month.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
 |
|
|
 |
|
 |
Thank you for the correct link.
(I'm pretty sure it *did* have the right link at one time)
It took me a couple of different approaches just now, but I've corrected the link.
-- modified at 7:27 Wednesday 29th November, 2006
|
|
|
|
 |
|
 |
Hi,
just for your info,
I've tried to download your sample code today (I am just courious and wanted to get a glimpse of it),
and had to find out the link is broken.
The current (broken) url is:
http://www.codeproject.com/useritems/DetectingTheIDE/DetectingTheIDE.zip
Still a good article.
Had a similar problem in the past and solved it just the same way as you did, by comparing the currentProcess.Name Prop.
Please type slowly, 'cause my English is realy bad
|
|
|
|
 |
|
 |
Lazal wrote: The current (broken) url is:
http://www.codeproject.com/useritems/DetectingTheIDE/DetectingTheIDE.zip
Code Project has move the location of the article but didn't update the link.
But, you didn't miss anything, as the sample code is just what's on this page. Here's a link that works: http://www.codeproject.com/KB/cs/DetectingTheIDE/DetectingTheIDE.zip[^]
Lazal wrote: Still a good article.
Thank you.
To tell the truth, I'm embarrassed by this article, it seems sooo noobie. But when I first needed to know this, I couldn't find anything on the subject; perhaps my search was inadequate. Still, others may find themselves in the same boat, so I'm leaving the article, embarrassment or not.
|
|
|
|
 |
|
 |
I guess I'm missing something here.
Why not use the property DesignMode?
"Gets a value indicates whether the System.CompoinenetModel.Component is currently is DesingMode"
It doesn't work on the Constructur (because the control still doesn't 'know' where he will be placed at) but in the Load event and all other places it does.
-- modified at 3:22 Saturday 8th July, 2006
|
|
|
|
 |
|
 |
Ignorance on my part.
Thanks for your note (even if I am now feeling embarrassed at my ignorance); for what I'm trying to do, the .DesignMode property is just what I need.
I've seen the property in relation to various classes. I'm fairly sure I looked up and read the documentation on it months ago (out of mere curiosity at the time) ... and forgot all about it when I needed to make use of it.
So, this article is mostly a waste of time ... unless one needs to know in the Constructor that the control is in design mode, or unless the component doesn't have an 'ISite' associated with it.
|
|
|
|
 |
|
 |
Either change the article to represent the fact it's not Detecting the IDE from a User Control into some else, or remove it?
We made the buttons on the screen look so good you'll want to lick them. Steve Jobs
|
|
|
|
 |
|
 |
"Either change the article to represent the fact it's not Detecting the IDE from a User Control into some else, or remove it?"
But that wouldn't make sense, since the code *does* detect the IDE and the concept *can* be used to detect the IDE from a UserControl (I do it all the time, since some of my controls contain code that shouldn't run under the development environment).
|
|
|
|
 |
|
 |
On the contrary, I tried two other ways to see if an app was in design mode, and this was the only one of the three that actually worked in my situation.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
 |
|
 |
DesignMode is a confusing property and I don't use it for
a number of reasons, the main one being that it only says
if an instance of the class that calls it, is being designed
(E.G., the class is open in a designer).
But for example, if the class being designed derives from
another base class, DesignMode when referenced from that
base class will always return false. That is because the
base class is not what is being 'designed'.
My needs are limited to knowing if my code is running in
the IDE, or not, and I do that by just checking the name
of the current process (if its 'devenv', then the code is
running in the IDE).
|
|
|
|
 |
|
 |
Good point.
I've never faced an issue like this with the DesignMode property I guess something it is not enough.
In the same issue, another interface that should be mentioned is the
System.ComponentModel.ISupportInitialize which describes 2 methods:
BeginInit() and EndInit().
When ever dragging a control that implements these methods, the designer automatically adds this command, this is usually a good place for placing methods with DesignMode question on them, before the load and after the constructor.
|
|
|
|
 |
|
 |
Tonyt,
Thanks for your comment. Checking the .ProcessName value is much cleaner than the try-catch method I came up with ... and it returns useful information in the Constructor, unlike the .DesignMode property.
For instance (assuming the variable 'gblRunModeIs_DesignMode' is defined), for what I want to do, the following code is just what I want for setting a boolean value I can check as necessary throughout the class:
if (System.Diagnostics.Process.GetCurrentProcess().ProcessName.ToLower() == "devenv")
{
gblRunModeIs_DesignMode = true;
}
|
|
|
|
 |
|
 |
Because DesignMode doesn't always do the trick.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
 |
|
 |
John Simmons / outlaw programmer wrote: Because DesignMode doesn't always do the trick.
Yeah, I later figured that out, so I'm still using the check-for-devenv method.
|
|
|
|
 |