PopupControlHost.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871
  1. 
  2. using System;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Runtime.InteropServices;
  6. using System.Security.Permissions;
  7. using System.Windows.Forms;
  8. using System.Windows.Forms.VisualStyles;
  9. namespace Dongke.WinForm.Controls
  10. {
  11. /// <summary>
  12. /// 弹出控件
  13. /// </summary>
  14. [ToolboxItem(false)]
  15. public class PopupControlHost : ToolStripDropDown
  16. {
  17. #region 事件声明
  18. #region SelectedOK
  19. /// <summary>
  20. /// 当确认选择项时发生。
  21. /// </summary>
  22. private static readonly object EventSelectedOK = new object();
  23. /// <summary>
  24. /// 当确认选择项时发生。
  25. /// </summary>
  26. [Description("当确认选择项时发生。"), Category("CustomerEx")]
  27. internal event EventHandler SelectedOK
  28. {
  29. add
  30. {
  31. base.Events.AddHandler(EventSelectedOK, value);
  32. }
  33. remove
  34. {
  35. base.Events.AddHandler(EventSelectedOK, value);
  36. }
  37. }
  38. /// <summary>
  39. /// 引发 SelectedOK 事件
  40. /// </summary>
  41. /// <param name="e">包含事件数据的 EventArgs</param>
  42. protected virtual void OnSelectedOK(EventArgs e)
  43. {
  44. EventHandler eventHandler = (EventHandler)base.Events[EventSelectedOK];
  45. if (eventHandler != null)
  46. {
  47. eventHandler(this, e);
  48. }
  49. }
  50. #endregion
  51. #region SelectedCancel
  52. /// <summary>
  53. /// 当取消选择项时发生。
  54. /// </summary>
  55. private static readonly object EventSelectedCancel = new object();
  56. /// <summary>
  57. /// 当取消选择项时发生。
  58. /// </summary>
  59. [Description("当取消选择项时发生。"), Category("CustomerEx")]
  60. internal event EventHandler SelectedCancel
  61. {
  62. add
  63. {
  64. base.Events.AddHandler(EventSelectedCancel, value);
  65. }
  66. remove
  67. {
  68. base.Events.AddHandler(EventSelectedCancel, value);
  69. }
  70. }
  71. /// <summary>
  72. /// 引发 SelectedCancel 事件
  73. /// </summary>
  74. /// <param name="e">包含事件数据的 EventArgs</param>
  75. protected virtual void OnSelectedCancel(EventArgs e)
  76. {
  77. EventHandler eventHandler = (EventHandler)base.Events[EventSelectedCancel];
  78. if (eventHandler != null)
  79. {
  80. eventHandler(this, e);
  81. }
  82. }
  83. #endregion
  84. #endregion
  85. #region 常量
  86. //private static readonly Size GRIP_SIZE = new Size(0x10, 0x10);
  87. #endregion
  88. #region 成员变量
  89. /// <summary>
  90. /// 弹出控件的父控件
  91. /// </summary>
  92. private Control _owner = null;
  93. /// <summary>
  94. /// 承载自定义控件或 Windows 窗体控件。
  95. /// </summary>
  96. private ToolStripControlHost _controlHost = null;
  97. /// <summary>
  98. /// 弹出的内容
  99. /// </summary>
  100. private Control _popupControl = null;
  101. /// <summary>
  102. /// 是否改变控件形状
  103. /// </summary>
  104. private bool _changeRegion = false;
  105. /// <summary>
  106. /// 显示时是否获得焦点
  107. /// </summary>
  108. private bool _focusOnOpen = true;
  109. /// <summary>
  110. /// 是否接受alt键输入
  111. /// </summary>
  112. private bool _acceptAlt = true;
  113. /// <summary>
  114. /// 能否改变控件大小
  115. /// </summary>
  116. private bool _canResize = true;
  117. /// <summary>
  118. /// 控件是否打开
  119. /// </summary>
  120. private bool _isOpen = false;
  121. private PopupControlHost _ownerPopup;
  122. private PopupControlHost _childPopup;
  123. private bool _resizableTop = false;
  124. private bool _resizableLeft = false;
  125. //private Color _borderColor = Color.FromArgb(23, 169, 254);
  126. //private VisualStyleRenderer sizeGripRenderer;
  127. private bool _sizeHasChanged = false;
  128. #endregion
  129. #region 构造函数
  130. /// <summary>
  131. /// 弹出控件
  132. /// </summary>
  133. public PopupControlHost(Control owner)
  134. {
  135. this.DoubleBuffered = true;
  136. this.ResizeRedraw = true;
  137. this.AutoSize = false;
  138. this.Padding = Padding.Empty;
  139. this.Margin = Padding.Empty;
  140. this.ResizeRedraw = true;
  141. this.SetOwner(owner);
  142. }
  143. #endregion
  144. #region 属性
  145. /// <summary>
  146. /// 获取弹出的内容
  147. /// </summary>
  148. public Control Content
  149. {
  150. get
  151. {
  152. return this._popupControl;
  153. }
  154. set
  155. {
  156. if (this._popupControl != value)
  157. {
  158. this.CreateHost(value);
  159. }
  160. }
  161. }
  162. /// <summary>
  163. /// 获取弹出的内容
  164. /// </summary>
  165. public ToolStripControlHost Host
  166. {
  167. get
  168. {
  169. return this._controlHost;
  170. }
  171. }
  172. /// <summary>
  173. /// 获取或设置一个值,该值指示弹出控件是否是异形控件。
  174. /// </summary>
  175. public bool ChangeRegion
  176. {
  177. get
  178. {
  179. return this._changeRegion;
  180. }
  181. set
  182. {
  183. this._changeRegion = value;
  184. this.UpdateRegion();
  185. }
  186. }
  187. /// <summary>
  188. /// 获取或设置一个值,该值指示控件显示时,是否获得焦点。
  189. /// </summary>
  190. public bool FocusOnOpen
  191. {
  192. get
  193. {
  194. return this._focusOnOpen;
  195. }
  196. set
  197. {
  198. this._focusOnOpen = value;
  199. }
  200. }
  201. /// <summary>
  202. /// 获取或设置一个值,该值指示控件是否接受Alt输入。
  203. /// </summary>
  204. public bool AcceptAlt
  205. {
  206. get
  207. {
  208. return this._acceptAlt;
  209. }
  210. set
  211. {
  212. this._acceptAlt = value;
  213. }
  214. }
  215. /// <summary>
  216. /// 获取或设置一个值,该值指示用户能否改变控件大小。
  217. /// </summary>
  218. public bool CanResize
  219. {
  220. get
  221. {
  222. return this._canResize;
  223. }
  224. set
  225. {
  226. this._canResize = value;
  227. }
  228. }
  229. ///// <summary>
  230. ///// 获取或设置一个值,该值指示控件边框颜色。
  231. ///// </summary>
  232. //public Color BorderColor
  233. //{
  234. // get
  235. // {
  236. // return this._borderColor;
  237. // }
  238. // set
  239. // {
  240. // this._borderColor = value;
  241. // }
  242. //}
  243. /// <summary>
  244. /// 获取一个值,该值指示控件是否打开状态。
  245. /// </summary>
  246. public bool IsOpen
  247. {
  248. get
  249. {
  250. return this._isOpen;
  251. }
  252. }
  253. #endregion
  254. #region 重写事件
  255. /// <summary>
  256. /// 控件正打开时
  257. /// </summary>
  258. /// <param name="e"></param>
  259. protected override void OnOpening(CancelEventArgs e)
  260. {
  261. if (this._popupControl.IsDisposed ||
  262. this._popupControl.Disposing)
  263. {
  264. e.Cancel = true;
  265. base.OnOpening(e);
  266. return;
  267. }
  268. //UpdateRegion();
  269. base.OnOpening(e);
  270. }
  271. /// <summary>
  272. /// 在打开控件时
  273. /// </summary>
  274. /// <param name="e"></param>
  275. protected override void OnOpened(EventArgs e)
  276. {
  277. if (this._focusOnOpen)
  278. {
  279. if (this._popupControl is IPopupControl)
  280. {
  281. (this._popupControl as IPopupControl).FocusOnShown();
  282. }
  283. else
  284. {
  285. this._popupControl.Focus();
  286. }
  287. }
  288. this._isOpen = true;
  289. base.OnOpened(e);
  290. }
  291. /// <summary>
  292. /// 控件正关闭时
  293. /// </summary>
  294. /// <param name="e"></param>
  295. protected override void OnClosing(ToolStripDropDownClosingEventArgs e)
  296. {
  297. base.OnClosing(e);
  298. }
  299. /// <summary>
  300. /// 在关闭控件时
  301. /// </summary>
  302. /// <param name="e"></param>
  303. protected override void OnClosed(ToolStripDropDownClosedEventArgs e)
  304. {
  305. this._isOpen = false;
  306. base.OnClosed(e);
  307. }
  308. /// <summary>
  309. /// 大小改变时
  310. /// </summary>
  311. /// <param name="e"></param>
  312. protected override void OnSizeChanged(EventArgs e)
  313. {
  314. base.OnSizeChanged(e);
  315. if (this._controlHost != null)
  316. {
  317. this._controlHost.Size = this.Size - this.Padding.Size;
  318. }
  319. if (this._isOpen)
  320. {
  321. this._sizeHasChanged = true;
  322. }
  323. }
  324. /// <summary>
  325. /// 绘制控件时
  326. /// </summary>
  327. /// <param name="e"></param>
  328. protected override void OnPaint(PaintEventArgs e)
  329. {
  330. base.OnPaint(e);
  331. }
  332. #endregion
  333. #region 重写方法
  334. /// <summary>
  335. /// 获取新窗口的参数
  336. /// </summary>
  337. protected override CreateParams CreateParams
  338. {
  339. [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
  340. get
  341. {
  342. CreateParams cp = base.CreateParams;
  343. cp.ExStyle |= NativeMethods.WS_EX_NOACTIVATE;
  344. //cp.ExStyle |= 5242880;
  345. //cp.ExStyle &= -12289;
  346. return cp;
  347. }
  348. }
  349. /// <summary>
  350. /// 系统消息处理
  351. /// </summary>
  352. /// <param name="m"></param>
  353. [SecurityPermission(SecurityAction.LinkDemand,
  354. Flags = SecurityPermissionFlag.UnmanagedCode)]
  355. protected override void WndProc(ref Message m)
  356. {
  357. if (this.ProcessGrip(ref m))
  358. {
  359. return;
  360. }
  361. base.WndProc(ref m);
  362. }
  363. /// <summary>
  364. /// 处理对话框键
  365. /// </summary>
  366. /// <param name="keyData"></param>
  367. /// <returns></returns>
  368. [UIPermission(SecurityAction.LinkDemand, Window = UIPermissionWindow.AllWindows)]
  369. protected override bool ProcessDialogKey(Keys keyData)
  370. {
  371. //if (this._acceptAlt && ((keyData & Keys.Alt) == Keys.Alt))
  372. //{
  373. // if ((keyData & Keys.F4) != Keys.F4)
  374. // {
  375. // return false;
  376. // }
  377. // else
  378. // {
  379. // this.Close();
  380. // }
  381. //}
  382. // ESC
  383. if ((keyData & Keys.KeyCode) == Keys.Escape)
  384. {
  385. this.OnSelectedCancel(EventArgs.Empty);
  386. return base.ProcessDialogKey(Keys.Escape);
  387. //bool result = base.ProcessDialogKey(Keys.Escape);
  388. //if (result)
  389. //{
  390. // this.OnSelectedCancel(EventArgs.Empty);
  391. //}
  392. //return result;
  393. //return true;
  394. }
  395. // Enter
  396. if ((keyData & Keys.KeyCode) == Keys.Enter)
  397. {
  398. this.OnSelectedOK(EventArgs.Empty);
  399. return base.ProcessDialogKey(Keys.Escape);
  400. //bool result = base.ProcessDialogKey(Keys.Escape);
  401. //if (result)
  402. //{
  403. // this.OnSelectedOK(EventArgs.Empty);
  404. //}
  405. //return result;
  406. //return true;
  407. }
  408. return base.ProcessDialogKey(keyData);
  409. }
  410. #endregion
  411. #region 事件处理
  412. /// <summary>
  413. /// 控件显示范围改变
  414. /// </summary>
  415. /// <param name="sender"></param>
  416. /// <param name="e"></param>
  417. private void PopupControlRegionChanged(object sender, EventArgs e)
  418. {
  419. this.UpdateRegion();
  420. }
  421. #endregion
  422. #region 公有方法
  423. /// <summary>
  424. /// 显示控件
  425. /// </summary>
  426. public new void Show()
  427. {
  428. this.ShowInternal();
  429. }
  430. /// <summary>
  431. /// 显示控件
  432. /// </summary>
  433. /// <param name="control"></param>
  434. public void Show(Control control)
  435. {
  436. this.SetOwner(control);
  437. this.ShowInternal();
  438. }
  439. #endregion
  440. #region 保护方法
  441. /// <summary>
  442. /// 更新空间显示范围
  443. /// </summary>
  444. protected virtual void UpdateRegion()
  445. {
  446. if (!this._changeRegion)
  447. {
  448. return;
  449. }
  450. if (base.Region != null)
  451. {
  452. base.Region.Dispose();
  453. base.Region = null;
  454. }
  455. if (this._popupControl.Region != null)
  456. {
  457. base.Region = this._popupControl.Region.Clone();
  458. }
  459. }
  460. #endregion
  461. #region 私有方法
  462. /// <summary>
  463. /// 显示控件
  464. /// </summary>
  465. private void ShowInternal()
  466. {
  467. if (this._owner == null)
  468. {
  469. return;
  470. }
  471. if (this._canResize && !this._changeRegion)
  472. {
  473. this.Padding = new Padding(1, 1, 1, 3);
  474. }
  475. else if (!this._changeRegion)
  476. {
  477. this.Padding = new Padding(1);
  478. }
  479. else
  480. {
  481. this.Padding = Padding.Empty;
  482. }
  483. Size s = this._popupControl.Size + this.Padding.Size;
  484. if (!this._sizeHasChanged && this._owner != null)
  485. {
  486. s.Width = this._owner.Width;
  487. }
  488. this.Size = s;
  489. base.Show(this._owner, 0, this._owner.Height);
  490. }
  491. /// <summary>
  492. /// 设定Owner
  493. /// </summary>
  494. /// <param name="owner"></param>
  495. private void SetOwner(Control owner)
  496. {
  497. if (owner == null)
  498. {
  499. return;
  500. }
  501. this._owner = owner;
  502. this.Font = owner.Font;
  503. this.SetOwnerItem(owner);
  504. }
  505. /// <summary>
  506. /// 设定OwnerItem
  507. /// </summary>
  508. /// <param name="owner"></param>
  509. private void SetOwnerItem(Control owner)
  510. {
  511. if (owner == null)
  512. {
  513. return;
  514. }
  515. if (owner is PopupControlHost)
  516. {
  517. PopupControlHost popupControl = owner as PopupControlHost;
  518. this._ownerPopup = popupControl;
  519. this._ownerPopup._childPopup = this;
  520. this.OwnerItem = popupControl.Items[0];
  521. return;
  522. }
  523. if (owner.Parent != null)
  524. {
  525. this.SetOwnerItem(owner.Parent);
  526. }
  527. }
  528. /// <summary>
  529. ///
  530. /// </summary>
  531. /// <param name="control"></param>
  532. private void CreateHost(Control control)
  533. {
  534. if (this._controlHost != null)
  535. {
  536. this._controlHost.Dispose();
  537. }
  538. this._popupControl = control;
  539. if (control == null)
  540. {
  541. //throw new ArgumentException("control");
  542. return;
  543. }
  544. this._controlHost = new ToolStripControlHost(control, "popupControlHost");
  545. this._controlHost.Font = this.Font;
  546. this._controlHost.AutoSize = false;
  547. this._controlHost.Padding = Padding.Empty;
  548. this._controlHost.Margin = Padding.Empty;
  549. Size maxSize = new Size(500, 500);
  550. Size minSize = new Size(5, 5);
  551. if (control.MaximumSize.Width > 0 &&
  552. maxSize.Width > control.MaximumSize.Width)
  553. {
  554. maxSize.Width = control.MaximumSize.Width;
  555. }
  556. if (control.MaximumSize.Height > 0 &&
  557. maxSize.Height > control.MaximumSize.Height)
  558. {
  559. maxSize.Height = control.MaximumSize.Height;
  560. }
  561. if (minSize.Width < control.MinimumSize.Width)
  562. {
  563. minSize.Width = control.MinimumSize.Width;
  564. }
  565. if (minSize.Height < control.MinimumSize.Height)
  566. {
  567. minSize.Height = control.MinimumSize.Height;
  568. }
  569. this.MaximumSize = maxSize;
  570. this.MinimumSize = minSize;
  571. base.Items.Add(this._controlHost);
  572. this._popupControl.RegionChanged += new EventHandler(PopupControlRegionChanged);
  573. this.UpdateRegion();
  574. }
  575. /// <summary>
  576. ///
  577. /// </summary>
  578. /// <param name="m"></param>
  579. /// <returns></returns>
  580. [SecurityPermission(SecurityAction.LinkDemand,
  581. Flags = SecurityPermissionFlag.UnmanagedCode)]
  582. private bool ProcessGrip(ref Message m)
  583. {
  584. //if (m.Msg == NativeMethods.WM_NCACTIVATE &&
  585. // m.WParam != IntPtr.Zero &&
  586. // this._childPopup != null &&
  587. // this._childPopup.Visible)
  588. //{
  589. // this._childPopup.Hide();
  590. //}
  591. if (this._canResize && !this._changeRegion)
  592. {
  593. if (m.Msg == NativeMethods.WM_NCHITTEST)
  594. {
  595. return this.OnNcHitTest(ref m);
  596. }
  597. if (m.Msg == NativeMethods.WM_GETMINMAXINFO)
  598. {
  599. return this.OnGetMinMaxInfo(ref m);
  600. }
  601. }
  602. return false;
  603. }
  604. /// <summary>
  605. /// 改变大小的范围
  606. /// </summary>
  607. /// <param name="m"></param>
  608. /// <returns></returns>
  609. [SecurityPermission(SecurityAction.LinkDemand,
  610. Flags = SecurityPermissionFlag.UnmanagedCode)]
  611. private bool OnGetMinMaxInfo(ref Message m)
  612. {
  613. NativeMethods.MINMAXINFO minmax =
  614. (NativeMethods.MINMAXINFO)Marshal.PtrToStructure(
  615. m.LParam, typeof(NativeMethods.MINMAXINFO));
  616. minmax.maxTrackSize = this.MaximumSize;
  617. minmax.minTrackSize = this.MinimumSize;
  618. Marshal.StructureToPtr(minmax, m.LParam, false);
  619. return true;
  620. }
  621. /// <summary>
  622. ///
  623. /// </summary>
  624. /// <param name="m"></param>
  625. /// <returns></returns>
  626. private bool OnNcHitTest(ref Message m)
  627. {
  628. Point location = this.PointToClient(new Point(
  629. NativeMethods.LOWORD(m.LParam), NativeMethods.HIWORD(m.LParam)));
  630. Rectangle gripRect = Rectangle.Empty;
  631. if (this._canResize && !this._changeRegion)
  632. {
  633. if (this._resizableLeft)
  634. {
  635. if (this._resizableTop)
  636. {
  637. gripRect = new Rectangle(0, 0, 6, 6);
  638. }
  639. else
  640. {
  641. gripRect = new Rectangle(
  642. 0,
  643. this.Height - 6,
  644. 6,
  645. 6);
  646. }
  647. }
  648. else
  649. {
  650. if (this._resizableTop)
  651. {
  652. gripRect = new Rectangle(this.Width - 6, 0, 6, 6);
  653. }
  654. else
  655. {
  656. gripRect = new Rectangle(
  657. this.Width - 6,
  658. this.Height - 6,
  659. 6,
  660. 6);
  661. }
  662. }
  663. }
  664. if (gripRect.Contains(location))
  665. {
  666. if (this._resizableLeft)
  667. {
  668. if (this._resizableTop)
  669. {
  670. m.Result = (IntPtr)NativeMethods.HTTOPLEFT;
  671. return true;
  672. }
  673. else
  674. {
  675. m.Result = (IntPtr)NativeMethods.HTBOTTOMLEFT;
  676. return true;
  677. }
  678. }
  679. else
  680. {
  681. if (this._resizableTop)
  682. {
  683. m.Result = (IntPtr)NativeMethods.HTTOPRIGHT;
  684. return true;
  685. }
  686. else
  687. {
  688. m.Result = (IntPtr)NativeMethods.HTBOTTOMRIGHT;
  689. return true;
  690. }
  691. }
  692. }
  693. else
  694. {
  695. Rectangle rectClient = this.ClientRectangle;
  696. if (location.X > rectClient.Right - 3 &&
  697. location.X <= rectClient.Right &&
  698. !this._resizableLeft)
  699. {
  700. m.Result = (IntPtr)NativeMethods.HTRIGHT;
  701. return true;
  702. }
  703. else if (location.Y > rectClient.Bottom - 3 &&
  704. location.Y <= rectClient.Bottom &&
  705. !this._resizableTop)
  706. {
  707. m.Result = (IntPtr)NativeMethods.HTBOTTOM;
  708. return true;
  709. }
  710. else if (location.X > -1 &&
  711. location.X < 3 &&
  712. this._resizableLeft)
  713. {
  714. m.Result = (IntPtr)NativeMethods.HTLEFT;
  715. return true;
  716. }
  717. else if (location.Y > -1 &&
  718. location.Y < 3 &&
  719. this._resizableTop)
  720. {
  721. m.Result = (IntPtr)NativeMethods.HTTOP;
  722. return true;
  723. }
  724. }
  725. return false;
  726. }
  727. #endregion
  728. /*
  729. private bool OnNcHitTest(ref Message m, bool contentControl)
  730. {
  731. int x = NativeMethods.LOWORD(m.LParam);
  732. int y = NativeMethods.HIWORD(m.LParam);
  733. Point clientLocation = PointToClient(new Point(x, y));
  734. GripBounds gripBouns = new GripBounds(contentControl ? content.ClientRectangle : ClientRectangle);
  735. IntPtr transparent = new IntPtr(NativeMethods.HTTRANSPARENT);
  736. if (resizableTop)
  737. {
  738. if (resizableRight && gripBouns.TopLeft.Contains(clientLocation))
  739. {
  740. m.Result = contentControl ? transparent : (IntPtr)NativeMethods.HTTOPLEFT;
  741. return true;
  742. }
  743. if (!resizableRight && gripBouns.TopRight.Contains(clientLocation))
  744. {
  745. m.Result = contentControl ? transparent : (IntPtr)NativeMethods.HTTOPRIGHT;
  746. return true;
  747. }
  748. if (gripBouns.Top.Contains(clientLocation))
  749. {
  750. m.Result = contentControl ? transparent : (IntPtr)NativeMethods.HTTOP;
  751. return true;
  752. }
  753. }
  754. else
  755. {
  756. if (resizableRight && gripBouns.BottomLeft.Contains(clientLocation))
  757. {
  758. m.Result = contentControl ? transparent : (IntPtr)NativeMethods.HTBOTTOMLEFT;
  759. return true;
  760. }
  761. if (!resizableRight && gripBouns.BottomRight.Contains(clientLocation))
  762. {
  763. m.Result = contentControl ? transparent : (IntPtr)NativeMethods.HTBOTTOMRIGHT;
  764. return true;
  765. }
  766. if (gripBouns.Bottom.Contains(clientLocation))
  767. {
  768. m.Result = contentControl ? transparent : (IntPtr)NativeMethods.HTBOTTOM;
  769. return true;
  770. }
  771. }
  772. if (resizableRight && gripBouns.Left.Contains(clientLocation))
  773. {
  774. m.Result = contentControl ? transparent : (IntPtr)NativeMethods.HTLEFT;
  775. return true;
  776. }
  777. if (!resizableRight && gripBouns.Right.Contains(clientLocation))
  778. {
  779. m.Result = contentControl ? transparent : (IntPtr)NativeMethods.HTRIGHT;
  780. return true;
  781. }
  782. return false;
  783. }
  784. private VS.VisualStyleRenderer sizeGripRenderer;
  785. /// <summary>
  786. /// Paints the size grip.
  787. /// </summary>
  788. /// <param name="e">The <see cref="System.Windows.Forms.PaintEventArgs" /> instance containing the event data.</param>
  789. public void PaintSizeGrip(PaintEventArgs e)
  790. {
  791. if (e == null || e.Graphics == null || !resizable)
  792. {
  793. return;
  794. }
  795. Size clientSize = content.ClientSize;
  796. if (Application.RenderWithVisualStyles)
  797. {
  798. if (this.sizeGripRenderer == null)
  799. {
  800. this.sizeGripRenderer = new VS.VisualStyleRenderer(VS.VisualStyleElement.Status.Gripper.Normal);
  801. }
  802. this.sizeGripRenderer.DrawBackground(e.Graphics, new Rectangle(clientSize.Width - 0x10, clientSize.Height - 0x10, 0x10, 0x10));
  803. }
  804. else
  805. {
  806. ControlPaint.DrawSizeGrip(e.Graphics, content.BackColor, clientSize.Width - 0x10, clientSize.Height - 0x10, 0x10, 0x10);
  807. }
  808. }
  809. */
  810. }
  811. }