MainForm.cs :  » Testing » NUnitForms » NUnit » Extensions » Forms » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Testing » NUnitForms 
NUnitForms » NUnit » Extensions » Forms » MainForm.cs
/*----------------------------------------------------------------------------------------

  A-Soft Ingenieurbro

  Copyright  1994 - 2007. All Rights reserved.

  Related Copyrights :

      Microsoft .NET Windows Forms V2.0 library.
      Copyright (C) 2004...2006 Microsoft Corporation,
      All rights reserved.


  FILE    :  MainForm.cs

  PROJECT    :  A-Soft Library
  SUB      :  Standard Library
 
  SYSTEM    :  Windows-XP, (Windows 2000), C# (.NET 2.0, Visual Studio.NET 2005)

  AUTHOR    :  Joachim Holzhauer
  
  DESCRIPTION  :  Main form of screen capture application
 
  VERSION    :  1.0 - 2006.01.31

----------------------------------------------------------------------------------------*/

using System;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Windows.Forms;

namespace NUnit.Extensions.Forms{
    /// <summary>
    /// Main form of screen capture application
    /// </summary>
    public partial class MainForm : Form
    {
        /// <summary>
        /// The class instance used to capture the screen
        /// </summary>
        private ScreenCapture capture;

        /// <summary>
        /// Helper to handle the file formats
        /// </summary>
        private ImageFormatHandler handlers;

        /// <summary>
        /// The path of the executable, used to save the captured images.
        /// </summary>
        private string pathName;

        /// <summary>
        /// Do it....
        /// </summary>
        public MainForm()
        {
            InitializeComponent();
            pathName = String.Format("{0}\\Data\\", Path.GetDirectoryName(Application.ExecutablePath));
            if (! Directory.Exists(pathName))
            {
                Directory.CreateDirectory(pathName);
            }

            handlers = new ImageFormatHandler();
            capture = new ScreenCapture(handlers);
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            Process[] processes = Process.GetProcesses();

            foreach (Process process in processes)
            {
                if (!String.IsNullOrEmpty(process.ProcessName) && process.MainWindowHandle != null)
                {
                    listBoxProcesses.Items.Add(process.ProcessName);
                }
            }
        }

        private void buttonPrimaryScreen_Click(object sender, EventArgs e)
        {
            string filename = String.Format("{0}Captured PrimaryScreen.png", pathName);
            capture.Capture(ScreenCapture.CaptureType.PrimaryScreen, filename,
                            ImageFormatHandler.ImageFormatTypes.imgPNG);
        }

        private void buttonWorkingArea_Click(object sender, EventArgs e)
        {
            string filename = String.Format("{0}Captured WorkingArea.png", pathName);
            capture.Capture(ScreenCapture.CaptureType.WorkingArea, filename, ImageFormatHandler.ImageFormatTypes.imgPNG);
        }

        private void buttonVirtualScreen_Click(object sender, EventArgs e)
        {
            string filename = String.Format("{0}Captured VirtualScreen.png", pathName);
            capture.Capture(ScreenCapture.CaptureType.VirtualScreen, filename,
                            ImageFormatHandler.ImageFormatTypes.imgPNG);
        }

        private void buttonAllScreens_Click(object sender, EventArgs e)
        {
            string filename = String.Format("{0}Captured All.png", pathName);
            capture.Capture(ScreenCapture.CaptureType.AllScreens, filename, ImageFormatHandler.ImageFormatTypes.imgPNG);
        }

        private void buttonAllFormats_Click(object sender, EventArgs e)
        {
            string filename = String.Format("{0}Capture Formats.png", pathName);
            capture.Capture(ScreenCapture.CaptureType.VirtualScreen, filename,
                            ImageFormatHandler.ImageFormatTypes.imgPNG);
            capture.Capture(ScreenCapture.CaptureType.VirtualScreen, filename,
                            ImageFormatHandler.ImageFormatTypes.imgBMP);
            capture.Capture(ScreenCapture.CaptureType.VirtualScreen, filename,
                            ImageFormatHandler.ImageFormatTypes.imgGIF);
            capture.Capture(ScreenCapture.CaptureType.VirtualScreen, filename,
                            ImageFormatHandler.ImageFormatTypes.imgJPEG);
            capture.Capture(ScreenCapture.CaptureType.VirtualScreen, filename,
                            ImageFormatHandler.ImageFormatTypes.imgTIFF);
        }

        private void buttonPrintScreen_Click(object sender, EventArgs e)
        {
            capture.Print();
        }

        private void buttonProcess_Click(object sender, EventArgs e)
        {
            try
            {
                Process[] processes = Process.GetProcessesByName(listBoxProcesses.SelectedItem.ToString());

                string filename = String.Format("{0}Captured Other Process.png", pathName);
                Bitmap bitmap =
                    capture.Capture(processes[0].MainWindowHandle, filename, ImageFormatHandler.ImageFormatTypes.imgPNG);
                pictureBox1.SizeMode = PictureBoxSizeMode.AutoSize;
                pictureBox1.Image = bitmap;
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.