Delphi 2010 平板电脑支持

发布于 2024-10-04 22:45:57 字数 161 浏览 5 评论 0原文

当我因工作需要购买 delphi 时,我看到的一大卖点是它支持平板电脑的能力。现在我工作的公司的客户想要使用平板电脑。我一直在努力寻找 delphi 与平板电脑的示例,但我没有找到。有人有这方面的经验吗?有任何类型的教程或示例吗?

当组件获得焦点时我什至无法带上虚拟键盘并在失去焦点时隐藏它。

One of the big selling points I saw when I had to buy delphi for my job was the ability to support tablet pc's. Now the client of the company where I work want to use a tablet pc. I've been trying hard to find examples of delphi with tablet pc but I don't find any. Does anybody has experience with it? Any kind of tutorials or examples?

I don't seem to be able even to bring a virtual keyboard when a component gain focus and hide it when it loses it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蒲公英的约定 2024-10-11 22:45:57

Delphi 2010 为 Delphi 引入了一些很好的触摸和手势支持。

要获取更多信息,请访问 EDN 网站并查找 CodeRage 4 重播。 Seppy Bloom 举办了一场题为“VCL 中的手势”的会议。 CodeRage 5 中还有一个题为“新应用程序和当前项目的手势功能”的会议,作者为 Vesvolod Leonov。

Marco Cantu 的“Delphi 2010 手册”第 6 章也介绍了 Delphi 中的触摸和手势。

最后,您可以查看 Chris Bensen 的博客,了解一些介绍性帖子和演示源代码Delphi 中的触摸和手势支持。

我好像连带都带不了
当组件时的虚拟键盘
获得焦点并在失去焦点时隐藏它
它。

在 Delphi 2010 及更新版本中,支持触摸的键盘组件是已经可用。要使其在焦点更改时可见或隐藏,您可以处理 CM_FOCUSCHANGED VCL消息,当获得焦点的控件派生于某个类或满足某些特殊条件时,使键盘可见。以下是示例代码:

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Button1: TButton;
    Memo1: TMemo;
    TouchKeyboard1: TTouchKeyboard;
  private
    procedure ActivateVirtualKeyboard(Control: TWinControl; Keyboard: TTouchKeyboard);
    procedure CmFocusChanged(var Msg: TCMFocusChanged); message CM_FOCUSCHANGED;
  public
    { Public declarations }
  end;

/// Implementation

procedure TForm1.ActivateVirtualKeyboard(Control: TWinControl; Keyboard: TTouchKeyboard);
var
  APoint : TPoint;
begin
  if Control is TCustomEdit then
  begin
    APoint := Control.ClientToScreen(Point(0,0));
    APoint := Keyboard.Parent.ScreenToClient(APoint);
    Keyboard.Left := APoint.X;
    Keyboard.Top := APoint.Y + (Control.Height);
    Keyboard.Visible := True;
  end
  else
    Keyboard.Visible := False;
end;

procedure TForm1.CmFocusChanged(var Msg: TCMFocusChanged);
begin
  ActivateVirtualKeyboard(Msg.Sender, TouchKeyboard1);
end;

每次焦点更改时,上面的代码都会调用ActivateVirtualKeyboard。 Msg.Sender 是获得焦点的控件。 ActivateVirtualKeyboard 检查该控件是否是 TCustomEdit 后代(如 TEdit 或 TMemo 之类的组件源自此类)。如果该控件派生自 TCustomEdit,则它将虚拟键盘放置在该控件的正下方,并使键盘可见;否则,它会隐藏键盘。

在示例代码中,Form1 上有一个编辑、一个备忘录和一个按钮。键盘对于 Edit1 和 Memo1 应该可见,而当 Button1 获得焦点时键盘应该隐藏。

屏幕上键盘位置的计算并不那么聪明,如果具有焦点的控件非常接近窗体的底部边缘,键盘可能会太向下。无论如何,在屏幕上定位控件超出了您的问题范围。

Delphi 2010 introduced some nice touch and gesture support to Delphi.

To get more info about it, go to EDN website and look for CodeRage 4 replays. There is a session titled "Hands on gestures in VCL" by Seppy Bloom. Also in CodeRage 5 there is a session titled "Gesturing Capabilities for New Application and Current Projects" by Vesvolod Leonov.

Chapter 6 of Marco Cantu's "Delphi 2010 Handbook" also covers touch and gesture in Delphi.

Eventually, you can check Chris Bensen's weblog for some introductory posts and demo source code about touch and gesture support in Delphi.

I don't seem to be able even to bring
a virtual keyboard when a component
gain focus and hide it when it loses
it.

In Delphi 2010 and newer versions a touch-enabled keyboard component is already available. To make it is visible or hide it when focus is changed, you can handle CM_FOCUSCHANGED VCL message, and make the keyboard visible when the control gaining focus is derived from a certain class or meets some special conditions. Here is a sample code:

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Button1: TButton;
    Memo1: TMemo;
    TouchKeyboard1: TTouchKeyboard;
  private
    procedure ActivateVirtualKeyboard(Control: TWinControl; Keyboard: TTouchKeyboard);
    procedure CmFocusChanged(var Msg: TCMFocusChanged); message CM_FOCUSCHANGED;
  public
    { Public declarations }
  end;

/// Implementation

procedure TForm1.ActivateVirtualKeyboard(Control: TWinControl; Keyboard: TTouchKeyboard);
var
  APoint : TPoint;
begin
  if Control is TCustomEdit then
  begin
    APoint := Control.ClientToScreen(Point(0,0));
    APoint := Keyboard.Parent.ScreenToClient(APoint);
    Keyboard.Left := APoint.X;
    Keyboard.Top := APoint.Y + (Control.Height);
    Keyboard.Visible := True;
  end
  else
    Keyboard.Visible := False;
end;

procedure TForm1.CmFocusChanged(var Msg: TCMFocusChanged);
begin
  ActivateVirtualKeyboard(Msg.Sender, TouchKeyboard1);
end;

The code above calls ActivateVirtualKeyboard each time focus is changed. Msg.Sender is the control which gained focus. ActivateVirtualKeyboard checks if the control is a TCustomEdit descendant (components like TEdit or TMemo descend from this class). If the control is derived from TCustomEdit, then it places virtual keyboard right beneath the control, and makes the keyboard visible; otherwise, it hides the keyboard.

In the sample code we have an edit, a memo, and a button on Form1. The keyboard should be visible for Edit1 and Memo1, and hid when Button1 has focus.

The calculation for keyboard position on the screen isn't that clever, and keyboard might go too down if the control having focus is very close to the bottom edge of the form. Anyway, positioning a control on the screen is out of the scope of your question.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文