Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Interfaces
Message
De
19/01/2010 00:38:34
 
 
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Titre:
Versions des environnements
Environment:
C# 2.0
Divers
Thread ID:
01444635
Message ID:
01444682
Vues:
50
>From what you are telling me it seems that I can't use Interfaces in this particular case (which I kind of suspected). Let me explain. The textbox classes where the event OnTextChanged need to "be aware" of the interface IMyInterface are in a separate project of all base classes used by different projects of the application. So what you are saying is that I need to reference each one of the projects in the class where the text box class reside. And this is "impractical" if not "impossible" since every time I use this base textbox class in a project I will need to reference the new project in the base class library. I hope I am explaining myself clear.

I think you're still misunderstanding some of the concepts, Dmitry. From what you're saying above, it sounds like you think it works exactly opposite of the way it actually works.

Your project where IMyInterface is defined (it's not necessary, nor do I recommend, putting all interfaces in one spot, but I'm just using the namespace for illustration purposes):
namespace AllInterfaces
{
    public interface IMyInterface
    {
        void MyMethod(bool IsOK);
    }
}
Your project where your TextBox (and presumably other controls) is defined, needs to simply have a reference to the AllInterfaces project, along with the using statement:
using AllInterfaces;

namespace MyCompany
{
    public class MyTextBox : System.Windows.Forms.TextBox
    {
        protected override void OnTextChanged(EventArgs e)
        {
            Control o = this.parent;
            if (o != null && (o is IMyInterface))
            {
                ((IMyInterface)o).MyMethod(false);
            }
            base.OnTextChanged(e);
        }
    }
}
I'm not quite sure how you've laid out your projects/namespaces, but this will certainly work.

~~Bonnie
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform