【问题标题】:Delphi - scroll group of components on block overflowDelphi - 在块溢出时滚动组件组
【发布时间】:2015-08-02 05:29:30
【问题描述】:

我查看了诸如 GroupBox、Panel、ScrollBox、ListBox 之类的组件,但没有一个是我想要的。

我想要的是一个具有固定大小、没有可见边框、最好是非彩色背景的组件,并且如果它们溢出该组件,将允许隐藏包含的组件。

这是我想在我的 Delphi 项目中实现的示例:http://jsfiddle.net/jgems3Ls/1/

德尔福层次思想:

 #non-visible component
 #non-visible component
+---------------------+
|  visible component  |
|  visible component  |  //TOverflowBox(?) borders
|  visible component  |
+---------------------+
 #non-visible component

不幸的是,谷歌搜索没有给我一个提示我该怎么做

【问题讨论】:

  • 我不明白你在问什么
  • @DavidHeffernan,我需要一个行为类似于 #wrapper 并应用了所有 CSS 的组件
  • TScrollBox 有什么问题?
  • TPanel 可以做overflow: hidden 所做的事情(即在不滚动的情况下剪切内容)。
  • @fantaghirocco 父窗体有自定义图像作为其背景,我需要通过滚动组件查看此图像

标签: delphi overflow components delphi-7


【解决方案1】:

找到了使用 TPanel 的解决方案。

有两件事要开始:

  1. 我的表单有自定义图片作为背景
  2. 面板设置和子组件在运行时设置

由于 TPanel 没有透明度属性,我需要找到一种方法来保留表单图像而不是灰色面板背景。解决方案非常明显:将表单图像作为新组件放入面板中,并具有所需的左侧和顶部偏移量,以使其看起来不错。示例代码是:

P := Panel1;
P.Width := 300;
P.Height := 200;
P.Left := 100;
P.Top := 50;

//panel background
I := Image1;  //its width and height equal to forms ClientWidth and ClientHeight
I.Left := -100;
I.Top := -50;

下一个问题是面板边框,P.BevelOuter := bvNone 可以轻松移除。

为了让面板组件滚动,我使用了 MouseWheel 事件。

procedure TForm1.FormMouseWheel(Sender: TObject; Shift: TShiftState;
  WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
var P: TPanel;
    B: boolean;
begin
  B := true;
  case global_navigation(location, sub_location) of //returns current visible panel
    0: B := false;  //no visible panels
    1: P := Form1.Panel1;           
    ...
  end;

  //now we need to check if cursor is in panel area
  if B then
    if (PtInRect(P.ClientRect, P.ScreenToClient(Mouse.CursorPos))) then
      if WheelDelta > 0 then                     //if we scroll up
        for i := (P.ControlCount - 1) downto 1 do
          P.Controls[i].Top := P.Controls[i].Top + 10
     else                                        //if we scroll down
        for i := (P.ControlCount - 1) downto 1 do
          P.Controls[i].Top := P.Controls[i].Top - 10;
end;

通过面板组件循环完成downto 1,而不是downto 0,因为面板包含的第一个组件是用作背景的图像,我不想移动它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-29
    • 2021-02-12
    • 1970-01-01
    • 2012-01-21
    相关资源
    最近更新 更多