Skip to content

Commit

Permalink
建立repo
Browse files Browse the repository at this point in the history
  • Loading branch information
xupefei committed May 23, 2012
0 parents commit 2ba49a5
Show file tree
Hide file tree
Showing 58 changed files with 11,046 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .gitignore
@@ -0,0 +1,27 @@
Thumbs.db
*.obj
*.exe
*.pdb
*.user
*.aps
*.pch
*.vspscc
*_i.c
*_p.c
*.ncb
*.suo
*.sln.docstates
*.tlb
*.tlh
*.bak
*.cache
*.ilk
*.log
[Bb]in
[Dd]ebug*/
*.lib
*.sbr
obj/
[Rr]elease*/
_ReSharper*/
[Tt]est[Rr]esult*
20 changes: 20 additions & 0 deletions Script Text Editor.sln
@@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Script Text Editor", "Script Text Editor\Script Text Editor.csproj", "{B8078F0A-E284-4BB2-B28F-C8220596FAC0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x86 = Debug|x86
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B8078F0A-E284-4BB2-B28F-C8220596FAC0}.Debug|x86.ActiveCfg = Debug|x86
{B8078F0A-E284-4BB2-B28F-C8220596FAC0}.Debug|x86.Build.0 = Debug|x86
{B8078F0A-E284-4BB2-B28F-C8220596FAC0}.Release|x86.ActiveCfg = Release|x86
{B8078F0A-E284-4BB2-B28F-C8220596FAC0}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
193 changes: 193 additions & 0 deletions Script Text Editor/Controls/DataGridViewEx.cs
@@ -0,0 +1,193 @@
using System;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using ComponentFactory.Krypton.Toolkit;

namespace Script_Text_Editor.Controls
{
public class DataGridViewEx : KryptonDataGridView
{
#region P/Invoke Function

private const int WM_KEYDOWN = 0x0100;
private const int WM_HSCROLL = 0x0114;
private const int WM_VSCROLL = 0x0115;
private const int WM_MOUSEWHEEL = 0x020A;

protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case WM_KEYDOWN:
case WM_HSCROLL:
case WM_VSCROLL:
case WM_MOUSEWHEEL:
Invalidate();
break;
}

base.WndProc(ref m);
}

internal void Redraw()
{
Invalidate();
}

#endregion P/Invoke Function

#region Override

protected override void OnSelectionChanged(EventArgs e)
{
Redraw();

base.OnSelectionChanged(e);
}

protected override void OnRowPostPaint(DataGridViewRowPostPaintEventArgs e)
{
try
{
var rectangle = new Rectangle(e.RowBounds.Location.X, Convert.ToInt32(
e.RowBounds.Location.Y +
(e.RowBounds.Height - RowHeadersDefaultCellStyle.Font.Size)
/ 2 - 3), RowHeadersWidth - 4, e.RowBounds.Height);

TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(),
RowHeadersDefaultCellStyle.Font, rectangle,
Properties.Settings.Default.ListColor, TextFormatFlags.Right);
}

catch
{
}
}

protected override void OnSizeChanged(EventArgs e)
{
base.OnSizeChanged(e);

if (Parent != null)
{
foreach (DataGridViewColumn dgvc in Columns)
dgvc.Width = (Parent.ClientSize.Width - 60) / 2;
}
}

#endregion Override

internal int FirstSelectedRowIndex
{
get
{
if (SelectedRows.Count != 0)
return SelectedRows[0].Index;
return -1;
}
set
{
ClearSelection();
Rows[value].Selected = true;
}
}

internal void SelectPrevLine()
{
try
{
if (FirstSelectedRowIndex == 0)
return;

FirstSelectedRowIndex -= 1;

MakeSelectedLineToCenterScreen();
}
catch (Exception)
{
}
}

internal void SelectNextLine()
{
try
{
if (FirstSelectedRowIndex == Rows.Count - 1)
return;

FirstSelectedRowIndex += 1;

MakeSelectedLineToCenterScreen();
}
catch (Exception)
{
}
}

internal void MakeSelectedLineToCenterScreen()
{
try
{
FirstDisplayedScrollingRowIndex = SelectedRows[0].Index - (DisplayedRowCount(false) / 2);
}
catch (Exception)
{
if (!SelectedRows[0].Displayed)
FirstDisplayedScrollingRowIndex = SelectedRows[0].Index;
}
}

internal void MarkCurrentLine()
{
Rows[FirstSelectedRowIndex].ErrorText = "Marked";
}

internal void ClearCurrentLineMark()
{
Rows[FirstSelectedRowIndex].ErrorText = "";
}

internal void ClearAllMarks()
{
foreach (DataRow row in Rows)
{
row.ClearErrors();
}
}

internal void GotoPrevMarkedLine()
{
int start = FirstSelectedRowIndex - 1;
if (start < 0)
start = 0;

for (int i = start; i >= 0; i--)
{
if (!String.IsNullOrEmpty(Rows[i].ErrorText))
{
FirstSelectedRowIndex = i;
MakeSelectedLineToCenterScreen();
return;
}
}
}

internal void GotoNextMarkedLine()
{
int start = FirstSelectedRowIndex + 1;
if (start >= Rows.Count)
start = Rows.Count - 1;

for (int i = start; i < Rows.Count; i++)
{
if (!String.IsNullOrEmpty(Rows[i].ErrorText))
{
FirstSelectedRowIndex = i;
MakeSelectedLineToCenterScreen();
return;
}
}
}
}
}
152 changes: 152 additions & 0 deletions Script Text Editor/Controls/TextBoxEx.cs
@@ -0,0 +1,152 @@
/*TextBox with user-defined background Image
*
* Usage:
* Add the following code to your Form.
*
const int WM_CTLCOLOREDIT = 0x0133;
const int TRANSPARENT = 0x1;
const int NULL_BRUSH = 0x5;
[DllImport("gdi32")]
private static extern int SetBkMode(IntPtr hdc, int bkMode);
[DllImport("gdi32")]
private static extern int SetTextColor(IntPtr hdc, int color);
[DllImport("gdi32")]
private static extern IntPtr GetStockObject(int fnobject);
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_CTLCOLOREDIT && m.LParam == textBox1.Handle)
{
SetBkMode(m.WParam, TRANSPARENT);
m.Result = GetStockObject(NULL_BRUSH);
return;
}
else base.WndProc(ref m);
}
*/

using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace Script_Text_Editor.Controls
{
internal class TextBoxEx : TextBox
{
private const int WM_KEYDOWN = 0x0100;
private const int WM_HSCROLL = 0x0114;
private const int WM_VSCROLL = 0x0115;
private const int WM_MOUSEWHEEL = 0x020A;

private const int WM_ERASEBKGND = 0x0014;

public TextBoxEx()
{
SetStyle(ControlStyles.DoubleBuffer, true);
}

public Image BackImage { get; set; }

public new string Text
{
get { return base.Text; }
set
{
base.Text = value;
base.SelectionStart = Utilities.SelectTextBox(value)[0];
base.SelectionLength = Utilities.SelectTextBox(value)[1];
}
}

protected override void OnTextChanged(EventArgs e)
{
SetBackImage();
Invalidate();
base.OnTextChanged(e);
}

protected override void OnLostFocus(EventArgs e)
{
Invalidate();
base.OnLostFocus(e);
}

protected override void OnSizeChanged(EventArgs e)
{
SetBackImage();
base.OnSizeChanged(e);
}

public void SetBackImage()
{
try
{
using (Bitmap bitmap = (new Bitmap(Parent.BackgroundImage, Parent.ClientSize)).Clone(
new Rectangle(
Location.X,
Location.Y,
Size.Width,
Size.Height),
PixelFormat.Format32bppPArgb))
{
var temp = new Bitmap(Size.Width, Size.Height);
Graphics g = Graphics.FromImage(temp);
g.DrawImage(bitmap, 0, 0);

g.FillRectangle(new SolidBrush(Color.FromArgb(173, Color.White)),
new Rectangle(0, 0, temp.Width, temp.Height));
BackImage = temp;
}
}
catch
{
return;
}
}

protected void OnEraseBkgnd(Graphics gs)
{
if (BackImage != null)
gs.DrawImage(BackImage, 0, 0);
else
gs.FillRectangle(Brushes.White, 0, 0, Width, Height);
gs.Dispose();
}

protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
Invalidate();
return base.ProcessCmdKey(ref msg, keyData);
}

[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true,
CallingConvention = CallingConvention.Winapi)]
internal static extern bool LockWindowUpdate(IntPtr hWndLock);

protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case WM_HSCROLL:
case WM_VSCROLL:
case WM_MOUSEWHEEL:
Invalidate();
break;

case WM_ERASEBKGND:
OnEraseBkgnd(Graphics.FromHdc(m.WParam));
m.Result = (IntPtr)1;
break;

default:
base.WndProc(ref m);
break;
}
}
}
}

0 comments on commit 2ba49a5

Please sign in to comment.