How to invoke C#winform using LabVIEW

Source: Internet
Author: User

Interface interaction is not the strong point of LabVIEW, when creating a UI using LabVIEW is always constrained by VI's limited controls, limited skins, and limited control events. When you need to implement a multi-document window of the UI, the window's floating docking, animation and other functions need to take a lot of effort. It is therefore possible to implement interface representations and interactions in other languages, supplemented by LabVIEW invocation. At the same time, in text programming (for example, C #), the IDE assists in the automatic generation of code through interactive configuration, and the development of interface programs is more efficient.

C # as an object-oriented language, the window code is encapsulated in the System.Windows.Forms.Form class. LabVIEW makes custom Form1 instance constructs by providing support for invoking. NET nodes, and uses the show () or ShowDialog () function to run and display a custom window. The way the window is called is divided into modal and non-modal, and you can specify the relationship between the owner form and the subordinate form. This is reflected in the following four form classes that provide functions:

 Public void Show ();                         Non-modal invocation, does not specify the relationship of the owner form and the subordinate form publicvoid  Show (iwin32window owner);       Non-modal invocation, specifying the relationship of the owner form and the subordinate form
Public void ShowDialog (); Schema invocation, implicitly specifying the relationship of the owner form and the subordinate form
Public void ShowDialog (IWin32Window owner); Schema invocation, explicitly specifying the relationship between the owner form and the subordinate form

Developers develop good WinForm code in C # and publish it as a DLL for. Net. The vi can then be called by invoking the. NET function node provided by LabVIEW, and be aware of the call:

1. Calling WinForm through the Show,showdialog method calls in a single thread, set the VI execution system in the property setting of the call VI to user Interface.

2. If you need to display the relationship that establishes the owner form and the attached form, you need to use the overloaded function with the IWin32Window owner as the entry parameter. IWin32Window is an interface type, which essentially implements a function to acquire Win32 HWND Handleds.

namespacesystem.windows.forms{//Summary://provides an interface to expose Win32 HWND handles.[ComVisible (true)] [Guid ("458ab8a2-a1ea-4d7b-8ebe-dee5d3d9442c")] [InterfaceType (Cominterfacetype.interfaceisiunknown)] Public InterfaceIWin32Window {//Summary://Gets the handle to the window represented by the implementer. //        //Returns://A handle to the window represented by the implementer.IntPtr Handle {Get; } }}

We can implement the interface by getting the HWND of the caller's vi form and then customizing an adapter class. First, the get HWND is passed into the class for construction, and then the show (IWin32Window owner) method is called:

 Public class Labviewwin32windowsadapter:iwin32window    {        public labviewwin32windowsadapter (int.  handle)        {            this.  Handle = (INTPTR) handle;        }        INTPTR handle;          Public IntPtr Handle        {            getreturn  handle;}        }    }

code example: Http://pan.baidu.com/s/1geIt0tH

Reference: https://lavag.org/topic/11857-launch-a-floating-windows-form/#comment -71599

How to invoke C#winform using LabVIEW

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.