Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / July 2007

Tip: Looking for answers? Try searching our database.

Skip some code in Design Time.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
deneb - 26 Jul 2007 01:10 GMT
Hi

I want to prevent some code to run in design time.

I have a base form that have some code in its Load event.
And I create a form inherited from base form.

When I watch the form design in design time, codes that is in base
form's load event are excuted.
The problem is that because it's design time, it couldn't work well.
So it always return some errors.

As far as I know below code can prevent code to run in debug mode.

#if debug then
#end if

Is there something like that can prevent code in design time???

I'm using Visual-Studio 2005 VB.NET.
Thanks :)
Empi - 26 Jul 2007 07:49 GMT
Hi,

Why won't you define a special "flag" such as :

#Const DESIGNTIME = True

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

#If Not DESIGNTIME Then

MsgBox("Hello")

#End If

End Sub

End Class

> Hi
>
[quoted text clipped - 17 lines]
> I'm using Visual-Studio 2005 VB.NET.
> Thanks :)
Peter Duniho - 26 Jul 2007 08:21 GMT
> I want to prevent some code to run in design time.

In the System.ComponentModel namespace, there are several Designer-related  
code attribute classes defined.  I haven't tried it myself, but one in  
particular looks like it might be useful: DesignerProperties, which has an  
IsInDesignMode property that can be used to check whether your component  
is running within the Designer.

http://msdn2.microsoft.com/en-us/library/system.componentmodel.designerpropertie
s.aspx


Note: this appears to be .NET 3.0 only.  I didn't check the others...if  
you need something that works in an earlier version, maybe one of the  
other Designer-related properties would still do the job and yet is  
available in an earlier .NET.

Pete
count0 - 26 Jul 2007 11:48 GMT
> Hi
>
> I want to prevent some code to run in design time.

[]
> As far as I know below code can prevent code to run in debug mode.
>
> #if debug then
> #end if
>
> Is there something like that can prevent code in design time???

Check Component.DesignMode property,
Mythran - 26 Jul 2007 16:29 GMT
>> Hi
>>
[quoted text clipped - 9 lines]
>
> Check Component.DesignMode property,

Microsoft.Net Framework v1.1.4322 and above (and may work for v1.0 as well):

if (this.Site != null && this.Site.DesignMode) {
   ... currently in design mode ...
} else {
   ... not currently in design mode ...
}

This works for us and we use it for web controls and web forms to prevent
code from executing during design-time (and for some forms, to make sure
some code ONLY runs during design time).

HTH,
Mythran
deneb - 27 Jul 2007 00:39 GMT
Thanks all guys.

Because I use .NET Framework 2.0, I can't use DesignerProperties in
System.ComponentModel of .NET Framework 3.0.
But, Component.DesignMode property does work well.

I really appreciate for your help.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.