Page 1 of 1

How to Pop Up a Windows.Forms.Form

Posted: Thu Mar 28, 2013 4:05 pm
by Jwphilippi
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?

Re: How to Pop Up a Windows.Forms.Form

Posted: Fri Mar 29, 2013 8:16 am
by mark.monroe
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: Select all

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();
		}
		
    }
}

Re: How to Pop Up a Windows.Forms.Form

Posted: Fri Mar 29, 2013 12:58 pm
by Jwphilippi
Thanks Mark. You are the man!