【发布时间】:2013-02-04 14:47:54
【问题描述】:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
namespace MyProject
{
public partial class MyForm : Form
{
Process MyProcess;
public MyForm()
{
InitializeComponent();
}
private void MyForm_KeyPress(object sender, KeyPressEventArgs e)
{
switch (e.KeyChar)
{
case 'a':
this.MyPictureBox.Image = null;
this.MyProcess = new Process();
this.MyProcess.StartInfo =
new ProcessStartInfo("\"C:\\Program Files (x86)\\LilyPond\\usr\\bin\\lilypond.exe\"", "--png tmp.ly");
this.MyProcess.Start();
this.MyProcess.WaitForExit();
this.MyPictureBox.Image = new Bitmap("tmp.png");
break;
default:
break;
}
}
}
}
"C:\Program Files (x86)\LilyPond\usr\bin\lilypond.exe" --png tmp.ly 命令创建tmp.png。当我第一次按a 键时,MyProcess 返回 0,但下一个 - 总是返回 1。我认为问题在于覆盖了 MyPictureBox 使用的文件tmp.png,但我不知道如何修复它。你能帮帮我吗?
【问题讨论】:
-
删除它,如果它存在。查看此帖子:stackoverflow.com/questions/8905714/overwrite-existing-image