how to reference the form?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • rua17

    #1

    how to reference the form?

    I'm creating a special button control that creates a log in the database
    every time is touched.

    I need to log whe name of the button and the name of the form that contains
    it

    In some cases the button could be contained by the form, in some cases it
    could be contained by a pageframe that is contained by the form...

    How can I reference the form name for this case??? is there any property
    that has the container of the button?

    thanks


  • Matt Burland

    #2
    Re: how to reference the form?

    Yes, each control has a property called Container that returns the container
    (e.g. form, another control...) of that control. You can traverse up the
    list of Containers (i.e. find the container of your button, then find the
    container of that container and so on until you get null) until you find the
    parent of all the controls which should be a form in a simple windows forms
    app.

    "rua17" <rua17@hotmail. com> wrote in message
    news:%2309O1hTr DHA.3844@tk2msf tngp13.phx.gbl. ..[color=blue]
    > I'm creating a special button control that creates a log in the database
    > every time is touched.
    >
    > I need to log whe name of the button and the name of the form that[/color]
    contains[color=blue]
    > it
    >
    > In some cases the button could be contained by the form, in some cases it
    > could be contained by a pageframe that is contained by the form...
    >
    > How can I reference the form name for this case??? is there any property
    > that has the container of the button?
    >
    > thanks
    >
    >[/color]


    Comment

    • Matt Burland

      #3
      Re: how to reference the form?

      Actually, there is also a Parent property you can use. I'm not sure exactly
      what the difference is though...

      "rua17" <rua17@hotmail. com> wrote in message
      news:%2309O1hTr DHA.3844@tk2msf tngp13.phx.gbl. ..[color=blue]
      > I'm creating a special button control that creates a log in the database
      > every time is touched.
      >
      > I need to log whe name of the button and the name of the form that[/color]
      contains[color=blue]
      > it
      >
      > In some cases the button could be contained by the form, in some cases it
      > could be contained by a pageframe that is contained by the form...
      >
      > How can I reference the form name for this case??? is there any property
      > that has the container of the button?
      >
      > thanks
      >
      >[/color]


      Comment

      • Matt Burland

        #4
        Re: how to reference the form?

        Actually, that was wrong, my fault. Use the parent property instead.

        "Matt Burland" <anonymous@disc ussions.microso ft.com> wrote in message
        news:uJtQfoTrDH A.2676@TK2MSFTN GP11.phx.gbl...[color=blue]
        > Yes, each control has a property called Container that returns the[/color]
        container[color=blue]
        > (e.g. form, another control...) of that control. You can traverse up the
        > list of Containers (i.e. find the container of your button, then find the
        > container of that container and so on until you get null) until you find[/color]
        the[color=blue]
        > parent of all the controls which should be a form in a simple windows[/color]
        forms[color=blue]
        > app.
        >
        > "rua17" <rua17@hotmail. com> wrote in message
        > news:%2309O1hTr DHA.3844@tk2msf tngp13.phx.gbl. ..[color=green]
        > > I'm creating a special button control that creates a log in the database
        > > every time is touched.
        > >
        > > I need to log whe name of the button and the name of the form that[/color]
        > contains[color=green]
        > > it
        > >
        > > In some cases the button could be contained by the form, in some cases[/color][/color]
        it[color=blue][color=green]
        > > could be contained by a pageframe that is contained by the form...
        > >
        > > How can I reference the form name for this case??? is there any property
        > > that has the container of the button?
        > >
        > > thanks
        > >
        > >[/color]
        >
        >[/color]


        Comment

        • Darrin J Olson

          #5
          Re: how to reference the form?

          I had the same suggestion as Matt. You could make a short recursive method
          to look for the parent of the current control until you find a control of
          the type you are looking for.

          -Darrin


          "rua17" <rua17@hotmail. com> wrote in message
          news:%2309O1hTr DHA.3844@tk2msf tngp13.phx.gbl. ..[color=blue]
          > I'm creating a special button control that creates a log in the database
          > every time is touched.
          >
          > I need to log whe name of the button and the name of the form that[/color]
          contains[color=blue]
          > it
          >
          > In some cases the button could be contained by the form, in some cases it
          > could be contained by a pageframe that is contained by the form...
          >
          > How can I reference the form name for this case??? is there any property
          > that has the container of the button?
          >
          > thanks
          >
          >[/color]


          Comment

          • Rakesh Namineni[MSFT]

            #6
            RE: how to reference the form?

            Button.Parent - Gives you the container control and Forms is a container
            control. Hope that helps.
            --------------------[color=blue]
            >From: "rua17" <rua17@hotmail. com>
            >Subject: how to reference the form?
            >Date: Mon, 17 Nov 2003 12:27:04 -0600
            >Lines: 15
            >X-Priority: 3
            >X-MSMail-Priority: Normal
            >X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
            >X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
            >Message-ID: <#09O1hTrDHA.38 44@tk2msftngp13 .phx.gbl>
            >Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
            >NNTP-Posting-Host: ip251-10.ct.co.cr 196.40.10.251
            >Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!tk2 msftngp13.phx.g bl
            >Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.csharp:1999 14
            >X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp
            >
            >I'm creating a special button control that creates a log in the database
            >every time is touched.
            >
            >I need to log whe name of the button and the name of the form that contains
            >it
            >
            >In some cases the button could be contained by the form, in some cases it
            >could be contained by a pageframe that is contained by the form...
            >
            >How can I reference the form name for this case??? is there any property
            >that has the container of the button?
            >
            >thanks
            >
            >
            >[/color]


            Rakesh, EFT.

            This posting is provided "AS IS" with no warranties, and confers no rights.
            Use of included script samples are subject to the terms specified at
            http://www.microsoft.com/info/cpyright.htm

            Comment

            Working...