- ak_wizard_src.zip
- UtilityLibrary.Designers
- UtilityLibrary.Win32.WindowsAPI
- UtilityLibrary
- AssemblyInfo.cs
- Collections
- Combos
- CommandBars
- Controls.resX
- DateTimeControls
- Dialogs
- Gantt Chart
- General
- licenses.licx
- Menus
- mssccprj.scc
- Notification
- OutlookBar
- Resources
- Controls.resX
- DragCursor.cur
- ImagesColorPicker.resX
- ImagesMenu.resX
- MenuControlImages.resX
- SortedListView.resX
- vssver.scc
- Serialization
- Smtp
- Strong Keys
- UtilityLibStrongKey.snk
- vssver.scc
- TreeListView
- UtilityLibrary.csproj
- UtilityLibrary.csproj.user
- UtilityLibrary.csproj.vspscc
- UtilityLibrary.suo
- vssver.scc
- WinControls
- Wizards
|
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using System.Diagnostics;
using UtilityLibrary.General;
using UtilityLibrary.Win32;
namespace UtilityLibrary.WinControls
{
// <summary>
/// Summary description for TextBoxEx.
/// </summary>
[ToolboxItem(true)]
[ToolboxBitmap(typeof(UtilityLibrary.WinControls.TextBoxEx), "UtilityLibrary.WinControls.TextBoxEx.bmp")]
public class TextBoxEx : System.Windows.Forms.TextBox
{
#region Class Variables
DrawState drawState = DrawState.Normal;
#endregion
#region Constructors
public TextBoxEx()
{
// Make sure we have the 3D look setting which is the one
// we are going to paint over
BorderStyle = BorderStyle.Fixed3D;
}
#endregion
#region Overrides
protected override void OnMouseEnter(EventArgs e)
{
// Set state to hot
base.OnMouseEnter(e);
drawState = DrawState.Hot;
Invalidate();
}
protected override void OnMouseLeave(EventArgs e)
{
// Set state to Normal
base.OnMouseLeave(e);
if ( !ContainsFocus )
{
drawState = DrawState.Normal;
Invalidate();
}
}
protected override void OnGotFocus(EventArgs e)
{
// Set state to Hot
base.OnGotFocus(e);
drawState = DrawState.Hot;
Invalidate();
}
protected override void OnLostFocus(EventArgs e)
{
// Set state to Normal
base.OnLostFocus(e);
drawState = DrawState.Normal;
Invalidate();
}
protected override void WndProc(ref Message m)
{
bool callBase = true;
switch(m.Msg)
{
case ((int)Msg.WM_PAINT):
{
// Let the edit control do its painting
base.WndProc(ref m);
// Now do our custom painting
DrawTextBoxState(Enabled?drawState:DrawState.Disable);
callBase = false;
}
break;
default:
break;
}
if ( callBase )
base.WndProc(ref m);
}
#endregion
#region Properties
public new BorderStyle BorderStyle
{
// Don't let the user change this property
// because we are counting on the extra pixels
// than the 3D look adds to the edit control size
// to do our painting
get { return base.BorderStyle; }
set
{
if ( value != BorderStyle.Fixed3D )
{
// Throw an exception to tell the user
// that this property needs to be Fixe3D if
// he is to use this class
string message = "BorderStyle can only be Fixed3D for this class";
ArgumentException argumentException = new ArgumentException("BorderStyle", message);
throw(argumentException);
}
else
base.BorderStyle = value;
}
}
#endregion
#region Implementation
void DrawTextBoxState(DrawState drawState)
{
// Get window area
Win32.RECT rc = new Win32.RECT();
WindowsAPI.GetWindowRect(Handle, ref rc);
// Convert to Rectangle
Rectangle rect = new Rectangle(0, 0, rc.right - rc.left, rc.bottom - rc.top);
// Create DC for the whole edit window instead of just for the client area
IntPtr hDC = WindowsAPI.GetWindowDC(Handle);
using (Graphics g = Graphics.FromHdc(hDC))
{
// This rectangle is always drawn for any state
using ( Pen windowPen = new Pen(SystemBrushes.Window) )
{
g.DrawRectangle(windowPen, rect.Left+1, rect.Top+1, rect.Width-3, rect.Height-3);
}
if ( drawState == DrawState.Normal )
{
// draw SystemColos.Window rectangle
using ( Pen windowPen = new Pen(SystemBrushes.Window) )
{
g.DrawRectangle(windowPen, rect.Left, rect.Top, rect.Width-1, rect.Height-1);
}
}
else if ( drawState == DrawState.Hot )
{
// draw highlighted rectangle
g.DrawRectangle(SystemPens.Highlight, rect.Left, rect.Top, rect.Width-1, rect.Height-1);
}
else if ( drawState == DrawState.Disable )
{
// draw highlighted rectangle
g.FillRectangle(SystemBrushes.Control, rect);
Size textSize = TextUtil.GetTextSize(g, Text, Font);
Point point = new Point(rect.Left+1, rect.Top + (rect.Height - textSize.Height)/2);
if ( PasswordChar != 0)
{
int length = Text.Length;
string currentText = new String(PasswordChar, length);
g.DrawString(currentText, Font, SystemBrushes.ControlDark, point);
}
else
g.DrawString(Text, Font, SystemBrushes.ControlDark, point);
}
}
// Release DC
WindowsAPI.ReleaseDC(Handle, hDC);
}
#endregion
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.