NekoManu Posted August 21, 2004 Posted August 21, 2004 I created a form MNLForm based on Form. On my form I have a property DBStatus. I also created a textbox MNLTextBox based on TextBox. Now when the text of my TextBox changes, I want to change the DBStatus of the form that my textbox is on. The question is how? I tried with Form.ActiveForm.DBStatus, but that does not exists. The same with MNLForm.ActiveForm.DBStatus Anyone please? Quote
jdemackio Posted August 21, 2004 Posted August 21, 2004 Assuming that DBStatus is a property in the same form that your MNLTextBox is on. Private Sub MNLTextBox_TextChanged(ByVal sender As Object, _ ByVal e As System.EventArgs) Handles MNLTextBox.TextChanged If (MNLTextBox.Text = ??whatever??) Then DBStatus = ??whatever?? End Sub Quote - The only true knowledge is knowing that you know nothing.
Engine252 Posted August 21, 2004 Posted August 21, 2004 did you test the code you just said or assumed it wasn't there becauls the intellisense said it wassn't try ((MNLForm)MNLForm.ActiveForm).DBStatus Quote
NekoManu Posted August 22, 2004 Author Posted August 22, 2004 I couldn't try that code becuase I got errors and couldn't build the solution. I'll try your solution and let you know. Quote
NekoManu Posted August 22, 2004 Author Posted August 22, 2004 It works! Thanks. But this leads to another problem: I have this virtual VerfiyTextBox method on my textbox control. I was going to override it in my form. Again the question is how? And talking about verify: how do I test if a control has a certain method. What I want to do is, in the form I want to go over all the controls and check if they have a VerifyMethod. In case they have one, I want to execute that method. I have a method that goes over all the controls in a form, but I don't know how to test if the control has a verify-method. Quote
Administrators PlausiblyDamp Posted August 22, 2004 Administrators Posted August 22, 2004 Easiest way is to create an interface that exposes the relevant method and implement that interface in the controls - then you can always do something like 'declare and implement the interface Public Interface ITest 'give a better name Sub RequiredFunction() End Interface Public Class MyControl Inherits TextBox Implements ITest Public Sub RequiredFunction() Implements ITest.RequiredFunction End Sub End Class 'elsewhere you could then do For Each ctl As Control In Me.Controls If TypeOf ctl Is ITest Then Dim ctltest As ITest = DirectCast(ctl, ITest) ctltest.RequiredFunction() End If Next End Sub Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
NekoManu Posted August 22, 2004 Author Posted August 22, 2004 Can you explain this a bit more please? If possible in C#. Thanks Quote
Administrators PlausiblyDamp Posted August 22, 2004 Administrators Posted August 22, 2004 In C# you would declare the interface and class like below public interface ITest //give a better name { void VerifyMethod(); } public class MyControl : System.Windows.Forms.TextBox, ITest { public void VerifyMethod() { // Write the code for the VerifyMethod here } } By implementing the interface you are forced to provide the VerifyMethod and as a consequence anything that implements this interface must have the VerifyMethod. In your form you can loop over all the controls and check which do implement this interface - and if they do call the method like so foreach (Control c in this.Controls) { ITest t = c as ITest; if (t != null) { t.VerifyMethod(); } } Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.