Welcome Guest ( Login | Register )



All times are UTC - 7 hours [ DST ]



Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: How to Pop Up a Windows.Forms.Form
PostPosted: Thu Mar 28, 2013 4:05 pm 

Joined: Mon Mar 11, 2013 8:48 am
Posts: 13

Offline
Alrighty. I am trying to get a Windows Form to pop up in front of the MainScreen to display an image.

Unfortunately, I can't get either:

a) the form to be brought to the front
or
b) the main screen to be brought to the back

So the form ends up behind the mainscreen with the focus on it. Thus essentially locking up the HMI.

Any ideas out there?


Attachments:
CodeSnippet.jpg
CodeSnippet.jpg [ 65.36 KiB | Viewed 2563 times ]
 Profile  
 
 Post subject: Re: How to Pop Up a Windows.Forms.Form
PostPosted: Fri Mar 29, 2013 8:16 am 

Joined: Tue Mar 13, 2012 9:53 am
Posts: 824

Offline
Can you not use a iX Developer popup screen and put the picture box on that screen rather than rolling your own form? It will do the same thing. The below code creates a picturebox on a iX Developer screen.

Code:
namespace Neo.ApplicationFramework.Generated
{
    using System.Windows.Forms;
    using System;
    using System.Drawing;
    using Neo.ApplicationFramework.Tools;
    using Neo.ApplicationFramework.Common.Graphics.Logic;
    using Neo.ApplicationFramework.Controls;
    using Neo.ApplicationFramework.Interfaces;
   
   using System.Diagnostics;
   
    public partial class Screen1
    {
      

      
      void Button1_Click(System.Object sender, System.EventArgs e)
      {
         //Create a Barcode2D object
         Neodynamic.CF.Barcode2D.Barcode2D bc = new Neodynamic.CF.Barcode2D.Barcode2D();
         //Set barcode symbology
         bc.Symbology = Neodynamic.CF.Barcode2D.Symbology2D.QRCode;

         //Set value to encode
         bc.Code = Globals.Tags.ToEncode.Value;
         
         //Set dimensions
         bc.DataMatrixModuleSize = 0.04f;
         //...
         //Generate and save the barcode image
         bc.Save(@"\FlashDrive\Project\DataMatrixTest_" + Globals.Tags.Count.Value.ToString() + ".bmp", System.Drawing.Imaging.ImageFormat.Bmp);
         
         ShowMyImage(@"\FlashDrive\Project\DataMatrixTest_" + Globals.Tags.Count.Value.ToString() + ".bmp", 140,140);
         
         Globals.Tags.Count.Value = Globals.Tags.Count.Value + 1;

      }
      
      void Button2_Click(System.Object sender, System.EventArgs e)
      {
         ProcessStartInfo startInfo = new ProcessStartInfo("explorer.exe", @"\FlashDrive");

         Process.Start(startInfo);
      }
      
      private Bitmap MyImage;
      private PictureBox PictureBox1;
      
      private void InitializePictureBox()
      {
         PictureBox1 = new PictureBox();

         // Set the location and size of the PictureBox control.
         this.PictureBox1.Location = new System.Drawing.Point(80, 0);
         this.PictureBox1.Size = new System.Drawing.Size(300, 300);
         this.PictureBox1.TabStop = false;

         // Set the SizeMode property to the StretchImage value.  This
         // will shrink or enlarge the image as needed to fit into
         // the PictureBox.
         this.PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;

         // Set the border style to a three-dimensional border.
         //this.PictureBox1.BorderStyle = BorderStyle.Fixed3D;

         // Add the PictureBox to the form.
         this.Controls.Add(this.PictureBox1);

      }

      
      public void ShowMyImage(String fileToDisplay, int xSize, int ySize)
      {
         
         // Sets up an image object to be displayed.
         if (MyImage != null)
         {
            MyImage.Dispose();
         }

         // Stretches the image to fit the pictureBox.
         PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage ;
         MyImage = new Bitmap(fileToDisplay);
         PictureBox1.ClientSize = new Size(xSize, ySize);
         PictureBox1.Image = (Image) MyImage ;
      }
      
      void Screen1_Opened(System.Object sender, System.EventArgs e)
      {
         InitializePictureBox();
      }
      
    }
}

_________________
Best Regards,
Mark Monroe

Beijer Electronics, Inc. | Applications Engineer


 Profile  
 
 Post subject: Re: How to Pop Up a Windows.Forms.Form
PostPosted: Fri Mar 29, 2013 12:58 pm 

Joined: Mon Mar 11, 2013 8:48 am
Posts: 13

Offline
Thanks Mark. You are the man!


 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 7 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron