Initial commit.
+ CsvParser: CSV Parser with indexing. + CTextBox: CustomTextBox. + FrmCsvViewer: Basic form to view CSV files, as forms.
This commit is contained in:
27
.gitignore
vendored
Normal file
27
.gitignore
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
#ignorar miniaturas creadas por windows
|
||||
Thumbs.db
|
||||
#Ignorar archivos construidos por Visual Studio
|
||||
*.obj
|
||||
*.exe
|
||||
*.pdb
|
||||
*.user
|
||||
*.aps
|
||||
*.pch
|
||||
*.vspscc
|
||||
*_i.c
|
||||
*_p.c
|
||||
*.ncb
|
||||
*.suo
|
||||
*.tlb
|
||||
*.tlh
|
||||
*.bak
|
||||
*.cache
|
||||
*.ilk
|
||||
*.log
|
||||
[Bb]in
|
||||
[Dd]ebug*/
|
||||
*.lib
|
||||
*.sbr
|
||||
obj/
|
||||
[Rr]elease*/
|
||||
_ReSharper*/
|
||||
35
CTextBox.cs
Normal file
35
CTextBox.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Windows.Forms;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Drawing;
|
||||
|
||||
namespace CsvView
|
||||
{
|
||||
public class CTextBox : TextBox
|
||||
{
|
||||
public CTextBox()
|
||||
{
|
||||
Multiline = true;
|
||||
WordWrap = false;
|
||||
ScrollBars = ScrollBars.Horizontal;
|
||||
Font = new Font("Courier New", 9, FontStyle.Regular, GraphicsUnit.Point, 0);
|
||||
}
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
private static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wp, IntPtr lp);
|
||||
|
||||
private const int WM_MOUSEWHEEL = 0x20a;
|
||||
|
||||
protected override void WndProc(ref Message m)
|
||||
{
|
||||
if (m.Msg == WM_MOUSEWHEEL)
|
||||
{
|
||||
SendMessage(Parent.Handle, m.Msg, m.WParam, m.LParam);
|
||||
}
|
||||
else
|
||||
{
|
||||
base.WndProc(ref m);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
192
CsvParser.cs
Normal file
192
CsvParser.cs
Normal file
@@ -0,0 +1,192 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace CsvView
|
||||
{
|
||||
public class CsvParser
|
||||
{
|
||||
private bool _insideString = false;
|
||||
|
||||
private char _separator = ',';
|
||||
private char _quoteChar = '"';
|
||||
private char _escapeChar = '\\';
|
||||
|
||||
public CsvParser(char separator = ',', char quoteChar = '"', char escapeChar = '\\')
|
||||
{
|
||||
_separator = separator;
|
||||
_quoteChar = quoteChar;
|
||||
_escapeChar = escapeChar;
|
||||
}
|
||||
|
||||
private List<List<string>> _data = new List<List<string>>();
|
||||
|
||||
private List<string> _currentReg = null;
|
||||
StringBuilder _currentCell = null;
|
||||
|
||||
public List<List<string>> Data
|
||||
{
|
||||
get { return _data; }
|
||||
}
|
||||
|
||||
public void ParseLine(string line)
|
||||
{
|
||||
if(_currentReg == null)
|
||||
{
|
||||
_currentReg = new List<string>();
|
||||
}
|
||||
if(_currentCell == null)
|
||||
{
|
||||
_currentCell = new StringBuilder();
|
||||
}
|
||||
|
||||
for (int i = 0; i < line.Length; i++)
|
||||
{
|
||||
char c = line[i];
|
||||
if (c == _separator && _insideString == false)
|
||||
{
|
||||
_currentReg.Add(_currentCell.ToString());
|
||||
_currentCell.Clear();
|
||||
continue;
|
||||
}
|
||||
if (c == _quoteChar && _insideString == false)
|
||||
{
|
||||
_insideString = true;
|
||||
continue;
|
||||
}
|
||||
if (c == _quoteChar && _insideString == true)
|
||||
{
|
||||
_insideString = false;
|
||||
continue;
|
||||
}
|
||||
if (c == _escapeChar && _insideString)
|
||||
{
|
||||
i++;
|
||||
if (i == line.Length) { break; }
|
||||
c = line[i];
|
||||
}
|
||||
|
||||
_currentCell.Append(c);
|
||||
}
|
||||
|
||||
|
||||
if (_insideString)
|
||||
{
|
||||
_currentCell.Append('\n');
|
||||
}
|
||||
else
|
||||
{
|
||||
_currentReg.Add(_currentCell.ToString());
|
||||
_currentCell.Clear();
|
||||
_data.Add(_currentReg);
|
||||
_currentReg = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void ParseFile(string file, long offset = 0, int count = 0)
|
||||
{
|
||||
_insideString = false;
|
||||
_data = new List<List<string>>();
|
||||
_currentReg = null;
|
||||
FileStream stream = new FileStream(file, FileMode.Open);
|
||||
stream.Seek(offset, SeekOrigin.Begin);
|
||||
using (StreamReader reader = new StreamReader(stream, Encoding.Default, true, 4096))
|
||||
{
|
||||
string currentLine;
|
||||
while ((currentLine = reader.ReadLine()) != null)
|
||||
{
|
||||
ParseLine(currentLine);
|
||||
if(count>0 && Data.Count== count)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
stream.Close();
|
||||
}
|
||||
|
||||
private List<long> _index = new List<long>();
|
||||
|
||||
public List<long> Index { get { return _index; } }
|
||||
|
||||
private void DummyParser(string line)
|
||||
{
|
||||
for (int i = 0; i < line.Length; i++)
|
||||
{
|
||||
char c = line[i];
|
||||
if (c == _separator && _insideString == false)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (c == _quoteChar && _insideString == false)
|
||||
{
|
||||
_insideString = true;
|
||||
continue;
|
||||
}
|
||||
if (c == _quoteChar && _insideString == true)
|
||||
{
|
||||
_insideString = false;
|
||||
continue;
|
||||
}
|
||||
if (c == _escapeChar && _insideString)
|
||||
{
|
||||
i++;
|
||||
c = line[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class TrackingTextReader : TextReader
|
||||
{
|
||||
private TextReader _baseReader;
|
||||
private int _position;
|
||||
|
||||
public TrackingTextReader(TextReader baseReader)
|
||||
{
|
||||
_baseReader = baseReader;
|
||||
}
|
||||
|
||||
public override int Read()
|
||||
{
|
||||
_position++;
|
||||
return _baseReader.Read();
|
||||
}
|
||||
|
||||
public override int Peek()
|
||||
{
|
||||
return _baseReader.Peek();
|
||||
}
|
||||
|
||||
public int Position
|
||||
{
|
||||
get { return _position; }
|
||||
}
|
||||
}
|
||||
|
||||
public void GenerateIndex(string file)
|
||||
{
|
||||
_insideString = false;
|
||||
_index.Clear();
|
||||
FileStream stream = new FileStream(file, FileMode.Open);
|
||||
using (StreamReader streamReader = new StreamReader(stream, Encoding.Default, true, 4096))
|
||||
using (TrackingTextReader reader = new TrackingTextReader(streamReader))
|
||||
{
|
||||
string currentLine;
|
||||
if (_insideString == false)
|
||||
{
|
||||
_index.Add(reader.Position);
|
||||
}
|
||||
while ((currentLine = reader.ReadLine()) != null)
|
||||
{
|
||||
DummyParser(currentLine);
|
||||
if (_insideString == false)
|
||||
{
|
||||
_index.Add(reader.Position);
|
||||
}
|
||||
}
|
||||
}
|
||||
stream.Close();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
74
CsvView.csproj
Normal file
74
CsvView.csproj
Normal file
@@ -0,0 +1,74 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{587169B9-7891-4A2F-8537-9196898B86AF}</ProjectGuid>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>CsvView</RootNamespace>
|
||||
<AssemblyName>CsvView</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Deployment" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="CsvParser.cs" />
|
||||
<Compile Include="CTextBox.cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
<Compile Include="FrmCsvViewer.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="FrmCsvViewer.Designer.cs">
|
||||
<DependentUpon>FrmCsvViewer.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="MessageBoxEx.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<EmbeddedResource Include="FrmCsvViewer.resx">
|
||||
<DependentUpon>FrmCsvViewer.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
22
CsvView.sln
Normal file
22
CsvView.sln
Normal file
@@ -0,0 +1,22 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 14
|
||||
VisualStudioVersion = 14.0.25420.1
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CsvView", "CsvView.csproj", "{587169B9-7891-4A2F-8537-9196898B86AF}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{587169B9-7891-4A2F-8537-9196898B86AF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{587169B9-7891-4A2F-8537-9196898B86AF}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{587169B9-7891-4A2F-8537-9196898B86AF}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{587169B9-7891-4A2F-8537-9196898B86AF}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
210
FrmCsvViewer.Designer.cs
generated
Normal file
210
FrmCsvViewer.Designer.cs
generated
Normal file
@@ -0,0 +1,210 @@
|
||||
namespace CsvView
|
||||
{
|
||||
partial class FrmCsvViewer
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.txtPath = new System.Windows.Forms.TextBox();
|
||||
this.btnLoad = new System.Windows.Forms.Button();
|
||||
this.btnFirstReg = new System.Windows.Forms.Button();
|
||||
this.btnPrevReg = new System.Windows.Forms.Button();
|
||||
this.btnNextReg = new System.Windows.Forms.Button();
|
||||
this.btnLastReg = new System.Windows.Forms.Button();
|
||||
this.txtCurrentReg = new System.Windows.Forms.TextBox();
|
||||
this.txtTotalRegs = new System.Windows.Forms.TextBox();
|
||||
this.tblRegNumbers = new System.Windows.Forms.TableLayoutPanel();
|
||||
this.pnlReg = new System.Windows.Forms.Panel();
|
||||
this.pnlData = new System.Windows.Forms.Panel();
|
||||
this.tblRegNumbers.SuspendLayout();
|
||||
this.pnlReg.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// txtPath
|
||||
//
|
||||
this.txtPath.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.txtPath.Location = new System.Drawing.Point(12, 14);
|
||||
this.txtPath.Name = "txtPath";
|
||||
this.txtPath.Size = new System.Drawing.Size(457, 20);
|
||||
this.txtPath.TabIndex = 0;
|
||||
this.txtPath.DoubleClick += new System.EventHandler(this.txtPath_DoubleClick);
|
||||
//
|
||||
// btnLoad
|
||||
//
|
||||
this.btnLoad.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.btnLoad.Location = new System.Drawing.Point(475, 11);
|
||||
this.btnLoad.Name = "btnLoad";
|
||||
this.btnLoad.Size = new System.Drawing.Size(45, 23);
|
||||
this.btnLoad.TabIndex = 3;
|
||||
this.btnLoad.Text = "Load";
|
||||
this.btnLoad.UseVisualStyleBackColor = true;
|
||||
this.btnLoad.Click += new System.EventHandler(this.btnLoad_Click);
|
||||
//
|
||||
// btnFirstReg
|
||||
//
|
||||
this.btnFirstReg.Font = new System.Drawing.Font("Courier New", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.btnFirstReg.Location = new System.Drawing.Point(0, 0);
|
||||
this.btnFirstReg.Name = "btnFirstReg";
|
||||
this.btnFirstReg.Size = new System.Drawing.Size(36, 30);
|
||||
this.btnFirstReg.TabIndex = 4;
|
||||
this.btnFirstReg.Text = "|<";
|
||||
this.btnFirstReg.UseVisualStyleBackColor = true;
|
||||
this.btnFirstReg.Click += new System.EventHandler(this.btnFirstReg_Click);
|
||||
//
|
||||
// btnPrevReg
|
||||
//
|
||||
this.btnPrevReg.Font = new System.Drawing.Font("Courier New", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.btnPrevReg.Location = new System.Drawing.Point(42, 0);
|
||||
this.btnPrevReg.Name = "btnPrevReg";
|
||||
this.btnPrevReg.Size = new System.Drawing.Size(36, 30);
|
||||
this.btnPrevReg.TabIndex = 5;
|
||||
this.btnPrevReg.Text = "<";
|
||||
this.btnPrevReg.UseVisualStyleBackColor = true;
|
||||
this.btnPrevReg.Click += new System.EventHandler(this.btnPrevReg_Click);
|
||||
//
|
||||
// btnNextReg
|
||||
//
|
||||
this.btnNextReg.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.btnNextReg.Font = new System.Drawing.Font("Courier New", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.btnNextReg.Location = new System.Drawing.Point(430, 0);
|
||||
this.btnNextReg.Name = "btnNextReg";
|
||||
this.btnNextReg.Size = new System.Drawing.Size(36, 30);
|
||||
this.btnNextReg.TabIndex = 6;
|
||||
this.btnNextReg.Text = ">";
|
||||
this.btnNextReg.UseVisualStyleBackColor = true;
|
||||
this.btnNextReg.Click += new System.EventHandler(this.btnNextReg_Click);
|
||||
//
|
||||
// btnLastReg
|
||||
//
|
||||
this.btnLastReg.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.btnLastReg.Font = new System.Drawing.Font("Courier New", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.btnLastReg.Location = new System.Drawing.Point(472, 0);
|
||||
this.btnLastReg.Name = "btnLastReg";
|
||||
this.btnLastReg.Size = new System.Drawing.Size(36, 30);
|
||||
this.btnLastReg.TabIndex = 7;
|
||||
this.btnLastReg.Text = ">|";
|
||||
this.btnLastReg.UseVisualStyleBackColor = true;
|
||||
this.btnLastReg.Click += new System.EventHandler(this.btnLastReg_Click);
|
||||
//
|
||||
// txtCurrentReg
|
||||
//
|
||||
this.txtCurrentReg.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.txtCurrentReg.Location = new System.Drawing.Point(3, 3);
|
||||
this.txtCurrentReg.Name = "txtCurrentReg";
|
||||
this.txtCurrentReg.Size = new System.Drawing.Size(164, 20);
|
||||
this.txtCurrentReg.TabIndex = 8;
|
||||
this.txtCurrentReg.TextChanged += new System.EventHandler(this.txtCurrentReg_TextChanged);
|
||||
//
|
||||
// txtTotalRegs
|
||||
//
|
||||
this.txtTotalRegs.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.txtTotalRegs.Location = new System.Drawing.Point(173, 3);
|
||||
this.txtTotalRegs.Name = "txtTotalRegs";
|
||||
this.txtTotalRegs.ReadOnly = true;
|
||||
this.txtTotalRegs.Size = new System.Drawing.Size(164, 20);
|
||||
this.txtTotalRegs.TabIndex = 9;
|
||||
//
|
||||
// tblRegNumbers
|
||||
//
|
||||
this.tblRegNumbers.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.tblRegNumbers.ColumnCount = 2;
|
||||
this.tblRegNumbers.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
|
||||
this.tblRegNumbers.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
|
||||
this.tblRegNumbers.Controls.Add(this.txtTotalRegs, 1, 0);
|
||||
this.tblRegNumbers.Controls.Add(this.txtCurrentReg, 0, 0);
|
||||
this.tblRegNumbers.Location = new System.Drawing.Point(84, 0);
|
||||
this.tblRegNumbers.Name = "tblRegNumbers";
|
||||
this.tblRegNumbers.RowCount = 1;
|
||||
this.tblRegNumbers.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
|
||||
this.tblRegNumbers.Size = new System.Drawing.Size(340, 30);
|
||||
this.tblRegNumbers.TabIndex = 10;
|
||||
//
|
||||
// pnlReg
|
||||
//
|
||||
this.pnlReg.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.pnlReg.Controls.Add(this.pnlData);
|
||||
this.pnlReg.Controls.Add(this.btnPrevReg);
|
||||
this.pnlReg.Controls.Add(this.tblRegNumbers);
|
||||
this.pnlReg.Controls.Add(this.btnFirstReg);
|
||||
this.pnlReg.Controls.Add(this.btnLastReg);
|
||||
this.pnlReg.Controls.Add(this.btnNextReg);
|
||||
this.pnlReg.Enabled = false;
|
||||
this.pnlReg.Location = new System.Drawing.Point(12, 40);
|
||||
this.pnlReg.Name = "pnlReg";
|
||||
this.pnlReg.Size = new System.Drawing.Size(508, 469);
|
||||
this.pnlReg.TabIndex = 11;
|
||||
//
|
||||
// pnlData
|
||||
//
|
||||
this.pnlData.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.pnlData.AutoScroll = true;
|
||||
this.pnlData.Location = new System.Drawing.Point(0, 37);
|
||||
this.pnlData.Name = "pnlData";
|
||||
this.pnlData.Size = new System.Drawing.Size(508, 432);
|
||||
this.pnlData.TabIndex = 11;
|
||||
//
|
||||
// FrmCsvViewer
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(532, 521);
|
||||
this.Controls.Add(this.pnlReg);
|
||||
this.Controls.Add(this.btnLoad);
|
||||
this.Controls.Add(this.txtPath);
|
||||
this.Name = "FrmCsvViewer";
|
||||
this.Text = "CsvViewer";
|
||||
this.tblRegNumbers.ResumeLayout(false);
|
||||
this.tblRegNumbers.PerformLayout();
|
||||
this.pnlReg.ResumeLayout(false);
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.TextBox txtPath;
|
||||
private System.Windows.Forms.Button btnLoad;
|
||||
private System.Windows.Forms.Button btnFirstReg;
|
||||
private System.Windows.Forms.Button btnPrevReg;
|
||||
private System.Windows.Forms.Button btnNextReg;
|
||||
private System.Windows.Forms.Button btnLastReg;
|
||||
private System.Windows.Forms.TextBox txtCurrentReg;
|
||||
private System.Windows.Forms.TextBox txtTotalRegs;
|
||||
private System.Windows.Forms.TableLayoutPanel tblRegNumbers;
|
||||
private System.Windows.Forms.Panel pnlReg;
|
||||
private System.Windows.Forms.Panel pnlData;
|
||||
}
|
||||
}
|
||||
|
||||
169
FrmCsvViewer.cs
Normal file
169
FrmCsvViewer.cs
Normal file
@@ -0,0 +1,169 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace CsvView
|
||||
{
|
||||
public partial class FrmCsvViewer : Form
|
||||
{
|
||||
public FrmCsvViewer()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void txtPath_DoubleClick(object sender, EventArgs e)
|
||||
{
|
||||
OpenFileDialog loadDialog = new OpenFileDialog();
|
||||
DialogResult result = loadDialog.ShowDialog();
|
||||
if (result == DialogResult.OK)
|
||||
{
|
||||
txtPath.Text = loadDialog.FileName;
|
||||
}
|
||||
}
|
||||
|
||||
private string _loadedFile = string.Empty;
|
||||
private long _currentReg = 0;
|
||||
private long _totalRegs = 0;
|
||||
private List<List<string>> _data = null;
|
||||
|
||||
private void btnLoad_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (File.Exists(txtPath.Text) == false)
|
||||
{
|
||||
RenderRegClean();
|
||||
_loadedFile = null;
|
||||
_totalRegs = 0;
|
||||
_data = null;
|
||||
MessageBoxEx.Show(this, "FileNotFound");
|
||||
return;
|
||||
}
|
||||
|
||||
_loadedFile = txtPath.Text;
|
||||
|
||||
var csvParser = new CsvParser();
|
||||
csvParser.ParseFile(_loadedFile);
|
||||
|
||||
_totalRegs = csvParser.Data.Count;
|
||||
_data = csvParser.Data;
|
||||
|
||||
RenderReg(0);
|
||||
}
|
||||
|
||||
[DllImport("user32.dll", CharSet = CharSet.Auto)]
|
||||
private static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);
|
||||
|
||||
private const int WM_SetRedraw = 0XB;
|
||||
|
||||
private void RenderReg(long currentReg)
|
||||
{
|
||||
if (_data == null || _data.Count <= 0)
|
||||
{
|
||||
RenderRegClean();
|
||||
}
|
||||
pnlReg.Enabled = true;
|
||||
bool first = false;
|
||||
bool last = false;
|
||||
if (currentReg <= 0)
|
||||
{
|
||||
currentReg = 0;
|
||||
first = true;
|
||||
}
|
||||
if (currentReg >= (_totalRegs - 1))
|
||||
{
|
||||
currentReg = _totalRegs - 1;
|
||||
last = true;
|
||||
}
|
||||
|
||||
_currentReg = currentReg;
|
||||
txtCurrentReg.Text = Convert.ToString(currentReg);
|
||||
txtTotalRegs.Text = Convert.ToString(_totalRegs);
|
||||
|
||||
btnFirstReg.Enabled = (first == false);
|
||||
btnPrevReg.Enabled = (first == false);
|
||||
btnLastReg.Enabled = (last == false);
|
||||
btnNextReg.Enabled = (last == false);
|
||||
|
||||
List<string> currentData = _data[(int)currentReg];
|
||||
|
||||
pnlData.Visible = false;
|
||||
pnlData.Controls.Clear();
|
||||
int y = 0;
|
||||
const int TexboxPadding = 5;
|
||||
const int Padding = 9;
|
||||
const int LineHeight = 15;
|
||||
for (int i = 0; i < currentData.Count; i++)
|
||||
{
|
||||
TextBox txtValue = RenderValue(currentData[i], y, TexboxPadding, Padding, LineHeight);
|
||||
pnlData.Controls.Add(txtValue);
|
||||
y += txtValue.Height + Padding;
|
||||
}
|
||||
pnlData.Visible = true;
|
||||
}
|
||||
|
||||
private TextBox RenderValue(string value, int y, int TexboxPadding, int Padding, int LineHeight)
|
||||
{
|
||||
string[] valueLines = value.Split('\n');
|
||||
CTextBox txtValue = new CTextBox()
|
||||
{
|
||||
Anchor = (AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right),
|
||||
Width = pnlData.Width - Padding,
|
||||
Height = (valueLines.Length * LineHeight) + TexboxPadding,
|
||||
Top = y,
|
||||
Left = 0,
|
||||
ReadOnly = true,
|
||||
};
|
||||
for (int j = 0; j < valueLines.Length; j++)
|
||||
{
|
||||
if (j > 0)
|
||||
{
|
||||
txtValue.AppendText("\n");
|
||||
}
|
||||
txtValue.AppendText(valueLines[j]);
|
||||
}
|
||||
return txtValue;
|
||||
}
|
||||
|
||||
private void RenderRegClean()
|
||||
{
|
||||
pnlReg.Enabled = false;
|
||||
txtCurrentReg.Text = string.Empty;
|
||||
txtTotalRegs.Text = string.Empty;
|
||||
pnlData.Controls.Clear();
|
||||
}
|
||||
|
||||
private void btnFirstReg_Click(object sender, EventArgs e)
|
||||
{
|
||||
RenderReg(0);
|
||||
}
|
||||
|
||||
private void btnPrevReg_Click(object sender, EventArgs e)
|
||||
{
|
||||
RenderReg(_currentReg - 1);
|
||||
}
|
||||
|
||||
private void btnNextReg_Click(object sender, EventArgs e)
|
||||
{
|
||||
RenderReg(_currentReg + 1);
|
||||
}
|
||||
|
||||
private void btnLastReg_Click(object sender, EventArgs e)
|
||||
{
|
||||
RenderReg(_totalRegs - 1);
|
||||
}
|
||||
|
||||
private void txtCurrentReg_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
int newReg = 0;
|
||||
if (int.TryParse(txtCurrentReg.Text, out newReg))
|
||||
{
|
||||
RenderReg(newReg);
|
||||
}
|
||||
else
|
||||
{
|
||||
RenderReg(_currentReg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
120
FrmCsvViewer.resx
Normal file
120
FrmCsvViewer.resx
Normal file
@@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
||||
229
MessageBoxEx.cs
Normal file
229
MessageBoxEx.cs
Normal file
@@ -0,0 +1,229 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace CsvView
|
||||
{
|
||||
public class MessageBoxEx
|
||||
{
|
||||
private static IWin32Window _owner;
|
||||
private static HookProc _hookProc;
|
||||
private static IntPtr _hHook;
|
||||
|
||||
public static DialogResult Show(string text)
|
||||
{
|
||||
Initialize();
|
||||
return MessageBox.Show(text);
|
||||
}
|
||||
|
||||
public static DialogResult Show(string text, string caption)
|
||||
{
|
||||
Initialize();
|
||||
return MessageBox.Show(text, caption);
|
||||
}
|
||||
|
||||
public static DialogResult Show(string text, string caption, MessageBoxButtons buttons)
|
||||
{
|
||||
Initialize();
|
||||
return MessageBox.Show(text, caption, buttons);
|
||||
}
|
||||
|
||||
public static DialogResult Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon)
|
||||
{
|
||||
Initialize();
|
||||
return MessageBox.Show(text, caption, buttons, icon);
|
||||
}
|
||||
|
||||
public static DialogResult Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defButton)
|
||||
{
|
||||
Initialize();
|
||||
return MessageBox.Show(text, caption, buttons, icon, defButton);
|
||||
}
|
||||
|
||||
public static DialogResult Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defButton, MessageBoxOptions options)
|
||||
{
|
||||
Initialize();
|
||||
return MessageBox.Show(text, caption, buttons, icon, defButton, options);
|
||||
}
|
||||
|
||||
public static DialogResult Show(IWin32Window owner, string text)
|
||||
{
|
||||
_owner = owner;
|
||||
Initialize();
|
||||
return MessageBox.Show(owner, text);
|
||||
}
|
||||
|
||||
public static DialogResult Show(IWin32Window owner, string text, string caption)
|
||||
{
|
||||
_owner = owner;
|
||||
Initialize();
|
||||
return MessageBox.Show(owner, text, caption);
|
||||
}
|
||||
|
||||
public static DialogResult Show(IWin32Window owner, string text, string caption, MessageBoxButtons buttons)
|
||||
{
|
||||
_owner = owner;
|
||||
Initialize();
|
||||
return MessageBox.Show(owner, text, caption, buttons);
|
||||
}
|
||||
|
||||
public static DialogResult Show(IWin32Window owner, string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon)
|
||||
{
|
||||
_owner = owner;
|
||||
Initialize();
|
||||
return MessageBox.Show(owner, text, caption, buttons, icon);
|
||||
}
|
||||
|
||||
public static DialogResult Show(IWin32Window owner, string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defButton)
|
||||
{
|
||||
_owner = owner;
|
||||
Initialize();
|
||||
return MessageBox.Show(owner, text, caption, buttons, icon, defButton);
|
||||
}
|
||||
|
||||
public static DialogResult Show(IWin32Window owner, string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defButton, MessageBoxOptions options)
|
||||
{
|
||||
_owner = owner;
|
||||
Initialize();
|
||||
return MessageBox.Show(owner, text, caption, buttons, icon,
|
||||
defButton, options);
|
||||
}
|
||||
|
||||
public delegate IntPtr HookProc(int nCode, IntPtr wParam, IntPtr lParam);
|
||||
|
||||
public delegate void TimerProc(IntPtr hWnd, uint uMsg, UIntPtr nIDEvent, uint dwTime);
|
||||
|
||||
public const int WH_CALLWNDPROCRET = 12;
|
||||
|
||||
public enum CbtHookAction : int
|
||||
{
|
||||
HCBT_MOVESIZE = 0,
|
||||
HCBT_MINMAX = 1,
|
||||
HCBT_QS = 2,
|
||||
HCBT_CREATEWND = 3,
|
||||
HCBT_DESTROYWND = 4,
|
||||
HCBT_ACTIVATE = 5,
|
||||
HCBT_CLICKSKIPPED = 6,
|
||||
HCBT_KEYSKIPPED = 7,
|
||||
HCBT_SYSCOMMAND = 8,
|
||||
HCBT_SETFOCUS = 9
|
||||
}
|
||||
[DllImport("kernel32.dll")]
|
||||
private static extern uint GetCurrentThreadId();
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
private static extern bool GetWindowRect(IntPtr hWnd, ref Rectangle lpRect);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
private static extern int MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);
|
||||
|
||||
[DllImport("User32.dll")]
|
||||
public static extern UIntPtr SetTimer(IntPtr hWnd, UIntPtr nIDEvent, uint uElapse, TimerProc lpTimerFunc);
|
||||
|
||||
[DllImport("User32.dll")]
|
||||
public static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
public static extern IntPtr SetWindowsHookEx(int idHook, HookProc lpfn, IntPtr hInstance, int threadId);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
public static extern int UnhookWindowsHookEx(IntPtr idHook);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
public static extern IntPtr CallNextHookEx(IntPtr idHook, int nCode, IntPtr wParam, IntPtr lParam);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
public static extern int GetWindowTextLength(IntPtr hWnd);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
public static extern int GetWindowText(IntPtr hWnd, StringBuilder text, int maxLength);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
public static extern int EndDialog(IntPtr hDlg, IntPtr nResult);
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct CWPRETSTRUCT
|
||||
{
|
||||
public IntPtr lResult;
|
||||
public IntPtr lParam;
|
||||
public IntPtr wParam;
|
||||
public uint message;
|
||||
public IntPtr hwnd;
|
||||
};
|
||||
|
||||
static MessageBoxEx()
|
||||
{
|
||||
_hookProc = new HookProc(MessageBoxHookProc);
|
||||
_hHook = IntPtr.Zero;
|
||||
}
|
||||
|
||||
private static void Initialize()
|
||||
{
|
||||
if (_hHook != IntPtr.Zero)
|
||||
{
|
||||
throw new NotSupportedException("multiple calls are not supported");
|
||||
}
|
||||
|
||||
if (_owner != null)
|
||||
{
|
||||
_hHook = SetWindowsHookEx(WH_CALLWNDPROCRET, _hookProc, IntPtr.Zero, (int)GetCurrentThreadId());
|
||||
}
|
||||
}
|
||||
|
||||
private static IntPtr MessageBoxHookProc(int nCode, IntPtr wParam, IntPtr lParam)
|
||||
{
|
||||
if (nCode < 0)
|
||||
{
|
||||
return CallNextHookEx(_hHook, nCode, wParam, lParam);
|
||||
}
|
||||
|
||||
CWPRETSTRUCT msg = (CWPRETSTRUCT)Marshal.PtrToStructure(lParam, typeof(CWPRETSTRUCT));
|
||||
IntPtr hook = _hHook;
|
||||
|
||||
if (msg.message == (int)CbtHookAction.HCBT_ACTIVATE)
|
||||
{
|
||||
try
|
||||
{
|
||||
CenterWindow(msg.hwnd);
|
||||
}
|
||||
finally
|
||||
{
|
||||
UnhookWindowsHookEx(_hHook);
|
||||
_hHook = IntPtr.Zero;
|
||||
}
|
||||
}
|
||||
|
||||
return CallNextHookEx(hook, nCode, wParam, lParam);
|
||||
}
|
||||
|
||||
private static void CenterWindow(IntPtr hChildWnd)
|
||||
{
|
||||
Rectangle recChild = new Rectangle(0, 0, 0, 0);
|
||||
bool success = GetWindowRect(hChildWnd, ref recChild);
|
||||
|
||||
int width = recChild.Width - recChild.X;
|
||||
int height = recChild.Height - recChild.Y;
|
||||
|
||||
Rectangle recParent = new Rectangle(0, 0, 0, 0);
|
||||
success = GetWindowRect(_owner.Handle, ref recParent);
|
||||
|
||||
Point ptCenter = new Point(0, 0);
|
||||
ptCenter.X = recParent.X + ((recParent.Width - recParent.X) / 2);
|
||||
ptCenter.Y = recParent.Y + ((recParent.Height - recParent.Y) / 2);
|
||||
|
||||
|
||||
Point ptStart = new Point(0, 0);
|
||||
ptStart.X = (ptCenter.X - (width / 2));
|
||||
ptStart.Y = (ptCenter.Y - (height / 2));
|
||||
|
||||
ptStart.X = (ptStart.X < 0) ? 0 : ptStart.X;
|
||||
ptStart.Y = (ptStart.Y < 0) ? 0 : ptStart.Y;
|
||||
|
||||
int result = MoveWindow(hChildWnd, ptStart.X, ptStart.Y, width,
|
||||
height, false);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
22
Program.cs
Normal file
22
Program.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace CsvView.Net
|
||||
{
|
||||
static class Program
|
||||
{
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
Application.Run(new FrmCsvViewer());
|
||||
}
|
||||
}
|
||||
}
|
||||
14
Properties/AssemblyInfo.cs
Normal file
14
Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
[assembly: AssemblyTitle("CSVView.Net")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("CSVView.Net")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2017")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: ComVisible(false)]
|
||||
[assembly: Guid("587169b9-7891-4a2f-8537-9196898b86af")]
|
||||
[assembly: AssemblyVersion("1.0.*")]
|
||||
Reference in New Issue
Block a user