Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Export method and create interrupts from a .NET Component 2

Status
Not open for further replies.

arnoldw

Programmer
Sep 25, 2007
17
DK
I have created a custom made .NET Component (in Visual Studio .NET 2003) that contains a regular button and a checkbox. I build a .dll file and then use the .NET Component in a LabVIEW application. In LabVIEW I can get a long list of methods that the .NET Component supports (BeginInvoke(Delegate methid), BeginInvoke(Delegate method, Objects[] args), BringToFront(), Contains(Control ctl), and many more). I would like to add my own method that appears in this list of exported methods. How do I do that? Also, let's say the user pushes the button, what do I add to my C#-code to make this button press generate an interrupt in the LabVIEW application the .NET Component resides in? I have never before programmed in C# and this is my first .NET Component so please have that in mind when replying. If anybody can provide snippets of sample code, I'd be most grateful.
 
By interupt do you mean Event?

basically you should be able to add your own methods, properties and events to your component.

An example property would be
public bool CheckedValue
{
get
{
return checkBox1.Checked;
}
set
{
checkBox1.Checked = value;
}
}


as for an event, you could create one like this:

public event EventHandler ButtonClicked;

and then call it when your button is pressed.

private void button1_Click(object sender, EventArgs e)
{
this.ButtonClicked(this, EventArgs.Empty);
}


Try adding parts of this to your component and see what comes available to you.

 
Thanks! I can't believe it was that simple to export a method. I found out that the events works like this:

using System;

namespace EventExample
{
public delegate void EventHappenedDelegate(Double dValue);

public class MyClass
{
public event EventHappenedDelegate EventHappened;

private void button1_Click(object sender, System.EventArgs e)
{
EventHappened(10); // Generate the event
}

}
}
 
i minor change i would recommend:
Code:
namespace EventExample
{
   public delegate void EventHappenedDelegate(Double dValue);
 
   public class MyClass
   {
      public event EventHappenedDelegate EventHappened;

      private void button1_Click(object sender, System.EventArgs e)
      {
         if(EventHappened != null) 
         {
            EventHappened(10);
         }
      }
 
   }
}
this way an exception is not thrown if the delegate is not defined.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top