Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.88 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.  
  12.  
  13. namespace ToDoList
  14. {
  15.  
  16.     public partial class startForm : Form
  17.     {
  18.         public string path = "";
  19.         string loc1path = "loc1.txt";
  20.         string loc2path = "loc2.txt";
  21.         string theFile;
  22.         int loc1 = 29;
  23.         int loc2 = 85;
  24.         string loc2original = "85";
  25.         string thePath = "";
  26.         public static int ButtonClicked = 1;
  27.  
  28.  
  29.  
  30.         public startForm()
  31.         {
  32.  
  33.  
  34.             InitializeComponent();
  35.                 if (!File.Exists("./theFile.txt"))
  36.                 {
  37.                     FolderBrowserDialog fbd = new FolderBrowserDialog();
  38.                     if (fbd.ShowDialog() == DialogResult.OK)
  39.                     {
  40.                         path = fbd.SelectedPath;
  41.                         loc1path = Path.Combine(path, "loc1.txt");
  42.                         loc2path = Path.Combine(path, "loc2.txt");
  43.                         theFile = Path.Combine("./", "theFile.txt");
  44.                         File.WriteAllText(loc1path, loc1.ToString());
  45.                         File.WriteAllText(loc2path, loc2.ToString());
  46.                         File.WriteAllText(theFile, "something");
  47.                     }
  48.                 }
  49.                 else
  50.                 {
  51.                     loc1path = Path.Combine(path, "loc1.txt");
  52.                     loc2path = Path.Combine(path, "loc2.txt");
  53.                  theFile = Path.Combine("./", "theFile.txt");
  54.                  File.WriteAllText(loc1path, loc1.ToString());
  55.                  File.WriteAllText(loc2path, loc2.ToString());
  56.                  File.WriteAllText(theFile, "something");
  57.             }
  58.             }
  59.            
  60.  
  61.         private void label1_Click(object sender, EventArgs e)
  62.         {
  63.  
  64.         }
  65.  
  66.  
  67.         private void firstNote_Click(object sender, EventArgs e)
  68.         {
  69.             secondForm secondF = new secondForm("note1", path);
  70.             secondF.ShowDialog();
  71.         }
  72.  
  73.         private void button1_Click(object sender, EventArgs e)
  74.         {
  75.             if (ButtonClicked < 6)
  76.             {
  77.                 ButtonClicked++;
  78.                 generateButton();
  79.             }
  80.             else
  81.             {
  82.                 DialogResult noMoreButtons = MessageBox.Show("Sorry, you cannot create more than 6 notes");
  83.             }
  84.         }
  85.  
  86.         void newButton_Click(object sender, System.EventArgs e)
  87.         {
  88.             var butText = (sender as Button).Text;
  89.             secondForm secondF = new secondForm(butText, path);
  90.             secondF.ShowDialog();
  91.         }
  92.  
  93.         private void startForm_FormClosed(object sender, FormClosedEventArgs e)
  94.         {
  95.             if (ButtonClicked == 1)
  96.                 {
  97.                     File.WriteAllText(loc2path, loc2original);
  98.                 }
  99.             else
  100.                 {
  101.                     File.WriteAllText(loc2path, loc2original);
  102.                 }
  103.         }
  104.  
  105.         private void startForm_Load(object sender, EventArgs e)
  106.         {
  107.             if (File.Exists(Path.Combine(path, "Note 2.txt")))
  108.             {
  109.                 ButtonClicked = 2;
  110.                 generateButton();
  111.             }
  112.             if (File.Exists(Path.Combine(path, "Note 3.txt")))
  113.             {
  114.                 ButtonClicked = 3;
  115.                 generateButton();
  116.             }
  117.             if (File.Exists(Path.Combine(path, "Note 4.txt")))
  118.             {
  119.                 ButtonClicked = 4;
  120.                 generateButton();
  121.             }
  122.             if (File.Exists(Path.Combine(path, "Note 5.txt")))
  123.             {
  124.                 ButtonClicked = 5;
  125.                 generateButton();
  126.             }
  127.             if (File.Exists(Path.Combine(path, "Note 6.txt")))
  128.             {
  129.                 ButtonClicked = 6;
  130.                 generateButton();
  131.             }
  132.         }
  133.  
  134.         public void generateButton()
  135.          {
  136.             loc1 = Int32.Parse(File.ReadAllText(loc1path));
  137.             loc2 = Int32.Parse(File.ReadAllText(loc2path));
  138.             Button newButton = new Button();
  139.             newButton.Location = new Point(loc1, loc2 + 40);
  140.             newButton.Size = new Size(413, 23);
  141.             newButton.Text = string.Format("Note {0}", ButtonClicked);
  142.             newButton.Click += new EventHandler(this.newButton_Click);
  143.             this.Controls.Add(newButton);
  144.             loc2 = loc2 + 40;
  145.             File.WriteAllText(loc1path, loc1.ToString());
  146.             File.WriteAllText(loc2path, loc2.ToString());
  147.         }
  148.     }
  149. }
  150.  
  151. using System;
  152. using System.Collections.Generic;
  153. using System.ComponentModel;
  154. using System.Data;
  155. using System.Drawing;
  156. using System.IO;
  157. using System.Linq;
  158. using System.Text;
  159. using System.Threading.Tasks;
  160. using System.Windows.Forms;
  161.  
  162. namespace ToDoList
  163. {
  164.  
  165.     public partial class secondForm : Form
  166.     {
  167.  
  168.         string path;
  169.  
  170.         public secondForm(string butText, string path)
  171.         {
  172.             InitializeComponent();
  173.             this.path = Path.Combine(path, butText + ".txt");
  174.            
  175.  
  176.              if (File.Exists(Path.Combine(path, butText + ".txt")))
  177.             {
  178.                 userTextBox.Text = File.ReadAllText(Path.Combine(path, butText + ".txt"));
  179.            }
  180.           else
  181.            {
  182.           }
  183.         }
  184.  
  185.         private void userTextBox_TextChanged(object sender, EventArgs e)
  186.         {
  187.  
  188.         }
  189.  
  190.         private void saveButton_Click(object sender, EventArgs e)
  191.         {
  192.             File.WriteAllText(path, userTextBox.Text);
  193.             DialogResult saveFile = MessageBox.Show("File saved! " + path);
  194.         }
  195.  
  196.         private void button1_Click(object sender, EventArgs e)
  197.         {
  198.             this.Hide();
  199.             this.Close();
  200.  
  201.         }
  202.     }
  203. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement