Results 1 to 4 of 4

Thread: Custom Controls: How to tell if it is being placed on the form for the first time?

  1. #1

    Thread Starter
    No place like 127.0.0.1 eyeRmonkey's Avatar
    Join Date
    Jul 2005
    Location
    Blissful Oblivion
    Posts
    2,306

    Custom Controls: How to tell if it is being placed on the form for the first time?

    Which even should I use to see if my control if being placed on a form for the first time? I want to do some error checked and I want to size it properly. UserControl_Initialize is called a few other times as well. Is there a better event to use?
    Visual Studio 2005 Professional Edition (.NET Framework 2.0)
    ~ VB .NET Links: Visual Basic 6 to .NET Function Equivalents (Thread) | Refactor! (White Paper) | Easy Control for Wizard Forms | Making A Proper UI For WinForms | Graphics & GDI+ Tutorial | Websites For Free Icons
    ~ QUOTE: Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -Rich Cook

    ~ eyeRmonkey.com

  2. #2
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    UK
    Posts
    417

    Re: Custom Controls: How to tell if it is being placed on the form for the first time?

    Now sure if this is of any help. will show a messagebox as soon as you add the control to the form.

    Private Sub UserControl_Show()
    On Error Resume Next
    If Not (UserControl.Ambient.UserMode) Then
    MsgBox "design time"
    End If
    End Sub
    When your dreams come true.
    On error resume pulling hair out.

  3. #3
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Custom Controls: How to tell if it is being placed on the form for the first time?

    The InitProperties event only occurs when the usercontrol is first sited on a form. It does not fire at runtime.

    The Initialize event is always the first event to occur when an instance of the control is created, design time and runtime.

  4. #4

    Thread Starter
    No place like 127.0.0.1 eyeRmonkey's Avatar
    Join Date
    Jul 2005
    Location
    Blissful Oblivion
    Posts
    2,306

    Re: Custom Controls: How to tell if it is being placed on the form for the first time?

    But will InitProperties be called every time the project is loaded? I would think so. I guess I should go test it though .

    Thanks guys. I'll see what I can come up with.
    Visual Studio 2005 Professional Edition (.NET Framework 2.0)
    ~ VB .NET Links: Visual Basic 6 to .NET Function Equivalents (Thread) | Refactor! (White Paper) | Easy Control for Wizard Forms | Making A Proper UI For WinForms | Graphics & GDI+ Tutorial | Websites For Free Icons
    ~ QUOTE: Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -Rich Cook

    ~ eyeRmonkey.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width