using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.Runtime.InteropServices;
namespace WindowsFormsApplication2
{
public partial class TextBoxEx : TextBox
{
private struct RECT
{
public int Left;
public int Top;
public int Right;
public int Bottom;
};
[DllImport("user32.dll ", CharSet = CharSet.Auto)]
private static extern int SendMessage(IntPtr hwnd,int wMsg,int wParam,ref int lParam);
[DllImport("user32.dll ", CharSet = CharSet.Auto)]
private static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, ref RECT lParam);
public TextBoxEx()
{
}
private bool m_VerticalMiddle;
public bool VerticalMiddle
{
get { return m_VerticalMiddle; }
set { m_VerticalMiddle = value; }
}
RECT rc;
int nLines;
private void TextBoxEx_Layout(object sender, LayoutEventArgs e)
{
//SetVCenterText();
}
private void TextBoxEx_TextChanged(object sender, EventArgs e)
{
//long i=SendMessage(Handle,,0,0);
long i;
if (nLines!=i)
{
//SetVCenterText();
nLines = Lines.Length;
}
}
private void SetVCenterText()
{
if (!this.Multiline)
{
return;
}
SizeF sz;
Graphics g = this.CreateGraphics();
sz = g.MeasureString(Text, Font, this.Size);
if (sz.Height==0)
{
sz = g.MeasureString("H", Font, this.Size);
}
RECT rect = rc;
rect.Top =Convert.ToInt32( (this.ClientRectangle.Height - sz.Height)/ 2 - 2);
rect.Bottom = this.ClientRectangle.Bottom;
rect.Left = 1; //this.ClientRectangle.Left;
rect.Right = this.ClientRectangle.Right - 1;
if (rect.Top<1)
{
return;
}
SendMessage(Handle,EM_SETRECTNP,0&,rect)
}
//private Const EM_GETRECT = &HB2;
//private Const EM_SETRECTNP = &HB4;
//private Const EM_GETLINECOUNT = &HBA;
//private const int WM_PAINT = &HF;
}
}