Re: What are the rules for Me.DesignMode
- From: "Academia" <academiaNOSPAM@xxxxxxxxxx>
- Date: Wed, 23 Jan 2008 09:44:49 -0500
I wanted a library function so I changed in 3 places.
I read the help about the Site and got a feeling but not a real deep
understanding.
I'm guessing c.DesignMode is obtaining a property from c, which gets it from
Site. Correct?
While c.Site.DesignMode is going through c to the object Site which returns
the value. Is that correct?
Thanks a lot
Actually I was looking into Phil W.'s #1, but Help has very little on IIRC
and I hadn't searched the Internet yet. I don't think I ever would have
stumbled onto "Site".
Public Shared Function IsInDesignMode(ByVal c As UserControl) As Boolean
' Returns true if this control or any of its ancestors is in design mode
If c.Site.DesignMode Then
Return True
Else
Dim parent As Control = c.Parent
"Claes Bergefall" <claes.bergefall@xxxxxxxxxxxxx> wrote in message
news:%23BtvAZbXIHA.1132@xxxxxxxxxxxxxxxxxxxxxxx
Actually, doing #1 is pretty easy. The DesignMode property gets its value
from the Site property (which is public). Try this:
Private Function IsInDesignMode() As Boolean
' Returns true if this control or any of its ancestors is in design
mode
If Me.DesignMode Then
Return True
Else
Dim parent As Control = Me.Parent
While Not parent Is Nothing
Dim site As ISite = parent.Site
If Not site Is Nothing AndAlso site.DesignMode Then
Return True
End If
parent = parent.Parent
End While
Return False
End If
End Function
/claes
"Phill W." <p-.-a-.-w-a-r-d-@xxxxxxxxxxxxxxxxxxxx> wrote in message
news:fn4imc$snp$1@xxxxxxxxxxxxxxxxxxxx
Academia wrote:
If Not Me.DesignMode Then
MessageBox.Show("Got here " & Me.DesignMode.ToString)
When I Show Designer for a Form that contains a UserControl that
contains this UserControl and then I click the X in the Designer so the
Designer closes the Form, this message box displays:
Got Here False
How come?
Because the UserControl /isn't/ being hosted by a Designer - it's on a
proper Form - so it doesn't think it's in "DesignMode".
Two ways around this:
1) Check the DesignMode property on the Parent Control (tricky because,
IIRC, it's Protected and you have to add /another/ property to expose
it), or
2) (Quick and dirty) Find out what program the Control is running in and,
if it happens to be "devenv" - the 'Studio IDE - then /assume/ you're in
DesignMode (when you /debug/ the program, it'll be your exe name that
appears).
Dim sExePath as String _
= System.Reflection.Assembly.GetAssembly().Location
Dim bDesignMode as Boolean _
= ( sExePath.ToLower().IndexOf("devenv.exe") > -1 )
HTH,
Phill W.
.
- Follow-Ups:
- Re: What are the rules for Me.DesignMode
- From: Academia
- Re: What are the rules for Me.DesignMode
- References:
- What are the rules for Me.DesignMode
- From: Academia
- Re: What are the rules for Me.DesignMode
- From: Phill W.
- Re: What are the rules for Me.DesignMode
- From: Claes Bergefall
- What are the rules for Me.DesignMode
- Prev by Date: Re: Problem inserting a GUID into an UniqueIdentifier field on SQL
- Next by Date: Re: What are the rules for Me.DesignMode
- Previous by thread: Re: What are the rules for Me.DesignMode
- Next by thread: Re: What are the rules for Me.DesignMode
- Index(es):
Relevant Pages
|
Loading