Skip to content

Commit

Permalink
Set Line Indexing
Browse files Browse the repository at this point in the history
Set Line Indexing in Textbox
  • Loading branch information
andresruizdev committed Sep 25, 2019
1 parent b6a63c9 commit 9b44ec7
Show file tree
Hide file tree
Showing 7 changed files with 379 additions and 2 deletions.
64 changes: 63 additions & 1 deletion DenebStudio/DenebStudio/DenebStudio.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion DenebStudio/DenebStudio/DenebStudio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ public partial class DenebStudio : MaterialForm
public DenebStudio()
{
InitializeComponent();
InitializeMaterialTheme();
}

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);
}

}
}
9 changes: 9 additions & 0 deletions DenebStudio/DenebStudio/DenebStudio.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,20 @@
<Compile Include="DenebStudio.Designer.cs">
<DependentUpon>DenebStudio.cs</DependentUpon>
</Compile>
<Compile Include="IndexedTextbox.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="IndexedTextbox.Designer.cs">
<DependentUpon>IndexedTextbox.cs</DependentUpon>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="DenebStudio.resx">
<DependentUpon>DenebStudio.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="IndexedTextbox.resx">
<DependentUpon>IndexedTextbox.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
Expand Down
3 changes: 3 additions & 0 deletions DenebStudio/DenebStudio/DenebStudio.resx
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,7 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="materialContextMenuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>
108 changes: 108 additions & 0 deletions DenebStudio/DenebStudio/IndexedTextbox.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

73 changes: 73 additions & 0 deletions DenebStudio/DenebStudio/IndexedTextbox.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
Loading

0 comments on commit 9b44ec7

Please sign in to comment.