With C# How to detect that code is exec in IDE of VS 2008 ?

Hi experts!

  Im using C# 2008 , WinForm NET 2. And get this strange behavior:
I have a form  called CommonForm.cs. And have other form, which are inheriting this form, I mean public partial class frmCamp : CommonForm

 I put command to Form Load of CommonForm.cs. Some commands are OK, but when I put one command which open Datareadear from SQL Server I get strange behavior.

 I get error message in Designer when try to show form design of frmCamp which call FormLoad of CommonForm.cs. This is for all form which are based on CommonForm. Message is: Connection property has not been initialized and I can not see design of my form at all.  When I remove code from FormLoad CommonForm.cs which open DataReadear error message disaper.

 Look like Im in desing mode to create forms, but I face with real execution of FormLoad of CommonForm and get this error message bacuse connection is not Open. I open it on other class, when Im in run mode it is OK.

 So question is: how can I detect that my program is under Design mode of IDE of VS2008 and to stop execituon ? I mean somethin like this:

        public static bool bBlockFunction()

            If (bISDesignModeOFIDE) return false;

            string SQL = "SELECT CanLog,GroupCanLog,bEnable,LUpd,Info FROM dbo.qryLogOn WHERE UserID=" + g.UP.UserID ;

            SqlDataReader reader = gDs.GetReader(SQL, g.PR, 0);

            using (reader)
                    if (!g.bVar(reader["CanLog"]) )
                    { g.Msg("You personal account  i



Or - second option - how to tell to IDE that this is nor citical error and to show me design of form ??? In general problem is that I can not see design of my form after this error message.
Who is Participating?
GuitarRichConnect With a Mentor Commented:
you can use this.DesignMode
You can use the following:

if(this.DesignMode) {    // inside design mode}
it will work in a user control and inside a form.
ha able - beat you to it this time :)
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

You could try testing if you are in Debug mode or not.

Note that you will need to your EXE to be a Release version.

    Console.WriteLine("Debug version");

Open in new window

> second option - how to tell to IDE that this is nor citical error and to show me design of form ???

you can always put in a try/catch and just continue. Put the expected error in the catch clause. However, be aware that you will also catch a legitimate error in runtime, so I would not recommend that approach.
> ha able - beat you to it this time :)
haha, indeed ;-)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.