Re: What are the rules for Me.DesignMode



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.




.



Relevant Pages

  • Re: Controls - Page_init order
    ... the control after the Page_Load. ... Parent that says "Inside the Parent Page_Load", ... e as EventArgs) Dim sTest as String trace.warn("Inside the ... execute first before anything else since it is initialization code. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: What are the rules for Me.DesignMode
    ... ' Returns true if this control or any of its ancestors is in design mode ... Dim parent As Control = Me.Parent ... contains this UserControl and then I click the X in the Designer so the ...
    (microsoft.public.dotnet.languages.vb)
  • RE: Adding an item to a designer host programmatically
    ... The following code sample will programmatically add a control to a ASPX Web Form from the INIT method of another control. ... It solves the problem of the designer not displaying the control. ... Dim host As IDesignerHost = CType), ... Dim ccea As ComponentChangedEventArgs = New ComponentChangedEventArgs ...
    (microsoft.public.dotnet.framework.windowsforms.designtime)
  • Re: getting the row number in a datagrid
    ... Use can use the parent control to find the index. ... deal with CustomValidators in datagrids, I seem to recall some issues ... Dim valCustomControl As New CustomValidator ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Trouble referencing controls within list controls
    ... Use can use the parent control to find the index. ... with CustomValidators in datagrids, I seem to recall some issues with ... Dim valCustomControl As New CustomValidator ...
    (microsoft.public.dotnet.framework.aspnet)

Loading