Advertisement
Guest User

Untitled

a guest
Sep 24th, 2017
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.83 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Diagnostics;
  10. using System.IO;
  11. namespace WindowsFormsApplication2
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.         public Form1() { InitializeComponent(); }
  16.  
  17.         private void button1_Click(object sender, EventArgs e)
  18.         {
  19.             string baseDir = "c:\\ss\\";
  20.             string tempFile = "den";
  21.  
  22.             string tex = tempFile + ".tex";
  23.             string png = tempFile + ".png";
  24.             string ps = tempFile + ".ps";
  25.             string dvi = tempFile + ".dvi";
  26.  
  27.             //if (File.Exists(baseDir + png))
  28.             //    File.Delete(baseDir + png);
  29.  
  30.             File.WriteAllLines(baseDir + tempFile + ".tex", textBoxCommands.Lines);
  31.  
  32.             string strCmdLine =
  33.                 "/C cd c:\\ss & " + Ozellikler.texi2dviPath + " " + tex +
  34.                 "&" + Ozellikler.dvipsPath + " -E " + dvi;
  35.             string str2 =
  36.                 "/C cd c:\\ss & " + Ozellikler.imageMagickPath + " -density 200x200 " +
  37.                  baseDir + ps + " " + baseDir + png;
  38.  
  39.             // Use ProcessStartInfo class
  40.             ProcessStartInfo startInfo = new ProcessStartInfo();
  41.             startInfo.CreateNoWindow = false;
  42.             startInfo.UseShellExecute = false;
  43.             startInfo.FileName = "cmd.exe";
  44.             startInfo.WindowStyle = ProcessWindowStyle.Hidden;
  45.             startInfo.Arguments = strCmdLine + " & " + str2; ;
  46.  
  47.             try
  48.             {
  49.                 using (Process exeProcess = Process.Start(startInfo))
  50.                 {
  51.                     exeProcess.WaitForExit(3000);
  52.                     {
  53.                         foreach (Process p in System.Diagnostics.Process.GetProcessesByName("cmd"))
  54.                         {
  55.                             try
  56.                             {
  57.                                 p.Kill();
  58.                                 p.WaitForExit();
  59.                                 p.CloseMainWindow();
  60.                                 WindowState = FormWindowState.Normal;
  61.                             }
  62.                             catch
  63.                             {
  64.                                 MessageBox.Show("LATEX isleme hatasi");
  65.                             }
  66.                         }
  67.                     }
  68.                 }
  69.             }
  70.             catch
  71.             {
  72.                 MessageBox.Show("PROCESS OLUSTURMA HATASI");
  73.             }
  74.  
  75.             try
  76.             {
  77.                 pictureBox1.Image = Image.FromFile(baseDir + png);
  78.                 pictureBox1.Show();
  79.             }
  80.             catch
  81.             {
  82.                 MessageBox.Show("Resim Bulunan Dizinde Degil");
  83.             }
  84.         }
  85.     }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement