Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. How to Invoke Function from Form through Controls event?

How to Invoke Function from Form through Controls event?

Scheduled Pinned Locked Moved C#
questioncollaborationtutorial
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    manju 3
    wrote on last edited by
    #1

    Hi Team, How can i call function from Forms through any of the controls? Suppose i have function Validate() in FrmTest.cs under Global\Forms\ FrmTest.cs private void Validate() { } And control TestControl.cs under Global\Control\ TestControl.cs For any drop down event changed,i need to invoke the function Validate() from FrmTest.cs. Any suggestions will be great helpful Thanks in advance Manju

    L D 3 Replies Last reply
    0
    • M manju 3

      Hi Team, How can i call function from Forms through any of the controls? Suppose i have function Validate() in FrmTest.cs under Global\Forms\ FrmTest.cs private void Validate() { } And control TestControl.cs under Global\Control\ TestControl.cs For any drop down event changed,i need to invoke the function Validate() from FrmTest.cs. Any suggestions will be great helpful Thanks in advance Manju

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      You need a reference to the class that contains the Validate method. But without some more details of your application it is difficult to be more specific.

      1 Reply Last reply
      0
      • M manju 3

        Hi Team, How can i call function from Forms through any of the controls? Suppose i have function Validate() in FrmTest.cs under Global\Forms\ FrmTest.cs private void Validate() { } And control TestControl.cs under Global\Control\ TestControl.cs For any drop down event changed,i need to invoke the function Validate() from FrmTest.cs. Any suggestions will be great helpful Thanks in advance Manju

        D Offline
        D Offline
        Dave Kreskowiak
        wrote on last edited by
        #3

        You're doing this backwards. The control shouldn't know anything about the form it's on. It might not even be in the Controls collection of a Form. It may be a few levels deep in other control containers. The control should validate it's own content, not the form.

        A guide to posting questions on CodeProject

        Click this: Asking questions is a skill. Seriously, do it.
        Dave Kreskowiak

        1 Reply Last reply
        0
        • M manju 3

          Hi Team, How can i call function from Forms through any of the controls? Suppose i have function Validate() in FrmTest.cs under Global\Forms\ FrmTest.cs private void Validate() { } And control TestControl.cs under Global\Control\ TestControl.cs For any drop down event changed,i need to invoke the function Validate() from FrmTest.cs. Any suggestions will be great helpful Thanks in advance Manju

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Add a (public) "delegate" or Func instance to your target control that is automatically called by the event in question; the "default" response / behaviour of the delegate can be whatever you want (like a NotImplementedException). Otherwise, you pass in a reference to "Validate()" and initialize the delegate with that reference when the target control(s) are created. That's a generic way for attaching extra / new behavior to an object. Depending on the development context (Windows Forms; WPF; MVVM; blah, blah), you would probably adopt some other technique (like "command binding"!).

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups