Pregunta

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 command creates tmp.png. When I press a key first time, MyProcess returns 0, but next - returns 1 always. I think the problem is in overwritting file tmp.png, which is using by MyPictureBox, but I have no idea how to repair it. Could you help me?

¿Fue útil?

Solución

As far as I know lilypond does not give an option for overwriting using a command line argument. If I'm right then you can include code to delete then png file (if exsists) before MyProcess starts.

if (System.IO.File.Exists(path))
{
    System.IO.File.Delete(path);
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top