Advertisement
DrAungWinHtut

2022031101 CS Code Editor

Mar 11th, 2022
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 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.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.IO;
  11. using System.Diagnostics;
  12.  
  13.  
  14. namespace _2022031101_CS_TextEditor
  15. {
  16. public partial class frmEditor : Form
  17. {
  18. public frmEditor()
  19. {
  20. InitializeComponent();
  21. }
  22.  
  23. private void btnLoad_Click(object sender, EventArgs e)
  24. {
  25. if( Directory.Exists(txtPath.Text))
  26. {
  27. lstFileList .Items.Clear();
  28. string[] saFileList = Directory.GetFiles(txtPath.Text);
  29. foreach (string sFile in saFileList)
  30. {
  31. lstFileList.Items.Add(sFile);
  32. }
  33. }
  34. else
  35. {
  36. MessageBox.Show("Error!, Invalid path! Pls try again");
  37. txtPath.SelectAll();
  38. txtPath.Focus();
  39.  
  40. }
  41.  
  42.  
  43.  
  44. }
  45.  
  46. private void lstFileList_SelectedIndexChanged(object sender, EventArgs e)
  47. {
  48. StreamReader sr = new StreamReader (lstFileList .SelectedItem .ToString ());
  49. string sData = sr.ReadToEnd ();
  50. txtEditor .Text = sData;
  51. sr.Close();
  52. }
  53.  
  54. private void btnSave_Click(object sender, EventArgs e)
  55. {
  56. if( MessageBox.Show("Are you sure you want to override file","Confirm",MessageBoxButtons.OKCancel) == DialogResult.OK)
  57. {
  58. string sData = txtEditor.Text;
  59. StreamWriter sw = new StreamWriter(lstFileList.SelectedItem.ToString());
  60. sw.Write(sData);
  61. sw.Close();
  62. }
  63.  
  64.  
  65. }
  66.  
  67. private void btnRun_Click(object sender, EventArgs e)
  68. {
  69. string sData = txtEditor.Text;
  70. StreamWriter sw = new StreamWriter("d:\\temp.py");
  71. sw.Write(sData);
  72. sw.Close();
  73. Process.Start("python","d:\\temp.py");
  74. }
  75. }
  76. }
  77.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement