DesignMode, UserMode, RunTime?!?! For OCXs


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 7 of 7

Thread: DesignMode, UserMode, RunTime?!?! For OCXs

  1. #1
    Francois Gibeau Guest

    DesignMode, UserMode, RunTime?!?! For OCXs


    Hi All,

    I have a total black out and cannot remember how 2 years ago a team I was
    working with had implemented the solution to the following:

    In VB when the user control designer is openned and one can place constituent
    controls in it its called as the 'DesignTime' and can be verify by 'Ambient.UserMode
    = False'
    When the designer is closed and an instance of the control class is placed
    on a form 'Ambient.UserMode = True' which indicates the UserMode (user full
    for resizing the control conditionally).

    Now when one hits F5 or runs the application: How do we develop an OCX capable
    of differenciating between its own UserMode and the RunTime of the application?????

    All the code below didn't help me remember, anyone knows please???

    Debug.Print App.PrevInstance
    Debug.Print UserControl.Ambient.UserMode
    Debug.Print UserControl.Ambient.UIDead

    Dim obj As Object
    Dim obj2 As Object
    Dim obj3 As Object
    Dim obj4 As Object
    Set obj = UserControl.Controls(0)
    Set obj2 = UserControl.Extender
    Set obj3 = UserControl.Extender.Container
    Set obj4 = UserControl.Extender.Container.Parent
    Debug.Print TypeName(obj), TypeName(obj2), TypeName(obj3), TypeName(obj4)
    Debug.Print obj.name, obj2.name, obj3.name, obj4.name


  2. #2
    Mark Jerde Guest

    Re: DesignMode, UserMode, RunTime?!?! For OCXs

    Francois,

    > Now when one hits F5 or runs the application: How do we develop an OCX capable
    > of differenciating between its own UserMode and the RunTime of the application?????


    I use the function below.

    -- Mark

    Public Function InIDE() As Boolean
    ' Returns True if the program is running in the IDE, False
    ' if the program is compiled.
    '
    ' Adapted from the thread "Detect if in IDT? Detect if
    ' a form is present?" of 10-26-98 & after in the
    ' vb.general newsgroup of www.devx.com
    '
    Static Started As Boolean, IsInIDE As Boolean
    '
    If Not Started Then ' ... divide by zero once
    Started = True
    On Error Resume Next
    Debug.Print 1 \ 0
    If Err.Number Then
    IsInIDE = True
    End If
    End If
    '
    InIDE = IsInIDE
    End Function



  3. #3
    Mark Jerde Guest

    Re: DesignMode, UserMode, RunTime?!?! For OCXs

    ... on 2nd thought, I don't know if my answer fits your question ...

    Should have turned off the computer an hour ago when my brain turned to
    mush.

    -- Mark


  4. #4
    Mike Guest

    Re: DesignMode, UserMode, RunTime?!?! For OCXs


    Francois,

    When the control has the designer open there is no UserMode at all, because
    code cannot run at this time.

    When the control is on the form and the form is in design mode then UserMode=False

    When the control is on a form and the form is in run mode then UserMode=True

    So UserMode determines if the control's container is in run or design mode,
    not the control itself.

    Mike


    "Francois Gibeau" <gibeau_f@hotmail.com> wrote:
    >
    >Hi All,
    >
    >I have a total black out and cannot remember how 2 years ago a team I was
    >working with had implemented the solution to the following:
    >
    >In VB when the user control designer is openned and one can place constituent
    >controls in it its called as the 'DesignTime' and can be verify by 'Ambient.UserMode
    >= False'
    >When the designer is closed and an instance of the control class is placed
    >on a form 'Ambient.UserMode = True' which indicates the UserMode (user full
    >for resizing the control conditionally).
    >
    >Now when one hits F5 or runs the application: How do we develop an OCX capable
    >of differenciating between its own UserMode and the RunTime of the application?????
    >
    >All the code below didn't help me remember, anyone knows please???
    >
    > Debug.Print App.PrevInstance
    > Debug.Print UserControl.Ambient.UserMode
    > Debug.Print UserControl.Ambient.UIDead
    >
    > Dim obj As Object
    > Dim obj2 As Object
    > Dim obj3 As Object
    > Dim obj4 As Object
    > Set obj = UserControl.Controls(0)
    > Set obj2 = UserControl.Extender
    > Set obj3 = UserControl.Extender.Container
    > Set obj4 = UserControl.Extender.Container.Parent
    > Debug.Print TypeName(obj), TypeName(obj2), TypeName(obj3), TypeName(obj4)
    > Debug.Print obj.name, obj2.name, obj3.name, obj4.name
    >



  5. #5
    Francois Gibeau Guest

    Re: DesignMode, UserMode, RunTime?!?! For OCXs


    Dear Mark & Mike

    Here is the situtation I found myself last night which I had difficulty with:

    Application (in VB IDE)

    frmEmpsDetails (Form Designer Openned)

    usrDetail1 (User Control: UserMode = False)

    usrWidget2 (User Control Constituent of usrDetail Control: UserMode
    = True)

    The only way I found to avoid usrWidget2 from actually running certain procedures
    was to test the value of UserMode in the UserControl_Show of usrDetail control.

    Any better way of doing this???


  6. #6
    Colin McGuigan Guest

    Re: DesignMode, UserMode, RunTime?!?! For OCXs

    Francois Gibeau wrote in message <39007c5a$1@news.devx.com>...
    >
    >Dear Mark & Mike
    >
    >Here is the situtation I found myself last night which I had difficulty

    with:
    >
    >Application (in VB IDE)
    >
    > frmEmpsDetails (Form Designer Openned)
    >
    > usrDetail1 (User Control: UserMode = False)
    >
    > usrWidget2 (User Control Constituent of usrDetail Control:

    UserMode
    >= True)
    >
    >The only way I found to avoid usrWidget2 from actually running certain

    procedures
    >was to test the value of UserMode in the UserControl_Show of usrDetail

    control.
    >
    >Any better way of doing this???
    >


    If you've got a UserControl inside of a UserControl, the embedded
    UserControl's UserMode's always going to be True.

    If, however, all of your code is within the IDE, you can get around this by
    using a kludge with Debug.Assert; have your code check the following
    function:

    Public Function InIDE() As Boolean
    On Local Error GoTo ErrorBin

    InIDE = False
    Debug.Assert (1 / 0)
    Exit Function
    ErrorBin:
    InIDE = True
    End Function

    Executing the Debug.Assert line will raise an error, thus setting InIDE to
    True...but if the code is actually compiled, then the Debug.Assert line will
    be stripped out, resulting in no error, and InIDE returning False. Note,
    though, that this works only if all of your code is within the IDE.

    --
    Colin McGuigan




  7. #7
    Mike Guest

    Re: DesignMode, UserMode, RunTime?!?! For OCXs


    Francois,

    The usermode property works on the parent of the control. If the parent of
    your control is a control which is on a form, then it will always think it
    is in runmode. You could do a couple of things.

    1) Pass in the value from the top level control.

    2) Check the parent property (Parent.Ambient.UserMode)

    Hope this helps.

    Mike

    "Francois Gibeau" <gibeau_f@hotmail.com> wrote:
    >
    >Dear Mark & Mike
    >
    >Here is the situtation I found myself last night which I had difficulty

    with:
    >
    >Application (in VB IDE)
    >
    > frmEmpsDetails (Form Designer Openned)
    >
    > usrDetail1 (User Control: UserMode = False)
    >
    > usrWidget2 (User Control Constituent of usrDetail Control: UserMode
    >= True)
    >
    >The only way I found to avoid usrWidget2 from actually running certain procedures
    >was to test the value of UserMode in the UserControl_Show of usrDetail control.
    >
    >Any better way of doing this???
    >



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center