LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

system.drawing.graphics

Solved!
Go to solution
Dear
I want to use System.drawing.graphics class in LV
In attached file, Image class can call property, method without constructor.
But, when Graphics could not call property, method without constructor,
it is happen error as attached file.
and Graphics do not create class in constructor.
 
How can I ?
Bongchan Park
 
 
0 Kudos
Message 1 of 8
(5,715 Views)

Hi Bongchan,


Please refer to the attached images.  You have to use the .NET functions almost like you would in Visual Basic/C#.  Thus, the program is structured like so:


1. Create an instance of the System.Windows.Forms.Form class
2. Register the event Form_Paint that will invoke the callback VI
3. Create a graphics object from the PaintEventArgs passed into the callback VI
4. Create an image object that loads the picture file
5. Call the graphic object's method DrawImage using the image object
 
Here is the corresponding C# code:

 

name GDI_Test

{

   // Create an instance of the System.Windows.Forms.Form class

   public partial class Form1 : Form

   {

      public Form1()

      {

         InitializeComponent();

      }

     

      // Register the event Form_Paint that will invoke the callback [Function]

      private void Form1_Paint(object sender, PaintEventArgs e)

      {

         // Create a graphics object from the PaintEventArgs passed into the callback VI 

         Graphics g = e.Graphics;

 

         // Create an image object that loads the picture file

         Image test = Image.FromFile("C:\\test.png" );

 

        // Call the graphic object's method DrawImage using the image object

        g.DrawImage(test, 0, 0);

      }

   }

}

 

Steps 1 - 2:

 

Automatically create the callback VI by right-clicking on the VI Ref and selecting "Create Callback VI":

 

 

 

Steps 3 - 5:

 

 

Message Edited by Pakman on 08-18-2008 09:48 AM
Download All
Message 2 of 8
(5,639 Views)
Solution
Accepted by topic author bc7041
Just out of curiosity, what do you need to do with that class in terms of drawing? The LabVIEW <--> .NET interface is not known for its speed, so you may wish to consider using the native drawing tools in LabVIEW.
Message 3 of 8
(5,633 Views)

How do I do step 1 - 2?

 

VI, Block Diagram, Functions, Connectivity, .NET, Register Event Callback placed. Members are Event, VI Ref, and User Parameter. Selecting Event says "No Events". If I open a LabVIEW example (e.g. NET Event Callback for Calendar Control.vi) I am able to disconnect all wires from it. select Event, and get a list from which I can pick Paint. Then I can drag it to my VI.

 

Similarly, I select VI Ref and and Create Callback VI is grey (disabled).

0 Kudos
Message 4 of 8
(5,269 Views)

After creating the VIs as shown the caller runs but the image is not displayed. A break point in the callback is not triggered. What is the LabVIEW code that corresponds to the following C# code?

 

// Create an image object...

Image test = ...

0 Kudos
Message 5 of 8
(5,254 Views)
Nevermind about Image. I had a wire mismatch. The callback still doesn't break point but I don't care because the graphic appears on the Form. I still wonder how to start from a new Reg Event Callback though, instead of modifying one from an example.
0 Kudos
Message 6 of 8
(5,236 Views)

To start from a new Reg Event Callback, you connect the reference from the Form .NET constructor into the Event terminal of the Reg Event Callback.

 

Regards,

 

Peter K. 

Message 7 of 8
(5,233 Views)

I couldn't find the Reg Event Callback for a while either, but turns out it's just built in to LabView.  It is located in the .NET Palette, or you can just Ctrl+Space and search "Register Event Callback"

0 Kudos
Message 8 of 8
(3,881 Views)