All pastes #386057 Raw Edit

Stuff

public text v1 · immutable
·published 2007-03-08 09:50 UTC
rendered paste body
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Threading;
using System.Runtime.InteropServices;
using System.Security;

namespace testnew2
{
	public partial class Form1 : Form
	{
		
		//initierar formen//////////////////////
		public Form1()
		{
			InitializeComponent();
			string tempFileName = @"C:\Documents and Settings\Markus\Mina dokument\EXJOBBET\RASCAL\Vc\bin\imgtest.txt";
			MakeShort fileToShorten = new MakeShort();
			fileToShorten.start( tempFileName );

			Process proc = new Process();
			//c:\Documents and Settings\Markus\Mina dokument\EXJOBBET\RASCAL\Vc\bin\combine.exe
			proc.StartInfo.FileName = @"c:\windows\system32\cmd.exe";

			//proc.StartInfo.FileName = @"c:\Documents and Settings\Markus\Mina dokument\EXJOBBET\RASCAL\Vc\bin\rrcombine.exe";
			proc.StartInfo.Arguments = "/C dir";
			proc.StartInfo.CreateNoWindow = true;
			proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
			proc.StartInfo.RedirectStandardOutput = true;
			proc.StartInfo.UseShellExecute = false;


			proc.Start();
			Debug.WriteLine( "PROCESS OUTPUT:" );
			Debug.WriteLine( "---------------------" );
			Debug.WriteLine( proc.StandardOutput.ReadToEnd() );
			Debug.WriteLine( "---------------------" );
			proc.Close();

		}
		///
		//////////////////////////////vad händer då jag trycker på open/////////////////////////////
		
			private void openToolStripMenuItem_Click_1( object sender, EventArgs e )
			{
			OpenFileDialog dialog = new OpenFileDialog();
			//string[] fileNames = dialog.FileNames;
			dialog.Filter =
			"Images (*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|" +
			"All files (*.*)|*.*";

			// Allow the user to select multiple images.
			dialog.Multiselect = true;
			dialog.Title = "My Image Browser";

			DialogResult dr = dialog.ShowDialog();
			if ( dr == System.Windows.Forms.DialogResult.OK )
			{
				// Read the files

				for ( int i = 0; i < dialog.FileNames.Length; i++ )
				{
					string file = dialog.FileNames[ i ];

					//foreach ( String file in dialog.FileNames ){
					
					// Create a PictureBox.
					try
					{
						PictureBox pb = new PictureBox();
						Image loadedImage = Image.FromFile( file );
						pb.Height = 200;
						pb.Width = 200;
						//pb.Height = loadedImage.Height;
						//pb.Width = loadedImage.Width;
						pb.Image = loadedImage;
						flowLayoutPanel1.Controls.Add( pb );
					}
					catch ( SecurityException ex )
					{
						// The user lacks appropriate permissions to read files, discover paths, etc.
						MessageBox.Show( "Security error. Please contact your administrator for details.\n\n" +
							"Error message: " + ex.Message + "\n\n" +
							"Details (send to Support):\n\n" + ex.StackTrace
						);
					}
					catch ( Exception ex )
					{
						// Could not load the image - probably related to Windows file system permissions.
						MessageBox.Show( "Cannot display the image: " + file.Substring( file.LastIndexOf( '\\' ) )
							+ ". You may not have permission to read the file, or " +
							"it may be corrupt.\n\nReported error: " + ex.Message );
					}
				}
				Console.WriteLine( "här är filnamnen {0}",dialog.FileNames[2] );
			}
		}

	

		

	


	}
	
	public class MakeShort
	{
		[DllImport( "kernel32.dll", CharSet = CharSet.Auto )]
		public static extern int GetShortPathName(
			[MarshalAs( UnmanagedType.LPTStr )]
        string path,
			[MarshalAs( UnmanagedType.LPTStr )]
        StringBuilder shortPath,
			int shortPathLength
			);
		
		public void start(string filename)
		{
			StringBuilder shortPath = new StringBuilder( 255 );
			GetShortPathName( filename, shortPath, shortPath.Capacity );
			Console.Write( "hejsan" );
			Console.WriteLine( shortPath.ToString() );
		}
	}
	
	
}