我作实验怎么取了myform.parent:=form1;
就行呀。
var
myform:tform;
begin
myform:=Tform.create(form1);
myform.show;
end;
就行呀。
var
myform:tform;
begin
myform:=Tform.create(form1);
myform.show;
end;
解决方案 »
- Delphi转换文件为UTF-8的问题
- 领导说:delphi有个控件可以模拟用户输入以实现软件自动安装的功能,特来请教。
- fastreport
- 再次问关于Delphi 6 的TIdTCPClient超时问题。是delphi 6!!!
- 读取文本文件里内容的问题
- 超急的问题!!高手不吝赐教,针式打印机,QR怎么样打印收据,走纸的那种.控制纸张的宽度长度.谢谢,分不是问题!
- IndyTCPServer问题
- 急!!!在Delphi下调用exe文件的问题?
- 我的QQ被盗了,哪位老兄帮我弄回来感激不尽。这上面都是我大学的同学,帮帮忙吧!
- 百分比的转换
- 请教一个数据库的问题
- 怎么让程序最小化到托盘,并不停变换图标?
下面的方法。 frmNew := TfrmNew.Create(Application);
frmNew.parent := frmparent;
frmNew.BorderStyle := bsNone;
frmNew.Align := alclient;
frmNew.position := podefault;
frmNew.show;如果情况合适,我可以提供源代码。
是不是真的没人知道如何写?
formnew:=tform1.create(self);
formnew.Show ;
它就是获得了焦点的啊
frmNew := TfrmNew.Create(Application);
frmNew.parent := frmparent;
frmNew.BorderStyle := bsNone;
frmNew.Align := alclient;
frmNew.position := podefault;
frmNew.show;
在下面的代码中则Form(Form2.Owner)就是Form1,要是改成
Form2 := TForm.Create(MainForm);
则TForm(Form2.Owner) := MainForm
var
Form2: TForm;
begin
Form2 := TForm.Create(Form1);
Showmessage(TForm(Form2.Owner).Name);
Form2.Show;
end;
show和showmodal的区别,
和frmNew.BorderStyle := bsNone;
你怎么就不可以自己多试两下呢.
要看清楚人家的需求,他是想出现标题栏又要得到焦点,就想MDI那样,
把BorderStyle设置为None可以得到焦点但已经没有标题栏了.
******************************************************************** 动动态创建的窗口要获得焦点,请把 myform.show;
改为
myform.visible:=true, 马上就行!
********************************************************************
myform.setfocus;但也没有用,焦点仍没有转到新建窗口去。
********************************************************************
在下面的代码中则Form(Form2.Owner)就是Form1,要是改成
Form2 := TForm.Create(MainForm);
则TForm(Form2.Owner) := MainForm
var
Form2: TForm;
begin
Form2 := TForm.Create(Form1);
Showmessage(TForm(Form2.Owner).Name);
Form2.Show;
end;
这么做难道不行么?
frm2.BorderStyle := bsSizeable;
frm2.Left :=0;
frm2.Top :=0;
frm2.Width :=100;
frm2.Height := 80;
frm2.Show;
这是我的测试代码,很好用啊,满足了你的要求。
老兄,你哪有满足我的要求?你这样的方法楼上的随便拿一个就行,
看清楚了,我是要myform做为一个panel的子窗口,也就是说myform.parent:=panel1;
明白了吗?
下面是我的C代码
Application->CreateForm(__classid(TFormPacklist), &FormPacklist);
FormPacklist->BorderStyle = bsNone;
ScrollBox1->HorzScrollBar->Position = 0;
ScrollBox1->VertScrollBar->Position = 0;
FormPacklist->Parent = ScrollBox1;
FormPacklist->Show();
最好是用一个scrollbox作父
我的c代码
Application->CreateForm(__classid(TFormPacklist), &FormPacklist);
FormPacklist->BorderStype = bsNone;
...
ScrollBox1->HorzScrollBar->Position = 0;
ScrollBox1->VertScrollBar->Position = 0;
FormPacklist->Parent = ScrollBox1;
FormPacklist->Show();
注意1:Application->CreateForm
myform:Tform ;
yeedit:tedit;procedure Tmainform.Button1Click(Sender: TObject);
begin
myform:=Tform.create(application.Owner);
myform.parent:=mainform.Panel1 ;
myform.show;
yeedit:=Tedit.create(self);
yeedit.parent:=myform ;
yeedit.SetFocus;end;
begin
myform:=Tform.create(mainform);
myform.show;
end;
var
mForm : TForm;
begin
mForm := TForm.Create(self);
mForm.Position := poScreenCenter;
mForm.Show;
end;
myform.parent:=mainform;
myform.show;
BringWindowToTop(MyForm.handle);结帖吧!
myform.parent:=mainform.panel2;
谢谢,
myform:=Tform.create(nil);
//myform.parent:=form1;
Windows.SetParent(myform.Handle,form1.Handle);
myform.show;end;
Windows, Messages, SysUtils, Classes, Graphics, Controls, ExtCtrls, Buttons;type
TTitlePosition = alTop..alRight;
{$EXTERNALSYM TTitlePosition} TJvOutlookTitle = class(TPersistent)
private
FPosition: TTitlePosition;
FOnChange: TNotifyEvent;
FCaption: TCaption;
FFont: TFont;
FAlignment: TAlignment;
FGlyph: TBitmap;
FHeight: Integer;
FColor: TColor;
procedure SetPosition(const Value: TTitlePosition);
procedure SetCaption(const Value: TCaption);
procedure SetFont(const Value: TFont);
procedure SetAlignment(const Value: TAlignment);
procedure SetGlyph(const Value: TBitmap);
procedure SetHeight(const Value: Integer);
procedure SetColor(const Value: TColor);
protected
property OnChange: TNotifyEvent read FOnChange write FOnChange;
procedure FontChanged(Sender: TObject);
public
constructor Create;
published
property Alignment: TAlignment read FAlignment write SetAlignment default taCenter;
property Caption: TCaption read FCaption write SetCaption;
property Font: TFont read FFont write SetFont;
property Position: TTitlePosition read FPosition write SetPosition default alTop;
property Glyph: TBitmap read FGlyph write SetGlyph;
property Color: TColor read FColor write SetColor default clBtnFace;
property Height: Integer read FHeight write SetHeight default 20;
end; TJvOutlookPanel = class(TWinControl)
private
FTitle: TJvOutlookTitle;
FOnHide: TNotifyEvent;
FPanel: TPanel;
FButton: TSpeedButton;
protected
procedure TitleChanged(Sender: TObject);
procedure ButtonClick(Sender: TObject); virtual;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property Align;
property BorderWidth;
property Anchors;
property Visible;
property Constraints;
property Width;
property Height;
property ClientWidth;
property ClientHeight;
property Color;
property Hint;
property ShowHint;
property Title: TJvOutlookTitle read FTitle write FTitle;
property OnHide: TNotifyEvent read FOnHide write FOnHide;
end;implementation{$R RES_Outlook.res}///////////////////////////////////////////////////////////
// TJvOutlookPanel
///////////////////////////////////////////////////////////procedure TJvOutlookPanel.ButtonClick(Sender: TObject);
begin
Visible := False;
if Assigned(FOnHide) then
FOnHide(Self);
end;{***************************************************}constructor TJvOutlookPanel.Create(AOwner: TComponent);
begin
inherited;
FTitle := TJvOutlookTitle.Create;
FTitle.OnChange := TitleChanged;
Width := 275;
Height := 200;
FTitle.FCaption := 'Outlook Panel'; FPanel := TPanel.Create(Self);
with FPanel do
begin
Align := alTop;
Alignment := taCenter;
AutoSize := False;
Caption := FTitle.Caption;
BevelOuter := bvRaised;
Parent := Self;
Height := 20;
Font.Style := [fsBold];
ControlStyle := ControlStyle - [csAcceptsControls];
end; FButton := TSpeedButton.Create(Self);
with FButton do
begin
Parent := FPanel;
Align := alRight;
Flat := True;
Caption := '';
Width := 20;
Glyph.LoadFromResourceName(HInstance, 'CLOSE');
OnClick := ButtonClick;
end;
ControlStyle := ControlStyle - [csFixedWidth, csFixedHeight];
ControlStyle := ControlStyle + [csAcceptsControls];
Color := clGrayText;
end;{***************************************************}destructor TJvOutlookPanel.Destroy;
begin
FTitle.Free;
FButton.Free;
FPanel.Free;
inherited;
end;{***************************************************}procedure TJvOutlookPanel.TitleChanged(Sender: TObject);
begin
FPanel.Align := Title.Position;
case Title.Position of
alTop:
begin
FButton.Align := alRight;
FPanel.Caption := Title.Caption;
end;
alLeft:
begin
FButton.Align := alTop;
FPanel.Caption := '';
end;
alRight:
begin
FButton.Align := alBottom;
FPanel.Caption := '';
end;
alBottom:
begin
FButton.Align := alRight;
FPanel.Caption := Title.Caption;
end;
end;
FPanel.Font.Assign(Title.Font);
FPanel.Alignment := Title.Alignment;
FPanel.Color := Title.Color;
if Title.Glyph.Width > 0 then
FButton.Glyph.Assign(Title.Glyph)
else
FButton.Glyph.LoadFromResourceName(hInstance, 'CLOSE');
FPanel.Height := Title.Height;
end;///////////////////////////////////////////////////////////
// TJvOutlookTitle
///////////////////////////////////////////////////////////constructor TJvOutlookTitle.Create;
begin
FPosition := alTop;
FAlignment := taCenter;
FGlyph := TBitmap.Create;
FFont := TFont.Create;
FFont.Style := [fsBold];
FFont.OnChange := FontChanged;
FHeight := 20;
FColor := clBtnFace;
end;{***************************************************}procedure TJvOutlookTitle.FontChanged(Sender: TObject);
begin
if Assigned(FOnChange) then
FOnChange(Self);
end;{***************************************************}procedure TJvOutlookTitle.SetAlignment(const Value: TAlignment);
begin
FAlignment := Value;
if Assigned(FOnChange) then
FOnChange(Self);
end;{***************************************************}procedure TJvOutlookTitle.SetCaption(const Value: TCaption);
begin
FCaption := Value;
if Assigned(FOnChange) then
FOnChange(Self);
end;{***************************************************}procedure TJvOutlookTitle.SetColor(const Value: TColor);
begin
FColor := Value;
if Assigned(FOnChange) then
FOnChange(Self);
end;{***************************************************}procedure TJvOutlookTitle.SetFont(const Value: TFont);
begin
FFont := Value;
if Assigned(FOnChange) then
FOnChange(Self);
end;{***************************************************}procedure TJvOutlookTitle.SetGlyph(const Value: TBitmap);
begin
FGlyph.Assign(Value);
if Assigned(FOnChange) then
FOnChange(Self);
end;{***************************************************}procedure TJvOutlookTitle.SetHeight(const Value: Integer);
begin
FHeight := Value;
if Assigned(FOnChange) then
FOnChange(Self);
end;{***************************************************}procedure TJvOutlookTitle.SetPosition(const Value: TTitlePosition);
begin
FPosition := Value;
if Assigned(FOnChange) then
FOnChange(Self);
end;end.
你如果真的要处理Form的化我可以这么说,你处理完这个问题VCL也让你给改写个差不多了!Form不是普通的组件,如果硬要往Panel里放,它的一些消息和特性将丧失殆尽。如果你要完成以上你所需要的功能,最好自己从TCustomControl或TWinControl派生一个类来自己截获消息来实现。
其实不是myform 没获得焦点,只是标题为灰而己,你试着双击标题栏,还能看到变蓝一晃而过。同时我在myform中动态创建了一个button,它能获得焦点!因为一个子控件要获得焦点,就有在它的父控件先获得焦点的时候,从这点可以看出,myform是获得了焦点的。标题栏为灰的原因是你是直接生成tform类的实例,你看标准的自动生成的源码都是先用tform1 继承tform ,再产生实例。
这是就事论事。要解决你的问题,要从你的目的出发。我先考虑清楚一下,我会关注你的贴子的。
varmyform:Tform;begin
myform:=Tform.create(nil);
//myform.parent:=form1;
Windows.SetParent(myform.Handle,panel1.Handle);
myform.show;end;
myform:=Tform.create(Application);
myform.show;
即可。
myform.parent:=mainform;
这一行是不对的。窗体哪来的parent!
-----------------------------------------------