111,101
社区成员




namespace DrawIcon
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args) //修改Main()方法,增加参数。
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new frmDrawIcon(args[1])); //把args[1]传递给主窗体的构造方法。
}
}
}
public Form1(string[] args)
{
this.AllowDrop = true;
InitializeComponent();
if (args != null && args.Length > 0)
{
Image image = new Bitmap(args[0]);
this.pictureBox1.Image = image;
}
}
private void Form1_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
e.Effect = DragDropEffects.Copy;
else
e.Effect = DragDropEffects.None;
}
private void Form1_DragDrop(object sender, DragEventArgs e)
{
string[] arr = (string[])e.Data.GetData(DataFormats.FileDrop);
Image image = new Bitmap(arr[0]);
this.pictureBox1.Image = image;
}