We help IT Professionals succeed at work.

call event code in a diffrent dll

Tech_Men
Tech_Men asked
on
Medium Priority
324 Views
Last Modified: 2013-12-16
hi there ,
i have this event
  private void txtTz_Leave(object sender, EventArgs e)
        {
            if (Tz != txtTz.Text.Trim().TrimEnd())
            {
                Tz = txtTz.Text.Trim().TrimEnd();
                bool flag = fa.ChekEmpExs(Tz);
                if (flag == true)
                {
                    MessageBox.Show("¿¿ ¿¿¿¿ ¿¿¿¿ ¿¿¿¿¿¿", "¿¿¿¿¿ ¿¿¿¿¿");
                    txtTz.Clear();
                    txtTz.Focus();
                }
               
            }
        }
can i declare this event in another dll and get also the object propries in the distrbute dll
i just want to manage the code out from the win form
what its the best wasy to manage code by layers ?
Comment
Watch Question

Commented:
Hi, the code you've posted is not the event, but the function that is being called when the event is fired.

The function is being "attached" to the event by:

txtTz.Leave += new ...


Your function is not "Generic" since the code inside the function knows about a control called txtTz, and Tz (which is assume is a string).

You can access txtTz and Tz because you are writing in the Code-Behind of the form.


You can pass the textbox txtTz to the Dll, but that would be a bad coding.

You should better have the code in a way that every time the text changes, it changes a text property in your DLL, and then call a public function in your DLL when the textbox is being Left.


Please read more about MVP and 3 tiers model.



I can also suggest you to write in WPF since "Binding" is the new way of connecting Business logic to the View.
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2015

Commented:
Just to be clear, what you have posted is an event handler, not an event. The handler is the code that gets executed when some event occurs. A handler is just a function like any other.

Events are designed to be raised by the object which owns the event. Think about it like this:  unless you are an invalid, does someone else lift your arms for you? Does someone else turn 30 for you? etc.

An event should be raised by the object itself. Can you expand on what the ultimate goal is?

Commented:
As I understand, he wants the txtTz_Leave "sit" on another DLL other than his form, and he expects to access txtTz.Text from another DLL, which is obviously not a good idea.
Although he can actually get the mentioned TextBox from casting the sender into a TextBox, it is not recommended.
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2015

Commented:
As I understand, he wants the txtTz_Leave "sit" on another DLL other than his form, and he expects to access txtTz.Text from another DLL, which is obviously not a good idea.
Although he can actually get the mentioned TextBox from casting the sender into a TextBox, it is not recommended.
If that is the case, then there's not really any difference in assigning the handler to be a function in the DLL rather than a function on the forms, aside from location of the function. He would be coupling his DLL to the System.Windows.Forms library at that point, but the DLL itself would still be decoupled from the form due to your casting of sender, as you mentioned.
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.