H
H. Martins
I need to use command line input to a tinny c# application:
It goes like this:
** program.cs **
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace ClipboardImageSaveToFile
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
public static void Main(string[] args)
<<<<<<<<<<<<<<<< ADED
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new frmDefForm());
}
}
}
** Form1.cs **
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace ClipboardImageSaveToFile
{
public partial class frmDefForm : Form
{
public frmDefForm()
{
InitializeComponent();
}
private void frmDefForm_Activated(object sender, EventArgs e)
{
if (args.Lenght != 2) <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
FIRST ERROR
{
MessageBox.Show("Erro: não forem recebidos 2
argumentos (strFullPathName, strFileType");
}
if (Clipboard.GetDataObject() != null)
{
IDataObject data = Clipboard.GetDataObject();
if (data.GetDataPresent(DataFormats.Bitmap))
{
Image image =
(Image)data.GetData(DataFormats.Bitmap, true);
// image.Save("W:\\users\\hm\\apirac-db\\teste-
b.bmp", System.Drawing.Imaging.ImageFormat.Bmp);
// image.Save("W:\\users\\hm\\apirac-db\\teste-
b.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
// image.Save("W:\\users\\hm\\apirac-db\\teste-
b.png", System.Drawing.Imaging.ImageFormat.Png);
if (args[1] = "jpeg")
{
image.Save(args[0],
System.Drawing.Imaging.ImageFormat.Jpeg);
}
else
{
MessageBox.Show("Formato de ficheiro requerido
não suportado (apenas JPG)");
}
}
else
{
MessageBox.Show("O 'clipboard' não contém uma
imagem");
}
}
else
{
MessageBox.Show("Nada há no 'clipboard'");
}
// fechar aplicação
Close ();
}
private void label1_Click(object sender, EventArgs e)
{
}
}
}
This is an adaptation of something found somewhere. The point is that
I can't figure out how to pass main () arguments to the code in the
second file.
At the moment it says:
The name 'args' does not exist in the current context
I understand the array args[] is unknown in the second file, but I
can't find a way to pass array.
Thanks
H. Martins
It goes like this:
** program.cs **
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace ClipboardImageSaveToFile
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
public static void Main(string[] args)
<<<<<<<<<<<<<<<< ADED
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new frmDefForm());
}
}
}
** Form1.cs **
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace ClipboardImageSaveToFile
{
public partial class frmDefForm : Form
{
public frmDefForm()
{
InitializeComponent();
}
private void frmDefForm_Activated(object sender, EventArgs e)
{
if (args.Lenght != 2) <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
FIRST ERROR
{
MessageBox.Show("Erro: não forem recebidos 2
argumentos (strFullPathName, strFileType");
}
if (Clipboard.GetDataObject() != null)
{
IDataObject data = Clipboard.GetDataObject();
if (data.GetDataPresent(DataFormats.Bitmap))
{
Image image =
(Image)data.GetData(DataFormats.Bitmap, true);
// image.Save("W:\\users\\hm\\apirac-db\\teste-
b.bmp", System.Drawing.Imaging.ImageFormat.Bmp);
// image.Save("W:\\users\\hm\\apirac-db\\teste-
b.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
// image.Save("W:\\users\\hm\\apirac-db\\teste-
b.png", System.Drawing.Imaging.ImageFormat.Png);
if (args[1] = "jpeg")
{
image.Save(args[0],
System.Drawing.Imaging.ImageFormat.Jpeg);
}
else
{
MessageBox.Show("Formato de ficheiro requerido
não suportado (apenas JPG)");
}
}
else
{
MessageBox.Show("O 'clipboard' não contém uma
imagem");
}
}
else
{
MessageBox.Show("Nada há no 'clipboard'");
}
// fechar aplicação
Close ();
}
private void label1_Click(object sender, EventArgs e)
{
}
}
}
This is an adaptation of something found somewhere. The point is that
I can't figure out how to pass main () arguments to the code in the
second file.
At the moment it says:
The name 'args' does not exist in the current context
I understand the array args[] is unknown in the second file, but I
can't find a way to pass array.
Thanks
H. Martins