从不同的约束调整无边界形式的大小? [英] Resizing borderless form from different constraints than far edges?

查看:164
本文介绍了从不同的约束调整无边界形式的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个没有任何类型边框的自定义表单。我正在绘制一些我自己的自定义边框,而不是扩展到窗体的边缘。相反,这个自定义绘制边框之外的任何东西都是透明的,通过使用窗体的透明属性。这使得表单的一小部分可以使用和可见。



我知道有很多解决方案可以实现,我已经找到了最好的适合这样做的方法。但是,这种方法假设用户将沿着窗体的远边缘指向鼠标。我需要限制它在不同的限制内进行反应(例如一个较小尺寸的rect)。



这是我发现的代码,它已经在下一个-edge约束:

 程序WMNCHitTest(var Message:TWMNCHitTest);消息WM_NCHITTEST; 

....

程序TForm1.WMNCHitTest(var Message:TWMNCHitTest);
const
EDGEDETECT = 7; //调整适合自己
var
deltaRect:TRect; //不是真的用作一个rect,只是一个方便的结构
begin
继承;
如果BorderStyle = bsNone然后开始
与消息,deltaRect do begin
左:= XPos - BoundsRect.Left;
权限:= BoundsRect.Right - XPos;
顶部:= YPos - BoundsRect.Top;
底部:= BoundsRect.Bottom - YPos;
if(Top< EDGEDETECT)和(Left< EDGEDETECT)然后
结果:= HTTOPLEFT
else if(Top< EDGEDETECT)和(右< EDGEDETECT)然后
结果:= HTTOPRIGHT
else if(Bottom< EDGEDETECT)和(Left< EDGEDETECT)然后
结果:= HTBOTTOMLEFT
else if(底部< EDGEDETECT)和(右< EDGEDETECT)然后
结果:= HTBOTTOMRIGHT
else if(Top< EDGEDETECT)then
结果:= HTTOP
else if(Left< EDGEDETECT)then
结果:= HTLEFT
else if底部< EDGEDETECT)然后
结果:= HTBOTTOM
else if(Right< EDGEDETECT)then
结果:= HTRIGHT
end;
结束
结束

我将如何改变这个界限来做出反应?例如,左右边缘应该将10个像素反映到窗体中。标准格式rect可以是(0,0,100,100),但是我希望以上方法在(10,3, 90,97)

解决方案

实际上,定义两个常量而不是唯一的 EDGEDETECT 由于
,您需要水平和垂直偏移量才能变化,并从头开始写入,但这里是一个快速补丁:

 程序TForm1.WMNCHitTest(var Message:TWMNCHitTest); 
const
EDGEDETECT = 17; //调整适合自己//< - 增加以适应外部偏移
var
deltaRect:TRect; //不是真的用作一个rect,只是一个方便的结构

OuterRect:TRect; //用作一个rect
begin
继承;
如果BorderStyle = bsNone然后开始
与消息,deltaRect do begin

..
else if(Right< EDGEDETECT)then
结果:= HTRIGHT ;
..

OuterRect:= BoundsRect; // patch
InflateRect(OuterRect,-10,-3);
如果不是PtInRect(OuterRect,SmallPointToPoint(Message.Pos))然后
Message.Result:= HTTRANSPARENT;

end;
结束
结束


I have a custom form which does not have any type of border. I'm drawing some custom borders of my own instead, which do not extend up to the far edges of the form. Instead, whatever's outside this custom drawn border is transparent, through the use of the form's transparent properties. This leaves a smaller portion of the form to be usable and visible.

I know there are tons of solutions out there to accomplish this, and I've already found the best suited method to do this. However, this method assumes that user will be pointing the mouse along the far edges of the form. I need to limit it to react from within different constraints (for example a smaller sized rect).

Here's the code I found which already works on a next-to-the-edge constraint:

procedure WMNCHitTest(var Message: TWMNCHitTest); message WM_NCHITTEST;

....

procedure TForm1.WMNCHitTest(var Message: TWMNCHitTest);
const
  EDGEDETECT = 7;  //adjust to suit yourself
var
  deltaRect: TRect;  //not really used as a rect, just a convenient structure
begin
  inherited;
  if BorderStyle = bsNone then begin
    with Message, deltaRect do begin
      Left := XPos - BoundsRect.Left;
      Right := BoundsRect.Right - XPos;
      Top := YPos - BoundsRect.Top;
      Bottom := BoundsRect.Bottom - YPos;
      if (Top<EDGEDETECT)and(Left<EDGEDETECT) then
        Result := HTTOPLEFT
      else if (Top<EDGEDETECT)and(Right<EDGEDETECT) then
        Result := HTTOPRIGHT
      else if (Bottom<EDGEDETECT)and(Left<EDGEDETECT) then
        Result := HTBOTTOMLEFT
      else if (Bottom<EDGEDETECT)and(Right<EDGEDETECT) then
        Result := HTBOTTOMRIGHT
      else if (Top<EDGEDETECT) then
        Result := HTTOP
      else if (Left<EDGEDETECT) then
        Result := HTLEFT
      else if (Bottom<EDGEDETECT) then
        Result := HTBOTTOM
      else if (Right<EDGEDETECT) then
        Result := HTRIGHT
    end; 
  end;
end;

How would I go about changing the bounds for this to react? For example, the left and right edges should react 10 pixels into the form. The standard form rect may be (0, 0, 100, 100) but I want this method above to work within bounds of (10, 3, 90, 97)

解决方案

Actually it would make sense to define two constants instead of the only EDGEDETECT since you require horizontal and vertical offsets to be different and write it from scratch, but here is a quick patch:

procedure TForm1.WMNCHitTest(var Message: TWMNCHitTest);
const
  EDGEDETECT = 17;  //adjust to suit yourself    // <- increased to suit outer offset
var
  deltaRect: TRect;  //not really used as a rect, just a convenient structure

  OuterRect: TRect;                              // used as a rect
begin
  inherited;
  if BorderStyle = bsNone then begin
    with Message, deltaRect do begin

     ..
      else if (Right<EDGEDETECT) then
        Result := HTRIGHT;
     ..

      OuterRect := BoundsRect;                    // patch
      InflateRect(OuterRect, -10, -3);
      if not PtInRect(OuterRect, SmallPointToPoint(Message.Pos)) then
        Message.Result := HTTRANSPARENT;

    end;
  end;
end;

这篇关于从不同的约束调整无边界形式的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆