From 9b44ec72ee027cedbe22acbb5aed82cd352804b5 Mon Sep 17 00:00:00 2001 From: Andres Ruiz Date: Wed, 25 Sep 2019 00:51:33 -0500 Subject: [PATCH] Set Line Indexing Set Line Indexing in Textbox --- .../DenebStudio/DenebStudio.Designer.cs | 64 +++++++++- DenebStudio/DenebStudio/DenebStudio.cs | 4 +- DenebStudio/DenebStudio/DenebStudio.csproj | 9 ++ DenebStudio/DenebStudio/DenebStudio.resx | 3 + .../DenebStudio/IndexedTextbox.Designer.cs | 108 ++++++++++++++++ DenebStudio/DenebStudio/IndexedTextbox.cs | 73 +++++++++++ DenebStudio/DenebStudio/IndexedTextbox.resx | 120 ++++++++++++++++++ 7 files changed, 379 insertions(+), 2 deletions(-) create mode 100644 DenebStudio/DenebStudio/IndexedTextbox.Designer.cs create mode 100644 DenebStudio/DenebStudio/IndexedTextbox.cs create mode 100644 DenebStudio/DenebStudio/IndexedTextbox.resx diff --git a/DenebStudio/DenebStudio/DenebStudio.Designer.cs b/DenebStudio/DenebStudio/DenebStudio.Designer.cs index 64ff076..b40fb13 100644 --- a/DenebStudio/DenebStudio/DenebStudio.Designer.cs +++ b/DenebStudio/DenebStudio/DenebStudio.Designer.cs @@ -29,6 +29,13 @@ protected override void Dispose(bool disposing) private void InitializeComponent() { this.pnlMain = new System.Windows.Forms.Panel(); + this.pnlCode = new System.Windows.Forms.Panel(); + this.pnlConsole = new System.Windows.Forms.Panel(); + this.pnlProjetManager = new System.Windows.Forms.Panel(); + this.materialContextMenuStrip1 = new MaterialSkin.Controls.MaterialContextMenuStrip(); + this.indexedTextbox1 = new DenebStudioControls.IndexedTextbox(); + this.pnlMain.SuspendLayout(); + this.pnlCode.SuspendLayout(); this.SuspendLayout(); // // pnlMain @@ -36,12 +43,60 @@ private void InitializeComponent() this.pnlMain.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); - this.pnlMain.BackColor = System.Drawing.SystemColors.ButtonShadow; + this.pnlMain.BackColor = System.Drawing.SystemColors.Control; + this.pnlMain.Controls.Add(this.pnlCode); + this.pnlMain.Controls.Add(this.pnlConsole); + this.pnlMain.Controls.Add(this.pnlProjetManager); this.pnlMain.Location = new System.Drawing.Point(0, 63); this.pnlMain.Name = "pnlMain"; this.pnlMain.Size = new System.Drawing.Size(916, 493); this.pnlMain.TabIndex = 4; // + // pnlCode + // + this.pnlCode.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(28)))), ((int)(((byte)(28)))), ((int)(((byte)(28))))); + this.pnlCode.Controls.Add(this.indexedTextbox1); + this.pnlCode.Dock = System.Windows.Forms.DockStyle.Fill; + this.pnlCode.Location = new System.Drawing.Point(243, 0); + this.pnlCode.Name = "pnlCode"; + this.pnlCode.Size = new System.Drawing.Size(673, 300); + this.pnlCode.TabIndex = 2; + // + // pnlConsole + // + this.pnlConsole.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(28)))), ((int)(((byte)(28)))), ((int)(((byte)(28))))); + this.pnlConsole.Dock = System.Windows.Forms.DockStyle.Bottom; + this.pnlConsole.Location = new System.Drawing.Point(243, 300); + this.pnlConsole.Name = "pnlConsole"; + this.pnlConsole.Size = new System.Drawing.Size(673, 193); + this.pnlConsole.TabIndex = 1; + // + // pnlProjetManager + // + this.pnlProjetManager.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(28)))), ((int)(((byte)(28)))), ((int)(((byte)(28))))); + this.pnlProjetManager.Dock = System.Windows.Forms.DockStyle.Left; + this.pnlProjetManager.Location = new System.Drawing.Point(0, 0); + this.pnlProjetManager.Name = "pnlProjetManager"; + this.pnlProjetManager.Size = new System.Drawing.Size(243, 493); + this.pnlProjetManager.TabIndex = 0; + // + // materialContextMenuStrip1 + // + this.materialContextMenuStrip1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(255))))); + this.materialContextMenuStrip1.Depth = 0; + this.materialContextMenuStrip1.MouseState = MaterialSkin.MouseState.HOVER; + this.materialContextMenuStrip1.Name = "materialContextMenuStrip1"; + this.materialContextMenuStrip1.Size = new System.Drawing.Size(61, 4); + // + // indexedTextbox1 + // + this.indexedTextbox1.Dock = System.Windows.Forms.DockStyle.Fill; + this.indexedTextbox1.ForeColor = System.Drawing.SystemColors.Control; + this.indexedTextbox1.Location = new System.Drawing.Point(0, 0); + this.indexedTextbox1.Name = "indexedTextbox1"; + this.indexedTextbox1.Size = new System.Drawing.Size(673, 300); + this.indexedTextbox1.TabIndex = 0; + // // DenebStudio // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -50,6 +105,8 @@ private void InitializeComponent() this.Controls.Add(this.pnlMain); this.Name = "DenebStudio"; this.Text = "Deneb Studio"; + this.pnlMain.ResumeLayout(false); + this.pnlCode.ResumeLayout(false); this.ResumeLayout(false); } @@ -57,6 +114,11 @@ private void InitializeComponent() #endregion private System.Windows.Forms.Panel pnlMain; + private System.Windows.Forms.Panel pnlCode; + private System.Windows.Forms.Panel pnlConsole; + private System.Windows.Forms.Panel pnlProjetManager; + private MaterialSkin.Controls.MaterialContextMenuStrip materialContextMenuStrip1; + private DenebStudioControls.IndexedTextbox indexedTextbox1; } } diff --git a/DenebStudio/DenebStudio/DenebStudio.cs b/DenebStudio/DenebStudio/DenebStudio.cs index 8e295ea..11264d2 100644 --- a/DenebStudio/DenebStudio/DenebStudio.cs +++ b/DenebStudio/DenebStudio/DenebStudio.cs @@ -17,6 +17,7 @@ public partial class DenebStudio : MaterialForm public DenebStudio() { InitializeComponent(); + InitializeMaterialTheme(); } private void InitializeMaterialTheme() @@ -24,7 +25,8 @@ private void InitializeMaterialTheme() var materialSkinManager = MaterialSkinManager.Instance; materialSkinManager.AddFormToManage(this); materialSkinManager.Theme = MaterialSkinManager.Themes.LIGHT; - materialSkinManager.ColorScheme = new ColorScheme(Primary.BlueGrey800, Primary.BlueGrey900, Primary.BlueGrey500, Accent.LightBlue200, TextShade.WHITE); + materialSkinManager.ColorScheme = new ColorScheme(Primary.Blue800, Primary.Blue900, Primary.Blue500, Accent.LightBlue200, TextShade.WHITE); } + } } diff --git a/DenebStudio/DenebStudio/DenebStudio.csproj b/DenebStudio/DenebStudio/DenebStudio.csproj index 49f3522..100e0e2 100644 --- a/DenebStudio/DenebStudio/DenebStudio.csproj +++ b/DenebStudio/DenebStudio/DenebStudio.csproj @@ -55,11 +55,20 @@ DenebStudio.cs + + UserControl + + + IndexedTextbox.cs + DenebStudio.cs + + IndexedTextbox.cs + ResXFileCodeGenerator Resources.Designer.cs diff --git a/DenebStudio/DenebStudio/DenebStudio.resx b/DenebStudio/DenebStudio/DenebStudio.resx index 29dcb1b..cc0f2e4 100644 --- a/DenebStudio/DenebStudio/DenebStudio.resx +++ b/DenebStudio/DenebStudio/DenebStudio.resx @@ -117,4 +117,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 17, 17 + \ No newline at end of file diff --git a/DenebStudio/DenebStudio/IndexedTextbox.Designer.cs b/DenebStudio/DenebStudio/IndexedTextbox.Designer.cs new file mode 100644 index 0000000..94a2941 --- /dev/null +++ b/DenebStudio/DenebStudio/IndexedTextbox.Designer.cs @@ -0,0 +1,108 @@ +namespace DenebStudioControls +{ + partial class IndexedTextbox + { + /// + /// Variable del diseñador necesaria. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Limpiar los recursos que se estén usando. + /// + /// true si los recursos administrados se deben desechar; false en caso contrario. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Código generado por el Diseñador de componentes + + /// + /// Método necesario para admitir el Diseñador. No se puede modificar + /// el contenido de este método con el editor de código. + /// + private void InitializeComponent() + { + this.splitContainer1 = new System.Windows.Forms.SplitContainer(); + this.numberLabel = new System.Windows.Forms.Label(); + this.richTextBox1 = new System.Windows.Forms.RichTextBox(); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); + this.splitContainer1.Panel1.SuspendLayout(); + this.splitContainer1.Panel2.SuspendLayout(); + this.splitContainer1.SuspendLayout(); + this.SuspendLayout(); + // + // splitContainer1 + // + this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill; + this.splitContainer1.FixedPanel = System.Windows.Forms.FixedPanel.Panel1; + this.splitContainer1.IsSplitterFixed = true; + this.splitContainer1.Location = new System.Drawing.Point(0, 0); + this.splitContainer1.Name = "splitContainer1"; + // + // splitContainer1.Panel1 + // + this.splitContainer1.Panel1.Controls.Add(this.numberLabel); + // + // splitContainer1.Panel2 + // + this.splitContainer1.Panel2.Controls.Add(this.richTextBox1); + this.splitContainer1.Size = new System.Drawing.Size(403, 267); + this.splitContainer1.SplitterDistance = 41; + this.splitContainer1.SplitterWidth = 1; + this.splitContainer1.TabIndex = 2; + // + // numberLabel + // + this.numberLabel.Dock = System.Windows.Forms.DockStyle.Left; + this.numberLabel.Font = new System.Drawing.Font("Consolas", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.numberLabel.Location = new System.Drawing.Point(0, 0); + this.numberLabel.Name = "numberLabel"; + this.numberLabel.Size = new System.Drawing.Size(37, 267); + this.numberLabel.TabIndex = 1; + this.numberLabel.Text = "1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n8\r\n9\r\n10\r\n11\r\n12\r\n13\r\n14\r\n15\r\n16"; + this.numberLabel.TextAlign = System.Drawing.ContentAlignment.TopRight; + // + // richTextBox1 + // + this.richTextBox1.BorderStyle = System.Windows.Forms.BorderStyle.None; + this.richTextBox1.Dock = System.Windows.Forms.DockStyle.Fill; + this.richTextBox1.Font = new System.Drawing.Font("Consolas", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.richTextBox1.Location = new System.Drawing.Point(0, 0); + this.richTextBox1.Name = "richTextBox1"; + this.richTextBox1.Size = new System.Drawing.Size(361, 267); + this.richTextBox1.TabIndex = 0; + this.richTextBox1.Text = ""; + this.richTextBox1.WordWrap = false; + this.richTextBox1.VScroll += new System.EventHandler(this.richTextBox1_VScroll); + this.richTextBox1.FontChanged += new System.EventHandler(this.richTextBox1_FontChanged); + this.richTextBox1.TextChanged += new System.EventHandler(this.richTextBox1_TextChanged); + this.richTextBox1.Resize += new System.EventHandler(this.richTextBox1_Resize); + // + // IndexedTextbox + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.splitContainer1); + this.Name = "IndexedTextbox"; + this.Size = new System.Drawing.Size(403, 267); + this.splitContainer1.Panel1.ResumeLayout(false); + this.splitContainer1.Panel2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit(); + this.splitContainer1.ResumeLayout(false); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.SplitContainer splitContainer1; + private System.Windows.Forms.Label numberLabel; + public System.Windows.Forms.RichTextBox richTextBox1; + } +} diff --git a/DenebStudio/DenebStudio/IndexedTextbox.cs b/DenebStudio/DenebStudio/IndexedTextbox.cs new file mode 100644 index 0000000..be1e066 --- /dev/null +++ b/DenebStudio/DenebStudio/IndexedTextbox.cs @@ -0,0 +1,73 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Drawing; +using System.Data; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace DenebStudioControls +{ + public partial class IndexedTextbox : UserControl + { + public IndexedTextbox() + { + InitializeComponent(); + + numberLabel.Font = new Font(richTextBox1.Font.FontFamily, richTextBox1.Font.Size); + } + + private void updateNumberLabel() + { + //we get index of first visible char and number of first visible line + Point pos = new Point(0, 0); + int firstIndex = richTextBox1.GetCharIndexFromPosition(pos); + int firstLine = richTextBox1.GetLineFromCharIndex(firstIndex); + + //now we get index of last visible char and number of last visible line + pos.X = ClientRectangle.Width; + pos.Y = ClientRectangle.Height; + int lastIndex = richTextBox1.GetCharIndexFromPosition(pos); + int lastLine = richTextBox1.GetLineFromCharIndex(lastIndex); + + //this is point position of last visible char, we'll use its Y value for calculating numberLabel size + pos = richTextBox1.GetPositionFromCharIndex(lastIndex); + + + //finally, renumber label + numberLabel.Text = ""; + for (int i = firstLine; i <= lastLine + 1; i++) + { + numberLabel.Text += i + 1 + "\n"; + } + + } + + private void richTextBox1_TextChanged(object sender, EventArgs e) + { + updateNumberLabel(); + } + + private void richTextBox1_VScroll(object sender, EventArgs e) + { + //move location of numberLabel for amount of pixels caused by scrollbar + int d = richTextBox1.GetPositionFromCharIndex(0).Y % (richTextBox1.Font.Height + 1); + numberLabel.Location = new Point(0, d); + + updateNumberLabel(); + } + + private void richTextBox1_Resize(object sender, EventArgs e) + { + richTextBox1_VScroll(null, null); + } + + private void richTextBox1_FontChanged(object sender, EventArgs e) + { + updateNumberLabel(); + richTextBox1_VScroll(null, null); + } + } +} diff --git a/DenebStudio/DenebStudio/IndexedTextbox.resx b/DenebStudio/DenebStudio/IndexedTextbox.resx new file mode 100644 index 0000000..29dcb1b --- /dev/null +++ b/DenebStudio/DenebStudio/IndexedTextbox.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file