From fa57d7981751c422adafa9dd9ca910012d664e44 Mon Sep 17 00:00:00 2001 From: claes Date: Mon, 4 Jul 2022 09:30:27 +0200 Subject: [PATCH 1/3] Added basic forms to GUI --- NoteApp/Form1.Designer.cs | 93 ++++++++++++++++++++++++++++++++++++++- NoteApp/Form1.cs | 15 +++++++ NoteApp/Form1.resx | 62 +------------------------- 3 files changed, 108 insertions(+), 62 deletions(-) diff --git a/NoteApp/Form1.Designer.cs b/NoteApp/Form1.Designer.cs index c19f21c..fe908f5 100644 --- a/NoteApp/Form1.Designer.cs +++ b/NoteApp/Form1.Designer.cs @@ -28,12 +28,103 @@ protected override void Dispose(bool disposing) /// private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); + this.titelBox = new System.Windows.Forms.TextBox(); + this.noteBox = new System.Windows.Forms.TextBox(); + this.deleteButton = new System.Windows.Forms.Button(); + this.dataGridView1 = new System.Windows.Forms.DataGridView(); + this.saveButton = new System.Windows.Forms.Button(); + this.addButton = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); + this.SuspendLayout(); + // + // titelBox + // + this.titelBox.Font = new System.Drawing.Font("Times New Roman", 16F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point); + this.titelBox.Location = new System.Drawing.Point(313, 12); + this.titelBox.Name = "titelBox"; + this.titelBox.Size = new System.Drawing.Size(484, 44); + this.titelBox.TabIndex = 0; + this.titelBox.Text = "Titel"; + // + // noteBox + // + this.noteBox.AcceptsReturn = true; + this.noteBox.AcceptsTab = true; + this.noteBox.Font = new System.Drawing.Font("Times New Roman", 11F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.noteBox.Location = new System.Drawing.Point(313, 49); + this.noteBox.Multiline = true; + this.noteBox.Name = "noteBox"; + this.noteBox.Size = new System.Drawing.Size(484, 389); + this.noteBox.TabIndex = 1; + // + // deleteButton + // + this.deleteButton.Location = new System.Drawing.Point(218, 404); + this.deleteButton.Name = "deleteButton"; + this.deleteButton.Size = new System.Drawing.Size(89, 34); + this.deleteButton.TabIndex = 2; + this.deleteButton.Text = "Delete"; + this.deleteButton.UseVisualStyleBackColor = true; + this.deleteButton.Click += new System.EventHandler(this.button1_Click); + // + // dataGridView1 + // + this.dataGridView1.BackgroundColor = System.Drawing.SystemColors.Window; + this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView1.Location = new System.Drawing.Point(10, 12); + this.dataGridView1.Name = "dataGridView1"; + this.dataGridView1.RowHeadersWidth = 62; + this.dataGridView1.RowTemplate.Height = 33; + this.dataGridView1.Size = new System.Drawing.Size(297, 383); + this.dataGridView1.TabIndex = 3; + // + // saveButton + // + this.saveButton.Location = new System.Drawing.Point(114, 404); + this.saveButton.Name = "saveButton"; + this.saveButton.Size = new System.Drawing.Size(89, 34); + this.saveButton.TabIndex = 4; + this.saveButton.Text = "Save"; + this.saveButton.UseVisualStyleBackColor = true; + this.saveButton.Click += new System.EventHandler(this.saveButton_Click); + // + // addButton + // + this.addButton.Location = new System.Drawing.Point(10, 404); + this.addButton.Name = "addButton"; + this.addButton.Size = new System.Drawing.Size(89, 34); + this.addButton.TabIndex = 5; + this.addButton.Text = "Add"; + this.addButton.UseVisualStyleBackColor = true; + this.addButton.Click += new System.EventHandler(this.button2_Click); + // + // Form1 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.BackColor = System.Drawing.Color.Linen; this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.addButton); + this.Controls.Add(this.saveButton); + this.Controls.Add(this.dataGridView1); + this.Controls.Add(this.deleteButton); + this.Controls.Add(this.noteBox); + this.Controls.Add(this.titelBox); + this.Name = "Form1"; this.Text = "Form1"; + ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + } #endregion + + private TextBox titelBox; + private TextBox noteBox; + private Button deleteButton; + private DataGridView dataGridView1; + private Button saveButton; + private Button addButton; } } \ No newline at end of file diff --git a/NoteApp/Form1.cs b/NoteApp/Form1.cs index a0be3a7..6e3a083 100644 --- a/NoteApp/Form1.cs +++ b/NoteApp/Form1.cs @@ -6,5 +6,20 @@ public Form1() { InitializeComponent(); } + + private void button1_Click(object sender, EventArgs e) + { + + } + + private void button2_Click(object sender, EventArgs e) + { + + } + + private void saveButton_Click(object sender, EventArgs e) + { + + } } } \ No newline at end of file diff --git a/NoteApp/Form1.resx b/NoteApp/Form1.resx index 1af7de1..f298a7b 100644 --- a/NoteApp/Form1.resx +++ b/NoteApp/Form1.resx @@ -1,64 +1,4 @@ - - - + From b6b53b6167e93d2d311a07d9aa879dda913f78cd Mon Sep 17 00:00:00 2001 From: claes Date: Mon, 4 Jul 2022 09:53:40 +0200 Subject: [PATCH 2/3] Added basic functionalities, kinda 'works' --- NoteApp/Form1.Designer.cs | 41 +++++++++++++++++++++------------------ NoteApp/Form1.cs | 39 ++++++++++++++++++++++++++++++++----- NoteApp/Program.cs | 2 +- 3 files changed, 57 insertions(+), 25 deletions(-) diff --git a/NoteApp/Form1.Designer.cs b/NoteApp/Form1.Designer.cs index fe908f5..673d495 100644 --- a/NoteApp/Form1.Designer.cs +++ b/NoteApp/Form1.Designer.cs @@ -1,6 +1,6 @@ namespace NoteApp { - partial class Form1 + partial class NoteTaker { /// /// Required designer variable. @@ -31,9 +31,9 @@ private void InitializeComponent() this.titelBox = new System.Windows.Forms.TextBox(); this.noteBox = new System.Windows.Forms.TextBox(); this.deleteButton = new System.Windows.Forms.Button(); - this.dataGridView1 = new System.Windows.Forms.DataGridView(); this.saveButton = new System.Windows.Forms.Button(); this.addButton = new System.Windows.Forms.Button(); + this.dataGridView1 = new System.Windows.Forms.DataGridView(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); this.SuspendLayout(); // @@ -65,18 +65,7 @@ private void InitializeComponent() this.deleteButton.TabIndex = 2; this.deleteButton.Text = "Delete"; this.deleteButton.UseVisualStyleBackColor = true; - this.deleteButton.Click += new System.EventHandler(this.button1_Click); - // - // dataGridView1 - // - this.dataGridView1.BackgroundColor = System.Drawing.SystemColors.Window; - this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dataGridView1.Location = new System.Drawing.Point(10, 12); - this.dataGridView1.Name = "dataGridView1"; - this.dataGridView1.RowHeadersWidth = 62; - this.dataGridView1.RowTemplate.Height = 33; - this.dataGridView1.Size = new System.Drawing.Size(297, 383); - this.dataGridView1.TabIndex = 3; + this.deleteButton.Click += new System.EventHandler(this.deleteButton_Click); // // saveButton // @@ -96,22 +85,36 @@ private void InitializeComponent() this.addButton.TabIndex = 5; this.addButton.Text = "Add"; this.addButton.UseVisualStyleBackColor = true; - this.addButton.Click += new System.EventHandler(this.button2_Click); + this.addButton.Click += new System.EventHandler(this.addButton_Click); + // + // dataGridView1 + // + this.dataGridView1.BackgroundColor = System.Drawing.SystemColors.Window; + this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView1.Location = new System.Drawing.Point(10, 12); + this.dataGridView1.Name = "dataGridView1"; + this.dataGridView1.RowHeadersWidth = 62; + this.dataGridView1.RowTemplate.Height = 33; + this.dataGridView1.Size = new System.Drawing.Size(297, 386); + this.dataGridView1.TabIndex = 6; + this.dataGridView1.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellContentClick); + this.dataGridView1.CellContentDoubleClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellContentDoubleClick); // - // Form1 + // NoteTaker // this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.BackColor = System.Drawing.Color.Linen; this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.dataGridView1); this.Controls.Add(this.addButton); this.Controls.Add(this.saveButton); - this.Controls.Add(this.dataGridView1); this.Controls.Add(this.deleteButton); this.Controls.Add(this.noteBox); this.Controls.Add(this.titelBox); - this.Name = "Form1"; + this.Name = "NoteTaker"; this.Text = "Form1"; + this.Load += new System.EventHandler(this.NoteTaker_Load); ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -123,8 +126,8 @@ private void InitializeComponent() private TextBox titelBox; private TextBox noteBox; private Button deleteButton; - private DataGridView dataGridView1; private Button saveButton; private Button addButton; + private DataGridView dataGridView1; } } \ No newline at end of file diff --git a/NoteApp/Form1.cs b/NoteApp/Form1.cs index 6e3a083..ee16584 100644 --- a/NoteApp/Form1.cs +++ b/NoteApp/Form1.cs @@ -1,25 +1,54 @@ +using System.Data; + namespace NoteApp { - public partial class Form1 : Form + public partial class NoteTaker : Form { - public Form1() + DataTable notes = new DataTable(); + bool writeable = false; + public NoteTaker() { InitializeComponent(); } - private void button1_Click(object sender, EventArgs e) + private void deleteButton_Click(object sender, EventArgs e) + { + try + { + notes.Rows[dataGridView1.CurrentCell.RowIndex].Delete(); + } + catch (Exception ex) { Console.WriteLine("Invalid note, no action taken"); } + } + + private void addButton_Click(object sender, EventArgs e) + { + titelBox.Text = ""; + noteBox.Text = ""; + } + + private void saveButton_Click(object sender, EventArgs e) + { + notes.Rows.Add(titelBox.Text, noteBox.Text); + } + + private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { } - private void button2_Click(object sender, EventArgs e) + private void dataGridView1_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e) { + titelBox.Text = notes.Rows[dataGridView1.CurrentCell.RowIndex].ItemArray[0].ToString(); + noteBox.Text = notes.Rows[dataGridView1.CurrentCell.RowIndex].ItemArray[1].ToString(); } - private void saveButton_Click(object sender, EventArgs e) + private void NoteTaker_Load(object sender, EventArgs e) { + notes.Columns.Add("Title"); + notes.Columns.Add("note"); + dataGridView1.DataSource = notes; } } } \ No newline at end of file diff --git a/NoteApp/Program.cs b/NoteApp/Program.cs index 858cf62..632f2ab 100644 --- a/NoteApp/Program.cs +++ b/NoteApp/Program.cs @@ -11,7 +11,7 @@ static void Main() // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new Form1()); + Application.Run(new NoteTaker()); } } } \ No newline at end of file From 66efd9c7c8a37614bfa876ddccc33a5e6e398054 Mon Sep 17 00:00:00 2001 From: claes Date: Mon, 4 Jul 2022 10:55:54 +0200 Subject: [PATCH 3/3] Finalized first verison of note app --- NoteApp/Form1.Designer.cs | 5 +++++ NoteApp/Form1.cs | 17 +++++++++++++++-- NoteApp/writeToCSV.cs | 21 +++++++++++++++++++++ 3 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 NoteApp/writeToCSV.cs diff --git a/NoteApp/Form1.Designer.cs b/NoteApp/Form1.Designer.cs index 673d495..0064515 100644 --- a/NoteApp/Form1.Designer.cs +++ b/NoteApp/Form1.Designer.cs @@ -89,10 +89,15 @@ private void InitializeComponent() // // dataGridView1 // + this.dataGridView1.AllowUserToAddRows = false; + this.dataGridView1.AllowUserToDeleteRows = false; + this.dataGridView1.AllowUserToResizeColumns = false; + this.dataGridView1.AllowUserToResizeRows = false; this.dataGridView1.BackgroundColor = System.Drawing.SystemColors.Window; this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.dataGridView1.Location = new System.Drawing.Point(10, 12); this.dataGridView1.Name = "dataGridView1"; + this.dataGridView1.ReadOnly = true; this.dataGridView1.RowHeadersWidth = 62; this.dataGridView1.RowTemplate.Height = 33; this.dataGridView1.Size = new System.Drawing.Size(297, 386); diff --git a/NoteApp/Form1.cs b/NoteApp/Form1.cs index ee16584..e1ef6b2 100644 --- a/NoteApp/Form1.cs +++ b/NoteApp/Form1.cs @@ -5,7 +5,7 @@ namespace NoteApp public partial class NoteTaker : Form { DataTable notes = new DataTable(); - bool writeable = false; + bool editing = false; public NoteTaker() { InitializeComponent(); @@ -28,7 +28,19 @@ private void addButton_Click(object sender, EventArgs e) private void saveButton_Click(object sender, EventArgs e) { - notes.Rows.Add(titelBox.Text, noteBox.Text); + + if (editing) + { + notes.Rows[dataGridView1.CurrentCell.RowIndex]["Title"] = titelBox.Text; + notes.Rows[dataGridView1.CurrentCell.RowIndex]["note"] = noteBox.Text; + } + else + { + notes.Rows.Add(titelBox.Text, noteBox.Text); + } + titelBox.Text = "Title"; + noteBox.Text = ""; + editing = false; } private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) @@ -41,6 +53,7 @@ private void dataGridView1_CellContentDoubleClick(object sender, DataGridViewCel titelBox.Text = notes.Rows[dataGridView1.CurrentCell.RowIndex].ItemArray[0].ToString(); noteBox.Text = notes.Rows[dataGridView1.CurrentCell.RowIndex].ItemArray[1].ToString(); + editing = true; } private void NoteTaker_Load(object sender, EventArgs e) diff --git a/NoteApp/writeToCSV.cs b/NoteApp/writeToCSV.cs new file mode 100644 index 0000000..14bac0b --- /dev/null +++ b/NoteApp/writeToCSV.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.IO; + +namespace NoteApp +{ + /* + public classwriteToCSV + { + DirectoryInfo[] cDirs = new DirectoryInfo(@"c:\").GetDirectories(); + + using (StreamWriter sw = new StreamWriter("CDriveDirs.txt")) + { + + } + } + */ +}