0
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.pnga初めてキーを押すと、MyProcessは0を返しますが、next-は常に1を返します。tmp.pngMyPictureBoxで使用しているファイルの上書きに問題があると思いますが、どうすれば修復できるのかわかりません。私たちを手伝ってくれますか?

4

1 に答える 1

1

私の知る限り、lilypondはコマンドライン引数を使用して上書きするオプションを提供していません。私が正しければ、MyProcessを開始する前に、削除するコードを含めてからpngファイル(存在する場合)を含めることができます。

if (System.IO.File.Exists(path))
{
    System.IO.File.Delete(path);
}
于 2013-02-04T14:56:30.080 に答える