Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Why is this happening??
Message
De
29/01/2009 15:44:22
Timothy Bryan
Sharpline Consultants
Conroe, Texas, États-Unis
 
 
À
29/01/2009 14:39:41
Information générale
Forum:
ASP.NET
Catégorie:
Formulaires
Divers
Thread ID:
01378204
Message ID:
01378265
Vues:
11
>Sorry if I didn't do a good job of explaining. The control is defined separately in a Libarary. Then I've dropped the control onto a Panel, which is on the Form mainwin ...hopefully that will make my problem more clear.
>

I think I did understand that. If it was me, I still would define an event in the control and raise it when I want the form to respond. That way the control never needs to know anything about the form and the control can be placed on other forms easily. The form needs to subscribe to the event of the control. This is the same thing if you put a button on the form and the form subscribes to it's click event. Then the code you want to run on the form runs when the event is raised. I do this all the time with events and it really is easy. If I am not understaning still, I appologize.
Tim

>>Bob,
>>
>>>I have some code in a custom contol that is trying to run code in the form that the control is placed on. I want the code to be written in the control so I don't have to duplicate it for each contol I place on the form (I hear that's good programming practice :).
>>>
>>>Here's the code:
>>>
>>>MainWin1 = (MainWindow)this.TopLevelControl;
>>>MainWin1.MainMenu(MainWindow.MenuName.search);
>>>
>>>The code works great the first time the contol is clicked, but the second time its clicked it gives a NULL exception as the this.TopLevelControl is null for some reason.
>>>
>>>So I traced it and for some reason the second time through it ran the click event twice (that executes the above code) so I thought if I just ignored the time that this.TopLevelControl was null I'd be OK. But then I get a NULL exception for the mainwin variable at the very top of my program that invokes the main window in the first place:
>>>
>>>MainWindow mainwin = new MainWindow();
>>>Application.Run(mainwin); - This turns NULL for some reason.
>>>
>>>Any Ideas anyone? I don't have a clue why this would be happening. The main form hasn't been closed in the interim between the two clicks. OR Am I approaching this wrong and should I try a different approach to executing code in the mainform from a custom control?
>>>
>>>Thanks!!
>>>
>>>bob
>>
>>Just to make sure I understand this right. You have a control that you have placed on a form. You have code in the control that based on some action in the control needs to run some code within the form. If so, the idea with controls being self contained is they should not really know anything about the form using them. Another way you could do this is to define an event in the control and raise that event based on some action. The form can subscribe to that event and when it is raised it would respond by running that code.
>>Tim
Timothy Bryan
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform