How to Pop Up a Windows.Forms.Form

A forum devoted to the discussion of all topics having to do with scripting and other advanced programming using iX Developer.
Post Reply
Jwphilippi
Posts: 13
Joined: Mon Mar 11, 2013 8:48 am

How to Pop Up a Windows.Forms.Form

Post 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?
Attachments
CodeSnippet.jpg
CodeSnippet.jpg (65.36 KiB) Viewed 9243 times

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

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

Post 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();
		}
		
    }
}
Best Regards,
Mark Monroe

Beijer Electronics, Inc. | Applications Engineer

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

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

Post by Jwphilippi »

Thanks Mark. You are the man!

Post Reply