Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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?

Posted

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

- The only true knowledge is knowing that you know nothing.
Posted

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.

  • Administrators
Posted

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

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

  • Administrators
Posted

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();
}
}

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...