1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Drawing;
  6. using System.Drawing.Drawing2D;
  7. using System.Windows.Forms;
  8. using System.ComponentModel;
  9.  
  10. namespace ControlExs.ControlExs.TextBoxEx
  11. {
  12. public class QCTextBox : TextBox
  13. {
  14. #region Field
  15.  
  16. private QQControlState _state = QQControlState.Normal;
  17. private Font _defaultFont = new Font("微软雅黑", );
  18.  
  19. //当Text属性为空时编辑框内出现的提示文本
  20. private string _emptyTextTip;
  21. private Color _emptyTextTipColor = Color.DarkGray;
  22.  
  23. #endregion
  24.  
  25. #region Constructor
  26.  
  27. public QCTextBox()
  28. {
  29. SetStyles();
  30. this.Font = _defaultFont;
  31. //this.AutoSize = true;
  32. this.BorderStyle = BorderStyle.None;
  33. }
  34.  
  35. #endregion
  36.  
  37. #region Properites
  38.  
  39. [Description("当Text属性为空时编辑框内出现的提示文本")]
  40. public String EmptyTextTip
  41. {
  42. get { return _emptyTextTip; }
  43. set
  44. {
  45. if (_emptyTextTip != value)
  46. {
  47. _emptyTextTip = value;
  48. base.Invalidate();
  49. }
  50. }
  51. }
  52.  
  53. [Description("获取或设置EmptyTextTip的颜色")]
  54. public Color EmptyTextTipColor
  55. {
  56. get { return _emptyTextTipColor; }
  57. set
  58. {
  59. if (_emptyTextTipColor != value)
  60. {
  61. _emptyTextTipColor = value;
  62. base.Invalidate();
  63. }
  64. }
  65. }
  66.  
  67. private int _radius = ;
  68. [Description("获取或设置圆角弧度")]
  69. public int Radius
  70. {
  71. get { return _radius; }
  72. set {
  73. _radius = value;
  74. this.Invalidate();
  75. }
  76. }
  77.  
  78. [Description("获取或设置是否可自定义改变大小")]
  79. public bool CustomAutoSize
  80. {
  81. get { return this.AutoSize; }
  82. set { this.AutoSize = value; }
  83. }
  84.  
  85. #endregion
  86.  
  87. #region Override
  88.  
  89. protected override void OnMouseEnter(EventArgs e)
  90. {
  91. _state = QQControlState.Highlight;
  92. base.OnMouseEnter(e);
  93. }
  94.  
  95. protected override void OnMouseLeave(EventArgs e)
  96. {
  97. if (_state == QQControlState.Highlight && Focused)
  98. {
  99. _state = QQControlState.Focus;
  100. }
  101. else if (_state == QQControlState.Focus)
  102. {
  103. _state = QQControlState.Focus;
  104. }
  105. else
  106. {
  107. _state = QQControlState.Normal;
  108. }
  109. base.OnMouseLeave(e);
  110. }
  111.  
  112. protected override void OnMouseDown(MouseEventArgs mevent)
  113. {
  114. if (mevent.Button == MouseButtons.Left)
  115. {
  116. _state = QQControlState.Highlight;
  117. }
  118. base.OnMouseDown(mevent);
  119. }
  120.  
  121. protected override void OnMouseUp(MouseEventArgs mevent)
  122. {
  123. if (mevent.Button == MouseButtons.Left)
  124. {
  125. if (ClientRectangle.Contains(mevent.Location))
  126. {
  127. _state = QQControlState.Highlight;
  128. }
  129. else
  130. {
  131. _state = QQControlState.Focus;
  132. }
  133. }
  134. base.OnMouseUp(mevent);
  135. }
  136.  
  137. protected override void OnLostFocus(EventArgs e)
  138. {
  139. _state = QQControlState.Normal;
  140. base.OnLostFocus(e);
  141. }
  142.  
  143. protected override void OnEnabledChanged(EventArgs e)
  144. {
  145. if (Enabled)
  146. {
  147. _state = QQControlState.Normal;
  148. }
  149. else
  150. {
  151. _state = QQControlState.Disabled;
  152. }
  153. base.OnEnabledChanged(e);
  154. }
  155.  
  156. protected override void WndProc(ref Message m)
  157. {//TextBox是由系统进程绘制,重载OnPaint方法将不起作用
  158.  
  159. base.WndProc(ref m);
  160. if (m.Msg == Win32.WM_PAINT || m.Msg == Win32.WM_CTLCOLOREDIT)
  161. {
  162. WmPaint(ref m);
  163. }
  164. }
  165.  
  166. protected override void Dispose(bool disposing)
  167. {
  168. if (disposing)
  169. {
  170. if (_defaultFont != null)
  171. {
  172. _defaultFont.Dispose();
  173. }
  174. }
  175.  
  176. _defaultFont = null;
  177. base.Dispose(disposing);
  178. }
  179.  
  180. #endregion
  181.  
  182. #region Private
  183.  
  184. private void SetStyles()
  185. {
  186. // TextBox由系统绘制,不能设置 ControlStyles.UserPaint样式
  187. SetStyle(ControlStyles.AllPaintingInWmPaint, true);
  188. SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
  189. SetStyle(ControlStyles.ResizeRedraw, true);
  190. SetStyle(ControlStyles.SupportsTransparentBackColor, true);
  191. UpdateStyles();
  192. }
  193.  
  194. private void WmPaint(ref Message m)
  195. {
  196. Graphics g = Graphics.FromHwnd(base.Handle);
  197.  
  198. //g.SmoothingMode = SmoothingMode.AntiAlias;
  199. //去掉 TextBox 四个角
  200. g.InterpolationMode = InterpolationMode.HighQualityBicubic;
  201. g.SmoothingMode = SmoothingMode.AntiAlias;
  202. SetWindowRegion(this.Width, this.Height);
  203.  
  204. if (!Enabled)
  205. {
  206. _state = QQControlState.Disabled;
  207. }
  208.  
  209. switch (_state)
  210. {
  211. case QQControlState.Normal:
  212. DrawNormalTextBox(g);
  213. break;
  214. case QQControlState.Highlight:
  215. DrawHighLightTextBox(g);
  216. break;
  217. case QQControlState.Focus:
  218. DrawFocusTextBox(g);
  219. break;
  220. case QQControlState.Disabled:
  221. DrawDisabledTextBox(g);
  222. break;
  223. default:
  224. break;
  225. }
  226.  
  227. if (Text.Length == && !string.IsNullOrEmpty(EmptyTextTip) && !Focused)
  228. {
  229. TextRenderer.DrawText(g, EmptyTextTip, Font, ClientRectangle, EmptyTextTipColor, GetTextFormatFlags(TextAlign, RightToLeft == RightToLeft.Yes));
  230. }
  231. }
  232.  
  233. private void DrawNormalTextBox(Graphics g)
  234. {
  235. using (Pen borderPen = new Pen(Color.LightGray))
  236. {
  237. //g.DrawRectangle(borderPen, new Rectangle(ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width - 1, ClientRectangle.Height - 1));
  238. g.DrawPath(borderPen, DrawHelper.DrawRoundRect(ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width - , ClientRectangle.Height - , _radius));
  239. }
  240. }
  241.  
  242. private void DrawHighLightTextBox(Graphics g)
  243. {
  244. using (Pen highLightPen = new Pen(ColorTable.QQHighLightColor))
  245. {
  246. //Rectangle drawRect = new Rectangle(ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width - 1, ClientRectangle.Height - 1);
  247. //g.DrawRectangle(highLightPen, drawRect);
  248.  
  249. g.DrawPath(highLightPen, DrawHelper.DrawRoundRect(ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width - , ClientRectangle.Height - , _radius));
  250.  
  251. //InnerRect
  252. //drawRect.Inflate(-1, -1);
  253. //highLightPen.Color = ColorTable.QQHighLightInnerColor;
  254. //g.DrawRectangle(highLightPen, drawRect);
  255.  
  256. g.DrawPath(new Pen(ColorTable.QQHighLightInnerColor), DrawHelper.DrawRoundRect(ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width - , ClientRectangle.Height - , _radius));
  257. }
  258. }
  259.  
  260. private void DrawFocusTextBox(Graphics g)
  261. {
  262. using (Pen focusedBorderPen = new Pen(ColorTable.QQHighLightInnerColor))
  263. {
  264. //g.DrawRectangle(focusedBorderPen,new Rectangle(ClientRectangle.X,ClientRectangle.Y,ClientRectangle.Width - 1, ClientRectangle.Height - 1));
  265. g.DrawPath(focusedBorderPen, DrawHelper.DrawRoundRect(ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width - , ClientRectangle.Height - , _radius));
  266. }
  267. }
  268.  
  269. private void DrawDownTextBox(Graphics g)
  270. {
  271. using (Pen focusedBorderPen = new Pen(ColorTable.QQHighLightInnerColor))
  272. {
  273. //g.DrawRectangle(focusedBorderPen,new Rectangle(ClientRectangle.X,ClientRectangle.Y,ClientRectangle.Width - 1, ClientRectangle.Height - 1));
  274. g.DrawPath(focusedBorderPen, DrawHelper.DrawRoundRect(ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width - , ClientRectangle.Height - , _radius));
  275. }
  276. }
  277.  
  278. private void DrawDisabledTextBox(Graphics g)
  279. {
  280. using (Pen disabledPen = new Pen(SystemColors.ControlDark))
  281. {
  282. //g.DrawRectangle(disabledPen,new Rectangle( ClientRectangle.X,ClientRectangle.Y, ClientRectangle.Width - 1,ClientRectangle.Height - 1));
  283. g.DrawPath(disabledPen, DrawHelper.DrawRoundRect(ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width - , ClientRectangle.Height - , _radius));
  284. }
  285. }
  286.  
  287. private static TextFormatFlags GetTextFormatFlags(HorizontalAlignment alignment, bool rightToleft)
  288. {
  289. TextFormatFlags flags = TextFormatFlags.WordBreak |
  290. TextFormatFlags.SingleLine;
  291. if (rightToleft)
  292. {
  293. flags |= TextFormatFlags.RightToLeft | TextFormatFlags.Right;
  294. }
  295.  
  296. switch (alignment)
  297. {
  298. case HorizontalAlignment.Center:
  299. flags |= TextFormatFlags.VerticalCenter | TextFormatFlags.HorizontalCenter;
  300. break;
  301. case HorizontalAlignment.Left:
  302. flags |= TextFormatFlags.VerticalCenter | TextFormatFlags.Left;
  303. break;
  304. case HorizontalAlignment.Right:
  305. flags |= TextFormatFlags.VerticalCenter | TextFormatFlags.Right;
  306. break;
  307. }
  308. return flags;
  309. }
  310.  
  311. #endregion
  312.  
  313. public void SetWindowRegion(int width, int height)
  314. {
  315. System.Drawing.Drawing2D.GraphicsPath FormPath = new System.Drawing.Drawing2D.GraphicsPath();
  316. Rectangle rect = new Rectangle(, , width, height);
  317. FormPath = GetRoundedRectPath(rect, _radius);
  318. this.Region = new Region(FormPath);
  319. }
  320.  
  321. private GraphicsPath GetRoundedRectPath(Rectangle rect, int radius)
  322. {
  323. int diameter = radius;
  324. Rectangle arcRect = new Rectangle(rect.Location, new Size(diameter, diameter));
  325. GraphicsPath path = new GraphicsPath();
  326. // 左上角
  327. path.AddArc(arcRect, , );
  328. // 右上角
  329. arcRect.X = rect.Right - diameter;
  330. path.AddArc(arcRect, , );
  331. // 右下角
  332. arcRect.Y = rect.Bottom - diameter;
  333. path.AddArc(arcRect, , );
  334. // 左下角
  335. arcRect.X = rect.Left;
  336. path.AddArc(arcRect, , );
  337. path.CloseFigure();
  338. return path;
  339. }
  340. }
  341. }
  1. public enum QQControlState
  2. {
  3. /// <summary>
  4. /// 正常状态
  5. /// </summary>
  6. Normal = ,
  7. /// <summary>
  8. /// /鼠标进入
  9. /// </summary>
  10. Highlight = ,
  11. /// <summary>
  12. /// 鼠标按下
  13. /// </summary>
  14. Down = ,
  15. /// <summary>
  16. /// 获得焦点
  17. /// </summary>
  18. Focus = ,
  19. /// <summary>
  20. /// 控件禁止
  21. /// </summary>
  22. Disabled =
  23. }
  1. /// <summary>
  2. /// 实现仿QQ效果控件内部使用颜色表
  3. /// </summary>
  4. internal class ColorTable
  5. {
  6. public static Color QQBorderColor = Color.LightBlue; //LightBlue = Color.FromArgb(173, 216, 230)
  7. public static Color QQHighLightColor =RenderHelper.GetColor(QQBorderColor,,-,-,); //Color.FromArgb(110, 205, 253)
  8. public static Color QQHighLightInnerColor = RenderHelper.GetColor(QQBorderColor, , -, -, ); //Color.FromArgb(73, 172, 231);
  9. }
  1. internal class DrawHelper
  2. {
  3. public static GraphicsPath DrawRoundRect(int x, int y, int width, int height, int radius)
  4. {
  5. GraphicsPath gp = new GraphicsPath();
  6. gp.AddArc(x, y, radius, radius, , );
  7. gp.AddArc(width - radius, y, radius, radius, , );
  8. gp.AddArc(width - radius, height - radius, radius, radius, , );
  9. gp.AddArc(x, height - radius, radius, radius, , );
  10. gp.CloseAllFigures();
  11. return gp;
  12. }
  13.  
  14. /// <summary>
  15. /// 绘制圆角矩形
  16. /// </summary>
  17. /// <param name="rect">矩形</param>
  18. /// <param name="radius">弯曲程度(0-10),越大越弯曲</param>
  19. /// <returns></returns>
  20. public static GraphicsPath DrawRoundRect(Rectangle rect, int radius)
  21. {
  22. int x = rect.X;
  23. int y = rect.Y;
  24. int width = rect.Width;
  25. int height = rect.Height;
  26. return DrawRoundRect(x, y, width - , height - , radius);
  27. }
  28.  
  29. /// <summary>
  30. /// 得到两种颜色的过渡色(1代表开始色,100表示结束色)
  31. /// </summary>
  32. /// <param name="c">开始色</param>
  33. /// <param name="c2">结束色</param>
  34. /// <param name="value">需要获得的度</param>
  35. /// <returns></returns>
  36. public static Color GetIntermediateColor(Color c, Color c2, int value)
  37. {
  38. float pc = value * 1.0F / ;
  39.  
  40. int ca = c.A, cr = c.R, cg = c.G, cb = c.B;
  41. int c2a = c2.A, c2r = c2.R, c2g = c2.G, c2b = c2.B;
  42.  
  43. int a = (int)Math.Abs(ca + (ca - c2a) * pc);
  44. int r = (int)Math.Abs(cr - ((cr - c2r) * pc));
  45. int g = (int)Math.Abs(cg - ((cg - c2g) * pc));
  46. int b = (int)Math.Abs(cb - ((cb - c2b) * pc));
  47.  
  48. if (a > ) { a = ; }
  49. if (r > ) { r = ; }
  50. if (g > ) { g = ; }
  51. if (b > ) { b = ; }
  52.  
  53. return (Color.FromArgb(a, r, g, b));
  54. }
  55.  
  56. public static StringFormat StringFormatAlignment(ContentAlignment textalign)
  57. {
  58. StringFormat sf = new StringFormat();
  59. switch (textalign)
  60. {
  61. case ContentAlignment.TopLeft:
  62. case ContentAlignment.TopCenter:
  63. case ContentAlignment.TopRight:
  64. sf.LineAlignment = StringAlignment.Near;
  65. break;
  66. case ContentAlignment.MiddleLeft:
  67. case ContentAlignment.MiddleCenter:
  68. case ContentAlignment.MiddleRight:
  69. sf.LineAlignment = StringAlignment.Center;
  70. break;
  71. case ContentAlignment.BottomLeft:
  72. case ContentAlignment.BottomCenter:
  73. case ContentAlignment.BottomRight:
  74. sf.LineAlignment = StringAlignment.Far;
  75. break;
  76. }
  77. return sf;
  78. }
  79.  
  80. /// <summary>
  81. /// 绘图对像
  82. /// </summary>
  83. /// <param name="g">绘图对像</param>
  84. /// <param name="img">图片</param>
  85. /// <param name="r">绘置的图片大小、坐标</param>
  86. /// <param name="lr">绘置的图片边界</param>
  87. /// <param name="index">当前状态</param>
  88. /// <param name="Totalindex">状态总数</param>
  89. public static void DrawRect(Graphics g, Bitmap img, Rectangle r, Rectangle lr, int index, int Totalindex)
  90. {
  91. if (img == null) return;
  92. Rectangle r1, r2;
  93. int x = (index - ) * img.Width / Totalindex;
  94. int y = ;
  95. int x1 = r.Left;
  96. int y1 = r.Top;
  97.  
  98. if (r.Height > img.Height && r.Width <= img.Width / Totalindex)
  99. {
  100. r1 = new Rectangle(x, y, img.Width / Totalindex, lr.Top);
  101. r2 = new Rectangle(x1, y1, r.Width, lr.Top);
  102. g.DrawImage(img, r2, r1, GraphicsUnit.Pixel);
  103.  
  104. r1 = new Rectangle(x, y + lr.Top, img.Width / Totalindex, img.Height - lr.Top - lr.Bottom);
  105. r2 = new Rectangle(x1, y1 + lr.Top, r.Width, r.Height - lr.Top - lr.Bottom);
  106. if ((lr.Top + lr.Bottom) == ) r1.Height = r1.Height - ;
  107. g.DrawImage(img, r2, r1, GraphicsUnit.Pixel);
  108.  
  109. r1 = new Rectangle(x, y + img.Height - lr.Bottom, img.Width / Totalindex, lr.Bottom);
  110. r2 = new Rectangle(x1, y1 + r.Height - lr.Bottom, r.Width, lr.Bottom);
  111. g.DrawImage(img, r2, r1, GraphicsUnit.Pixel);
  112. }
  113. else
  114. if (r.Height <= img.Height && r.Width > img.Width / Totalindex)
  115. {
  116. r1 = new Rectangle(x, y, lr.Left, img.Height);
  117. r2 = new Rectangle(x1, y1, lr.Left, r.Height);
  118. g.DrawImage(img, r2, r1, GraphicsUnit.Pixel);
  119. r1 = new Rectangle(x + lr.Left, y, img.Width / Totalindex - lr.Left - lr.Right, img.Height);
  120. r2 = new Rectangle(x1 + lr.Left, y1, r.Width - lr.Left - lr.Right, r.Height);
  121. g.DrawImage(img, r2, r1, GraphicsUnit.Pixel);
  122. r1 = new Rectangle(x + img.Width / Totalindex - lr.Right, y, lr.Right, img.Height);
  123. r2 = new Rectangle(x1 + r.Width - lr.Right, y1, lr.Right, r.Height);
  124. g.DrawImage(img, r2, r1, GraphicsUnit.Pixel);
  125. }
  126. else
  127. if (r.Height <= img.Height && r.Width <= img.Width / Totalindex) { r1 = new Rectangle((index - ) * img.Width / Totalindex, , img.Width / Totalindex, img.Height); g.DrawImage(img, new Rectangle(x1, y1, r.Width, r.Height), r1, GraphicsUnit.Pixel); }
  128. else if (r.Height > img.Height && r.Width > img.Width / Totalindex)
  129. {
  130. //top-left
  131. r1 = new Rectangle(x, y, lr.Left, lr.Top);
  132. r2 = new Rectangle(x1, y1, lr.Left, lr.Top);
  133. g.DrawImage(img, r2, r1, GraphicsUnit.Pixel);
  134.  
  135. //top-bottom
  136. r1 = new Rectangle(x, y + img.Height - lr.Bottom, lr.Left, lr.Bottom);
  137. r2 = new Rectangle(x1, y1 + r.Height - lr.Bottom, lr.Left, lr.Bottom);
  138. g.DrawImage(img, r2, r1, GraphicsUnit.Pixel);
  139.  
  140. //left
  141. r1 = new Rectangle(x, y + lr.Top, lr.Left, img.Height - lr.Top - lr.Bottom);
  142. r2 = new Rectangle(x1, y1 + lr.Top, lr.Left, r.Height - lr.Top - lr.Bottom);
  143. g.DrawImage(img, r2, r1, GraphicsUnit.Pixel);
  144.  
  145. //top
  146. r1 = new Rectangle(x + lr.Left, y,
  147. img.Width / Totalindex - lr.Left - lr.Right, lr.Top);
  148. r2 = new Rectangle(x1 + lr.Left, y1,
  149. r.Width - lr.Left - lr.Right, lr.Top);
  150. g.DrawImage(img, r2, r1, GraphicsUnit.Pixel);
  151.  
  152. //right-top
  153. r1 = new Rectangle(x + img.Width / Totalindex - lr.Right, y, lr.Right, lr.Top);
  154. r2 = new Rectangle(x1 + r.Width - lr.Right, y1, lr.Right, lr.Top);
  155. g.DrawImage(img, r2, r1, GraphicsUnit.Pixel);
  156.  
  157. //Right
  158. r1 = new Rectangle(x + img.Width / Totalindex - lr.Right, y + lr.Top,
  159. lr.Right, img.Height - lr.Top - lr.Bottom);
  160. r2 = new Rectangle(x1 + r.Width - lr.Right, y1 + lr.Top,
  161. lr.Right, r.Height - lr.Top - lr.Bottom);
  162. g.DrawImage(img, r2, r1, GraphicsUnit.Pixel);
  163.  
  164. //right-bottom
  165. r1 = new Rectangle(x + img.Width / Totalindex - lr.Right, y + img.Height - lr.Bottom,
  166. lr.Right, lr.Bottom);
  167. r2 = new Rectangle(x1 + r.Width - lr.Right, y1 + r.Height - lr.Bottom,
  168. lr.Right, lr.Bottom);
  169. g.DrawImage(img, r2, r1, GraphicsUnit.Pixel);
  170.  
  171. //bottom
  172. r1 = new Rectangle(x + lr.Left, y + img.Height - lr.Bottom,
  173. img.Width / Totalindex - lr.Left - lr.Right, lr.Bottom);
  174. r2 = new Rectangle(x1 + lr.Left, y1 + r.Height - lr.Bottom,
  175. r.Width - lr.Left - lr.Right, lr.Bottom);
  176. g.DrawImage(img, r2, r1, GraphicsUnit.Pixel);
  177.  
  178. //Center
  179. r1 = new Rectangle(x + lr.Left, y + lr.Top,
  180. img.Width / Totalindex - lr.Left - lr.Right, img.Height - lr.Top - lr.Bottom);
  181. r2 = new Rectangle(x1 + lr.Left, y1 + lr.Top,
  182. r.Width - lr.Left - lr.Right, r.Height - lr.Top - lr.Bottom);
  183. g.DrawImage(img, r2, r1, GraphicsUnit.Pixel);
  184. }
  185. }
  186.  
  187. /// <summary>
  188. /// 绘图对像
  189. /// </summary>
  190. /// <param name="g"> 绘图对像</param>
  191. /// <param name="obj">图片对像</param>
  192. /// <param name="r">绘置的图片大小、坐标</param>
  193. /// <param name="index">当前状态</param>
  194. /// <param name="Totalindex">状态总数</param>
  195. public static void DrawRect(Graphics g, Bitmap img, Rectangle r, int index, int Totalindex)
  196. {
  197. if (img == null) return;
  198. int width = img.Width / Totalindex;
  199. int height = img.Height;
  200. Rectangle r1, r2;
  201. int x = (index - ) * width;
  202. int y = ;
  203. r1 = new Rectangle(x, y, width, height);
  204. r2 = new Rectangle(r.Left, r.Top, r.Width, r.Height);
  205. g.DrawImage(img, r2, r1, GraphicsUnit.Pixel);
  206. }
  207.  
  208. /// <summary>
  209. /// 得到要绘置的图片对像
  210. /// </summary>
  211. /// <param name="str">图像在程序集中的地址</param>
  212. /// <returns></returns>
  213. public static Bitmap GetResBitmap(string str)
  214. {
  215. Stream sm;
  216. sm = FindStream(str);
  217. if (sm == null) return null;
  218. return new Bitmap(sm);
  219. }
  220.  
  221. /// <summary>
  222. /// 得到图程序集中的图片对像
  223. /// </summary>
  224. /// <param name="str">图像在程序集中的地址</param>
  225. /// <returns></returns>
  226. private static Stream FindStream(string str)
  227. {
  228. Assembly assembly = Assembly.GetExecutingAssembly();
  229. string[] resNames = assembly.GetManifestResourceNames();
  230. foreach (string s in resNames)
  231. {
  232. if (s == str)
  233. {
  234. return assembly.GetManifestResourceStream(s);
  235. }
  236. }
  237. return null;
  238. }
  239.  
  240. }
  1. public class Win32
  2. {
  3. #region Window Const
  4.  
  5. public const int WM_KEYDOWN = 0x0100;
  6. public const int WM_KEYUP = 0x0101;
  7. public const int WM_CTLCOLOREDIT = 0x133;
  8. public const int WM_ERASEBKGND = 0x0014;
  9. public const int WM_LBUTTONDOWN = 0x0201;
  10. public const int WM_LBUTTONUP = 0x0202;
  11. public const int WM_LBUTTONDBLCLK = 0x0203;
  12. public const int WM_WINDOWPOSCHANGING = 0x46;
  13. public const int WM_PAINT = 0xF;
  14. public const int WM_CREATE = 0x0001;
  15. public const int WM_ACTIVATE = 0x0006;
  16. public const int WM_NCCREATE = 0x0081;
  17. public const int WM_NCCALCSIZE = 0x0083;
  18. public const int WM_NCPAINT = 0x0085;
  19. public const int WM_NCACTIVATE = 0x0086;
  20. public const int WM_NCLBUTTONDOWN = 0x00A1;
  21. public const int WM_NCLBUTTONUP = 0x00A2;
  22. public const int WM_NCLBUTTONDBLCLK = 0x00A3;
  23. public const int WM_NCMOUSEMOVE = 0x00A0;
  24.  
  25. public const int WM_NCHITTEST = 0x0084;
  26.  
  27. public const int HTLEFT = ;
  28. public const int HTRIGHT = ;
  29. public const int HTTOP = ;
  30. public const int HTTOPLEFT = ;
  31. public const int HTTOPRIGHT = ;
  32. public const int HTBOTTOM = ;
  33. public const int HTBOTTOMLEFT = 0x10;
  34. public const int HTBOTTOMRIGHT = ;
  35. public const int HTCAPTION = ;
  36. public const int HTCLIENT = ;
  37.  
  38. public const int WM_FALSE = ;
  39. public const int WM_TRUE = ;
  40.  
  41. #endregion
  42.  
  43. #region Public extern methods
  44.  
  45. [DllImport("gdi32.dll")]
  46. public static extern int CreateRoundRectRgn(int x1, int y1, int x2, int y2, int x3, int y3);
  47.  
  48. [DllImport("user32.dll")]
  49. public static extern int SetWindowRgn(IntPtr hwnd, int hRgn, Boolean bRedraw);
  50.  
  51. [DllImport("gdi32.dll", EntryPoint = "DeleteObject", CharSet = CharSet.Ansi)]
  52. public static extern int DeleteObject(int hObject);
  53.  
  54. [DllImport("user32.dll")]
  55. public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
  56.  
  57. [DllImport("user32.dll")]
  58. public static extern bool ReleaseCapture();
  59.  
  60. #endregion
  61. }

C# 自定义重绘TextBox的更多相关文章

  1. C# 自定义重绘DataGridView

    using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using Syste ...

  2. C# 自定义重绘TabControl

    using System.Drawing; using System.Windows.Forms; using System.Drawing.Drawing2D; using System.Runti ...

  3. Windows开发进阶之VC++中如何实现对话框的界面重绘

    技术:Windows 系统+Visual studio 2008   概述 应用程序界面是用户与应用程序之间的交互的桥梁和媒介,用户界面是应用程序中最重要的组成部分,也是最为直观的视觉体现.对用户而言 ...

  4. [DForm]我也来做自定义Winform之另类标题栏重绘

    据说得有楔子 按照惯例,先来几张样例图(注:为了展示窗口阴影效果,截图范围向外扩展了些,各位凭想象吧).                   还要来个序 其实,很多年没写过Winform了,前端时间在 ...

  5. c#winform自定义窗体,重绘标题栏,自定义控件学习

    c#winform自定义窗体,重绘标题栏 虽然现在都在说winform窗体太丑了,但是我也能尽量让桌面应用程序漂亮那么一点点话不多说,先上图 重绘标题栏先将原生窗体设置成无边框,FormBoderSt ...

  6. iOS 视图:重绘与UIScrollView(内容根据iOS编程编写)

    我们继续之前的 Hypnosister 应用,当用户开始触摸的时候,圆形的颜色会改变. 首先,在 JXHypnosisView 头文件中声明一个属性,用来表示圆形的颜色. #import " ...

  7. Android视图状态及重绘流程分析,带你一步步深入了解View(三)

    转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/17045157 在前面一篇文章中,我带着大家一起从源码的层面上分析了视图的绘制流程, ...

  8. (转)使用Custom Draw实现ListCtrl的重绘

    使用Custom Draw实现ListCtrl的重绘   common control 4.7版本介绍了一个新的特性叫做Custom Draw,这个名字显得模糊不清,让人有点摸不着头脑,而且MSDN里 ...

  9. 【转】【C#】C#重绘windows窗体标题栏和边框

    摘要 windows桌面应用程序都有标准的标题栏和边框,大部分程序也默认使用这些样式,一些对视觉效果要求较高的程序,如QQ, MSN,迅雷等聊天工具的样式则与传统的windows程序大不相同,其中迅雷 ...

随机推荐

  1. Python使用UUID库生成唯一ID(转)

    原文:http://www.cnblogs.com/dkblog/archive/2011/10/10/2205200.html 资料: Python官方Doc:<20.15. uuid — U ...

  2. Clean Code第三章<函数>

    1.方法不要写太长,如果太长,抽取其中的逻辑到新的方法中 bad good 2.函数只做一件事 如果做了多件事,要在方法名里体现出来 3.每个函数一个抽象层级 4.函数名可以长一些,比长注释好 5.方 ...

  3. Bash's ArithmeticExpression

    [Bash's ArithmeticExpression] let command: let a=17+23 echo "a = $a" # Prints a = 40 let a ...

  4. 树上的DP

    CF#196B http://codeforces.com/contest/338/problem/B 题意:在一颗树上,给m个点,求到所有m个点距离不超过d的点的个数,所有路径长度为1. 分析:问题 ...

  5. QTbaWidget控件几个例程 【worldsing笔记】

    Qt Creator自带的 QTabWidget控件几个例程 在Qt Windos版本安装后,在Example目录可以找到与QTabWidget相关的工程Demo,如果按默认安装的话他们分别是:   ...

  6. uestc oj 1217 The Battle of Chibi (dp + 离散化 + 树状数组)

    题目链接:http://acm.uestc.edu.cn/#/problem/show/1217 给你一个长为n的数组,问你有多少个长度严格为m的上升子序列. dp[i][j]表示以a[i]结尾长为j ...

  7. POJ2299Ultra-QuickSort (线段树和归并排序的解法)

    题目大意就是说帮你给一些(n个)乱序的数,让你求冒泡排序需要交换数的次数(n<=500000) 此题最初真不会做,我也只是在听了章爷的讲解后才慢慢明白过来的 首先介绍线段树的解法: 我们先将原数 ...

  8. Eclipse 安装对 Java 8 的支持

    Java 8 正式版今天已经发布了(详情),但最常用的 Java 开发工具 Eclipse 还没有正式发布对 Java 8 的支持.不过目前可以通过更新 JDT 来支持 Java 8.步骤如下: 菜单 ...

  9. [MySQL] 字符集和排序方式

    字符串类型 MySQL的字符串分为两大类: 1)二进制字符串:即一串字节序列,对字节的解释不涉及字符集,因此它没有字符集和排序方式的概念 2)非二进制字符串:由字符构成的序列,字符集用来解释字符串的内 ...

  10. 设置ul阴影效果和边框圆角

    ul.box {position: relative;z-index: 1; /* prevent shadows falling behind containers with backgrounds ...