gpt4 book ai didi

delphi - 如何对齐 Windows Media Player 控件以适应父窗口?

转载 作者:行者123 更新时间:2023-12-03 15:26:35 24 4
gpt4 key购买 nike

我有一个 Windows Media Player ActiveX 控件。我希望它与其父级 TPanel 对齐。

问题是,无论我尝试什么,WMP 控件始终设置为其初始大小,而无法调整其大小。

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, XpMan, ExtCtrls, WMPLib_TLB;

type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
public
Panel: TPanel;
MP: TWindowsMediaPlayer;
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
Width := 450;
Height := 260;

Panel := TPanel.Create(Self);
Panel.Parent := Self;
Panel.Align := alClient;


MP := TWindowsMediaPlayer.Create(Self);
// MP.stretchToFit := True;
MP.Parent := Panel;
MP.Align := alClient;
MP.URL := 'https://www.w3schools.com/html/mov_bbb.mp4';
end;

当您打开表单时,WMP 控件看起来不错:

enter image description here

但是当您调整表单大小时,WMP 控件将不会与父面板对齐:

enter image description here

这实际上是我尝试放大时看到的效果:

enter image description here

如何才能使 WMP 控件按预期运行?

我尝试过很多愚蠢的事情,例如:

procedure TForm1.FormResize(Sender: TObject);
begin
if not Assigned(MP) then Exit;
MP.Width := Panel.ClientWidth;
MP.Height := Panel.ClientHeight;
Panel.Realign;
end;

但是没有任何效果!

最佳答案

这是 Delphi 7 OleCtrls 中 TOleControl.SetBounds 中的一个错误。它已在新版本中修复。

procedure TOleControl.SetBounds(ALeft, ATop, AWidth, AHeight: Integer);
var
LRect: TRect;
begin
if ((AWidth <> Width) and (Width > 0)) or ((AHeight <> Height) and (Height > 0)) then
begin
if (FMiscStatus and OLEMISC_INVISIBLEATRUNTIME <> 0) or
((FOleObject.SetExtent(DVASPECT_CONTENT, Point(
MulDiv(AWidth, 2540, Screen.PixelsPerInch),
MulDiv(AHeight, 2540, Screen.PixelsPerInch))) <> S_OK)) then
begin
AWidth := Width;
AHeight := Height;
end;
{ fix start }
if FOleInplaceObject <> nil then
begin
LRect := Rect(Left, Top, AWidth, AHeight);
FOleInplaceObject.SetObjectRects(LRect, LRect);
end;
{ fix end }
end;
inherited SetBounds(ALeft, ATop, AWidth, AHeight);
end;

将其应用到 OleCtrls 的本地副本后,一切正常。

关于delphi - 如何对齐 Windows Media Player 控件以适应父窗口?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59346957/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com