开发者

trigger method in inherited class - windows forms

this is my scenario, and I want to know if it's possible to accomplish what I intend to do:

I have a class library (made in c#) that inside has a class (named SForm) that inherits from System.Windows.Forms.Form. In that class I declare some strings, and methods to set those strings' values.

public class SForm : Form
{
  public string _myDate;
  public void setTime(string val) { _mydate = val; }
}

In another class, I make some calls to an API that trigger callbacks, and when a callback occurs, call the methods to set the values in the class that inherits from Form. All working fine, and all classes are packed in a DLL.

public class Events
{
  private SForm _form;
  public void setForm(SForm f) 
  {
    _form = f;
  }
  public void connect()
  {
    //when I call this method, connects to a device using the API, and if
    //it's succesful, triggers OnCallback...
  }
  private void OnCallback(string retVal)
  {
    _form.setTime(retVal); //this works
  }
}

Here is my problem: I have a desktop app, in VB, that uses that DLL, and when I inherit from SForm, I want that the callback triggered by the DLL invokes the method in my form

Public Class Form1
  Inherits SForm

  Private _se As Events

  Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) _
  Handles Me.Load
    _se = New Events()
    _se.setForm(Me)
    _se.connect()
  End Sub

  Private Overloads Sub setTime(ByVal s As String)
    MessageBox.Show(s)
  End Sub

What I need is t开发者_JAVA技巧hat the callback trigger the "setTime" method in this form, and show the value sent by my DLL (I can push a button and access the value of the _myDate string, but I need it to be automatic). Is that possible? How??

Thanks a million


You need to declare setTime() virtual so you can override it. Don't forget to call the base method.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜