以无边框形式绘制抓手

Vah*_*heh 5 .net c# user-interface winforms

所以我有一个无边框的形式,我需要它可以重新调整大小(通过点击4个边或角的任何一个).为了澄清,我希望我的表单像Windows 7中的默认便签一样无边界.

在此输入图像描述

我已经通过使用Julien Lebosquain在这篇文章中提供的代码来实现它(现在只在右下角):

调整右下角的无边框窗口大小

但是,我真的想在右下角显示拖动夹子图像.在他的帖子中,Julien提到了关于抓手的事情:

您可以初始化一个新的
VisualStyleRenderer(VisualStyleElement.Status.Gripper.Normal)并
使用它的PaintBackground()方法.

我不知道如何在我的表格中这样做.有人能指出我正确的方向吗?

谢谢.

Vah*_*heh 8

所以在这里读了一下之后:http://msdn.microsoft.com/en-us/library/system.windows.forms.visualstyles.visualstyleelement.status.gripper.normal.aspx,我有解决方案.

首先覆盖OnPaint()表单的事件.

   protected override void OnPaint(PaintEventArgs e) {
       base.OnPaint(e);
       DrawGripper(e);
   }
Run Code Online (Sandbox Code Playgroud)

以及绘图的方法.

   public void DrawGripper(PaintEventArgs e) {
       if (VisualStyleRenderer.IsElementDefined(
           VisualStyleElement.Status.Gripper.Normal)) {
           VisualStyleRenderer renderer = new VisualStyleRenderer(VisualStyleElement.Status.Gripper.Normal);
           Rectangle rectangle1 = new Rectangle((Width) - 18, (Height) - 20, 20, 20);
           renderer.DrawBackground(e.Graphics, rectangle1);
       }
   }
Run Code Online (Sandbox Code Playgroud)