- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
使用 Delphi XE6,我正在创建一个类似 TdateTimePicker 的控件,但由于几个原因,我使用了 TButtonedEdit,其中“嵌入”了 TMonthCalendar。完整的简单演示是:
我已经按照预期进行了,当单击右键(使用 Style=WS_POPUP)时显示月历,并在做出选择时隐藏它,用户导航离开,转义符等。
unit DateEditBare1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.ImgList, Vcl.ComCtrls, Vcl.StdCtrls,
CommCtrl;
type
TespMonthCalendar = class(TMonthCalendar)
procedure DoCloseUp(Sender: TObject);
private
FDroppedDown: boolean;
FManagerHandle: HWND; // just a convenience to avoid having to assume its in the owner
procedure CNNotify(var Message: TWMNotify); message CN_NOTIFY;
procedure SetWindowDIMs;
protected
procedure CreateParams(var Params: TCreateParams); override;
procedure CreateWnd; override;
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
procedure WMActivate(var Msg: TWMActivate); message WM_ACTIVATE;
procedure CMHintShow(var Message: TCMHintShow); message CM_HINTSHOW;
end;
TespDateEdit = class(TButtonedEdit)
private
FMonthCalendar: TespMonthCalendar;
procedure DoRightButtonClick(Sender: TObject);
protected
procedure CreateWnd; override;
procedure CMHintShow(var Message: TCMHintShow); message CM_HINTSHOW;
public
constructor Create(AOwner:TComponent); override;
property MonthCalendar: TespMonthCalendar read FMonthCalendar write FMonthCalendar;
end;
TfrmDateEditBare1 = class(TForm)
Edit1: TEdit;
procedure FormCreate(Sender: TObject);
private
espDateEdit1: TespDateEdit;
public
end;
var
frmDateEditBare1: TfrmDateEditBare1;
implementation
{$R *.dfm}
var
_espdateEdit_ImageList: TImageList=nil;
//------------------------------------------------------------------------------
function MakeImageList(const ResNames: array of String): TImageList;
var
ResBmp: TBitmap;
I: Integer;
begin
{ Create an image list. }
_espdateEdit_ImageList := TImageList.Create(nil);
_espdateEdit_ImageList.Width := 24;
_espdateEdit_ImageList.Height := 16;
Result := _espdateEdit_ImageList;
for I := 0 to Length(ResNames) - 1 do
begin
ResBmp := TBitmap.Create();
try
{ Try to load the bitmap from the resource. }
try
//ResBmp.LoadFromResourceName(HInstance, ResNames[I]);
ResBmp.SetSize(24,16);
ResBmp.Transparent := true;
except
ResBmp.Free();
Result.Free();
Exit;
end;
Result.Add(ResBmp, nil);
finally
ResBmp.Free;
end;
end;
end;
// Aowner is ignored for now
function GetImageList: TImageList;
begin
if _espdateEdit_ImageList = nil then
result := MakeImageList(['CalendarDrop', 'CalendarDropShifted'])
else
result := _espdateEdit_ImageList;
end;
//------------------------------------------------------------------------------
procedure TfrmDateEditBare1.FormCreate(Sender: TObject);
begin
espDateEdit1:= TespDateEdit.Create(self);
espDateEdit1.Parent := self;
espDateEdit1.left := 100;
espDateEdit1.top := 100;
espDateEdit1.Visible := true;
end;
//------------------------------------------------------------------------------
{ TespMonthCalendar }
procedure TespMonthCalendar.CMHintShow(var Message: TCMHintShow);
begin
inherited;
if Message.HintInfo.HintControl=Self then
begin
Message.HintInfo.HintPos := self.ClientToScreen(Point(0, self.Height + 1));
Message.HintInfo.HideTimeout := 1000;
// Message.HintInfo.ReshowTimeout := 1500; // setting this does not help
end;
end;
procedure TespMonthCalendar.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
with Params do
begin
Style := WS_POPUP;
WindowClass.Style := WindowClass.Style or CS_SAVEBITS ;
if CheckWin32Version(5, 1) then
WindowClass.Style := WindowClass.style or CS_DROPSHADOW;
end;
end;
procedure TespMonthCalendar.CreateWnd;
begin
inherited;
// Get/set the dimensions of the calendar
SetWindowDIMs;
end;
procedure TespMonthCalendar.SetWindowDIMs;
var
ReqRect: TRect;
MaxTodayWidth: Integer;
begin
FillChar(ReqRect, SizeOf(TRect), 0);
// get required rect
Win32Check(MonthCal_GetMinReqRect(Handle, ReqRect));
// get max today string width
MaxTodayWidth := MonthCal_GetMaxTodayWidth(Handle);
// adjust rect width to fit today string
if MaxTodayWidth > ReqRect.Right then
ReqRect.Right := MaxTodayWidth;
// set new height & width
Width := ReqRect.Right ;
Height:= ReqRect.Bottom ;
end; (* SetWindowDIMs *)
procedure TespMonthCalendar.CNNotify(var Message: TWMNotify);
begin
// hand off control of the selection to the boss i.e. the espDateEdit that I belong to
// skip for demo ... just closeup
if ( Message.NMHdr^.code = MCN_SELECT) then
DoCloseUp(self);
inherited;
end; (*CNNotify*)
procedure TespMonthCalendar.KeyDown(var Key: Word; Shift: TShiftState);
begin
if Key = VK_ESCAPE then
begin
Key := 0;
DoCloseUp(self);
end
else
inherited KeyDown(Key, Shift);
end;
procedure TespMonthCalendar.WMActivate(var Msg: TWMActivate);
begin
if (Msg.Active <> WA_INACTIVE) then
// tell form to paint itself as though it still has focus (as we are no outside the form with POPUP)
SendMessage(screen.ActiveForm.Handle, WM_NCACTIVATE, WPARAM(True), -1)
else
DoCloseUp(self);
inherited;
end;
procedure TespMonthCalendar.DoCloseUp(Sender: TObject);
begin
if FDroppedDown then
begin
FDroppedDown := false;
Hide;
// put focus back on dateedit so that checking is done if we leave here to go on to another control
SendMessage(FManagerHandle, WM_ACTIVATE, WPARAM(True), -1); // less assumptions this way
end;
end;
//------------------------------------------------------------------------------
{ TespDateEdit }
procedure TespDateEdit.CMHintShow(var Message: TCMHintShow);
begin
inherited;
if Message.HintInfo.HintControl=Self then
Message.HintInfo.HintPos := self.ClientToScreen(Point(0, 21));
end;
constructor TespDateEdit.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
if not(csDesigning in ComponentState) then
begin
FmonthCalendar := TespMonthCalendar.Create(self);
self.hint := 'DUMMY HINT for Edit Box';
FMonthCalendar.Hint := 'Select required Date,' + ^M^J + 'or ESCape to close the calendar.';
FMonthCalendar.ShowHint := true;
end;
Width := 100;
Height := 21;
Images := GetImageList;
Text := ''; // FormatdateTime('dd/mm/yy', Date); // not for demo
ShowHint := True;
DoubleBuffered := true; // reduces flicker when passing thru and within control
RightButton.ImageIndex := 0;
RightButton.PressedImageIndex := 1;
RightButton.Visible := True;
OnRightButtonClick := DoRightButtonClick;
end;
procedure TespDateEdit.CreateWnd;
var
P: TWinControl;
begin
inherited CreateWnd;
if not(csDesigning in ComponentState) then
begin
FMonthCalendar.left := -900;
P := self.Parent;
while (P <> nil ) and not ( P is TCustomForm ) do
P := P.parent;
FmonthCalendar.Parent := P; // ie form (or the topmost non nil entry in the tree)
FmonthCalendar.FManagerHandle := self.Handle;
FMonthCalendar.Hide;
FmonthCalendar.OnExit := FmonthCalendar.DoCloseUp;
end;
end;
procedure TespDateEdit.DoRightButtonClick(Sender: TObject);
var
dt: Tdate;
TopLeft: TPoint;
Rect: TRect;
begin
if FmonthCalendar.FdroppedDown then
begin
FMonthCalendar.DoCloseUp(nil);
exit;
end;
// load non-zero date into calendar as the selected date ... skip for demo
TopLeft := self.ClientToScreen(Point(0, 0)); // i.e. screen co-ords of top left of edit box
monthCalendar.left := TopLeft.X - 3 ; // shift a poopsie to line up visually
monthCalendar.Top := TopLeft.Y + self.Height - 2;
// only move it if it exceeds screen bounds ... skip this for demo
FmonthCalendar.FDroppedDown := true;
MonthCal_SetCurrentView(FmonthCalendar.handle, MCMV_MONTH);
FmonthCalendar.Show;
// showing is not enough - need to grab focus to get kbd events happening on the calendar
FmonthCalendar.SetFocus;
inherited OnRightButtonClick;
end;
//------------------------------------------------------------------------------
initialization
finalization
FreeAndNil(_espdateEdit_ImageList);
end.
现在,我想为编辑框和 TMonthCalendar 添加单独的提示,但我想确保显示的提示不会遮挡相关控件。对于编辑框,我已经成功拦截了 CM_HINTSHOW 消息,并设置了 HintInfo.HintPos 来实现这一点。到目前为止,一切顺利。
问题 1:更新:我现在已经显示了。最初,我将提示文本设置为包含管道字符,以便我可以使用 TCustomHint。删除管道字符,导致显示提示。 但是此提示不会隐藏自身,它会在 TmonthCalendar 显示时保留在屏幕上。我怎样才能让它“ self 隐藏”?
问题 2:如果我对任一控件使用 TCustomHint,则 CMHintShow 过程永远不会触发。那么,如果我确实想使用 TCustomHint 来实现它提供的额外控制,那么这会如何改变定位策略呢?(我不希望在“应用程序”级别进行任何操作,例如通过 OnShowHint - 它必须特定于这些控件)
最佳答案
正如问题评论中所确定的那样,提示不会无限期地保留在屏幕上,但实际上一旦隐藏就会不断重新显示。
原因是,VCL 假定提示控件是子窗口,这是因为它的 Parent
属性不为零。就问题中的代码而言,尽管月历通过将其转变为弹出窗口而 float ,但就 VCL 所知,其父级仍然是表单。这会导致应用程序的ActivateHint
过程中提示矩形的计算出错。另一方面,应用程序的 HintMouseMessage
过程并不关心控件是否为父控件。接下来发生的情况是,虽然您没有在控件上移动鼠标指针,但 VCL 会推断鼠标指针不断离开提示边界然后重新进入。
这是该问题的简化再现:
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.StdCtrls;
type
TPanel = class(vcl.extctrls.TPanel)
protected
procedure CreateParams(var Params: TCreateParams); override;
end;
TForm1 = class(TForm)
Button1: TButton;
Panel1: TPanel;
procedure FormCreate(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TPanel }
procedure TPanel.CreateParams(var Params: TCreateParams);
begin
inherited;
Params.Style := WS_POPUPWINDOW or WS_THICKFRAME;
end;
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
begin
Button1.Hint := 'Button1';
Panel1.Hint := 'Panel1';
ShowHint := True;
Application.HintHidePause := 1000;
Left := 0;
Top := 0;
Panel1.ParentBackground := False;
Panel1.Left := 0;
Panel1.Height := 50;
Panel1.Top := Top + Height;
end;
end.
在上面的代码中,按钮的提示会在超时时隐藏,而面板的提示在隐藏后会重新显示。我特意将窗口定位到它们的位置,以便您可以在激活提示时观察指针位置的意义。如果您将鼠标指针从下方输入面板,提示将仅显示一次,然后隐藏。但是,如果您从上面进入面板,您就会看到问题。
修复方法很简单,您可以修改 CM_HINTSHOW
消息处理程序中的提示矩形。由于控制是 float 的,因此不需要复杂的计算。相应地修改了复制案例,这也修复了问题中的日历:
type
TPanel = class(vcl.extctrls.TPanel)
protected
procedure CreateParams(var Params: TCreateParams); override;
procedure CMHintShow(var Message: TCMHintShow); message CM_HINTSHOW;
end;
TForm1 = class(TForm)
...
{ TPanel }
procedure TPanel.CMHintShow(var Message: TCMHintShow);
begin
inherited;
if (GetAncestor(Handle, GA_ROOT) = Handle) and Assigned(Parent) then
Message.HintInfo.CursorRect := Rect(0, 0, Width, Height);
end;
对于问题 2,不幸的是,自定义提示窗口似乎没有被设计为可定位的。提示窗口是本地创建的,没有巧妙的方法来获取它或以任何其他方式指定其位置。我能想到的唯一方法是重写自定义提示的绘制方法之一,该方法将提示窗口公开为参数。因此,我们可以在提示窗口收到绘画消息后立即重新定位它。
这是一个工作示例(对于普通(非 float )控件):
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure FormCreate(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
type
TMyCustomHint = class(TCustomHint)
private
FControl: TControl;
public
procedure NCPaintHint(HintWindow: TCustomHintWindow; DC: HDC); override;
end;
procedure TMyCustomHint.NCPaintHint(HintWindow: TCustomHintWindow; DC: HDC);
var
Pt: TPoint;
begin
Pt := FControl.ClientToScreen(Point(0, 0));
SetWindowPos(HintWindow.Handle, 0, Pt.X, Pt.Y + FControl.Height, 0, 0,
SWP_NOSIZE or SWP_NOZORDER or SWP_NOACTIVATE);
inherited;
end;
//--------
procedure TForm1.FormCreate(Sender: TObject);
begin
ShowHint := True;
Button1.Hint := 'button1 hint';
Button1.CustomHint := TMyCustomHint.Create(Self);
TMyCustomHint(Button1.CustomHint).FControl := Button1;
end;
end.
关于delphi - Delphi 中组件的定位提示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41473016/
我的 friend 编写了一个程序,它比较随机排列的骰子面,以找到分布最均匀的面——尤其是当面不仅仅是序列时。 我将他的程序翻译成 haskell 是因为我一直在寻找一个理由来让别人知道 haskel
我需要对表单中的某些字段进行评论/提示。我的想法是在模型中描述它,就像attributeLabels一样。我该怎么做? 然后它会是理想的,如果 Gii 模型(和 Crud)生成器直接从 mysql 列
我们使用 FastReport 来生成报告。事实上,我们为访问源代码付费。 我们目前使用的是 FastReport 的最新稳定版本。虽然它对于我们的生产来说足够稳定,但每当我编译时,我都会看到以下内容
我需要创建一个对话框/提示,包括用于用户输入的文本框。我的问题是,确认对话框后如何获取文本?通常我会为此创建一个类,将文本保存在属性中。不过我想使用 XAML 设计对话框。因此,我必须以某种方式扩展
我想提示用户是否要执行操作(删除) - 用警报框说"is"或“否”,如果是,则运行删除脚本,如果否,则不执行任何操作 我不太了解 javascript,因此是否有人可以使用 javascript 获得
所以我正在编写一个简单的 JS 代码。我们刚刚开始学习函数。我需要创建一个名为“printStars”的函数。 我需要从用户那里获取一个号码,并根据该号码打印“*”。 这就是我所做的:
我在我的页面上添加了一个提示,但它在页面加载之前加载了。如何仅在整个页面可见时才显示消息? 这是我的提示: if (name == null || name == "") { txt == "No
我在我的页面上添加了一个提示,但它在页面加载之前加载了。如何仅在整个页面可见时才显示消息? 这是我的提示: if (name == null || name == "") { txt == "No
我正在自定义我的 zsh 提示,并发现以下内容来检查是否有任何后台作业: if [[ $(jobs | wc -l) -gt 0 ]]; then # has background job(s)
这个问题在这里已经有了答案: JavaScript object: access variable property by name as string [duplicate] (3 个答案) pa
我正在尝试用 javascript 制作一个简单的数学练习程序。在提示警报中给出不同的值,并将答案与用户输入进行比较。这是代码: Calculations generate(); functio
在这段代码中,尽管我使用了文本对齐属性在“编辑文本” View 的中心设置“提示”。但它无法正常工作。 最佳答案 尝试 关于android - 如何在编辑文本的中心对齐文本(提示),我们在Sta
我正在尝试让我的 EditText 显示一个提示,例如“请在此处输入答案”,当用户点击 EditText 以键入他们的答案时,文本应该消失并留空,以便他们在其中输入答案. 截至目前,这就是我的 .xm
我当前的 android 应用程序中有两个微调器,我想要一个默认值,例如 editText 的 android:hint 功能。有没有办法这样做,但不会将提示添加到填充微调器的字符串数组。例如从微调器
如果我的表单已完全填写,我如何提示“感谢您填写表单,“name”!” function submit_onclick() { if(confirm("Thanks for completing t
我刚刚了解了prompt()命令;我知道 Prompt() 命令以字符串的形式返回用户输入。我正在搞乱下面的程序,我输入了Per“Dead”Ohlin作为男性名字。为什么这有效并且没有引起任何问题?
void openUpNow(FILE *x, FILE *y) { x = fopen("xwhatever", "r"); y = fopen("ywhatever", "r");
我有一个作业正在处理,但我在使用 prompt() 方法时遇到了问题。我看到我可以做一个提示,但我需要几个并且有数量。 例如... 我创建了一个 HTML 表格,其中包含许多艺术家和包含 DVD、CD
我正在学习 Big Nerd Ranch 的 iOS Programming, 2nd Edition,我已经来到第 4 章挑战:标题。该练习暗示我感到困惑;它说我需要做一些我认为不需要做的事情。 到
抱歉,如果这是微不足道的,但我没有找到任何解决此问题的建议。我在 Ubuntu 上,我的 Yii 项目需要 PHPUnit。我已经安装了 PHPUnit 两次,方法是下载 phpunit.phar 并
我是一名优秀的程序员,十分优秀!