i'm trying to dynamically show a form in a TPanel
using this function
procedure Show_form_in_panel(form: TForm; Panel: Tpanel);
begin
form.Parent := Panel;
form.Show;
form.WindowState := wsMaximized;
end;
the form is showing very normal but he's not maximized in my panel and also i want to make this form automaticly react like components that have the Alight property = (alClient)
I want to make this form automatically react like components that have the Align property set to alClient.
That's the solution. Remove
form.WindowState := wsMaximized;
and replace with
form.Align := alClient;
Related
When use TEdit control on the right side stay small icon 'x'. How after click on icon clear TEdit box.
Tnx all!
Delphi provide TClearEditButton to clear the TEdit content. It can be added by right clicking and selecting AddItem - TClearEditButton from the popup menu. It also has a Click procedure overriden in FMX.Edit unit like:
procedure TClearEditButton.Click;
var
EditTmp: TCustomEdit;
begin
inherited Click;
EditTmp := GetEdit;
if EditTmp <> nil then
begin
if EditTmp.Observers.IsObserving(TObserverMapping.EditLinkID) then
if not TLinkObservers.EditLinkEdit(EditTmp.Observers) then
Exit; // Can't change
EditTmp.Text := string.Empty;
if EditTmp.Observers.IsObserving(TObserverMapping.EditLinkID) then
TLinkObservers.EditLinkModified(EditTmp.Observers);
if EditTmp.Observers.IsObserving(TObserverMapping.ControlValueID) then
TLinkObservers.ControlValueModified(EditTmp.Observers);
end;
end;
Which make you don't need to write OnClick event handler for the TClearEditButton unless you want to do some other job along side with clearing the edit.
If you are using a TEditButton then you should write the OnClick event handler like:
procedure TForm1.EditButton1Click(Sender: TObject);
begin
Edit1.Text:= EmptyStr;
end;
I have a main form, with multiple panels, some of which are hidden. As the user interacts with the main form, I need to make some of the hidden panels visible and display them in a modal fashion so the user can't interact with the other parts of the main form until they finish with the modal panel.
Is there a way to display an existing panel on a form in a modal fashion?
I would prefer to not cycle through the main forms controls and disable/hide everything except for the one panel, which is the common answer developers have given when others have asked this same question.
My goal is to simply display an existing panel on the main form in a modal fashion without having to manipulate the other controls on the main form.
Since a TForm has .ShowModal(), we can easily create a temporary form, move the TPanel to the form, display the form as modal, wait for the user to dismiss the form, then move the TPanel back to its original parent before destroying the TForm.
If you create a form with a hidden TPanel called pnl and a button on that panel called btnCloseModalPanel, then the following code displays pnl as modal until the user clicks the button.
begin
DisplayModalPanel(pnl);
// do something with 'pnl.data...'
end;
procedure TForm1.DisplayModalPanel(Panel: TPanel);
var
frm: TForm;
old_top, old_left: Integer;
old_parent: TWinControl;
old_visible: Boolean;
begin
frm := TForm.Create(Panel.Parent);
try
frm.BorderStyle := bsNone;
frm.Position := poOwnerFormCenter;
frm.Tag := 12921; // test in close button click, so we don't close the wrong form
// Rememer properties we can change and then restore them
old_top := Panel.Top;
old_left := Panel.Left;
old_parent := Panel.Parent;
old_visible := Panel.Visible;
// Move the panel to the modal form
Panel.Parent := frm;
Panel.Top := 0;
Panel.Left := 0;
Panel.Visible := True;
// Display the modal form
frm.AutoSize := True;
frm.ShowModal;
// Restore everything
Panel.Visible := old_visible;
Panel.Parent := old_Parent;
Panel.Left := old_left;
Panel.Top := old_top;
finally
FreeAndNil(frm);
end;
end;
procedure TForm1.btnCloseModalPanelClick(Sender: TObject);
var
frm: TForm;
begin
if pnl.Parent is TForm then
begin
frm := pnl.Parent as TForm;
if frm.Tag = 12921 then // don't close the wrong form
frm.Close;
end;
end;
I've code in Delphi XE2 who work perfectly. But in Delphi XE6 it doesn't work.
I create a Tform with the property AutoSize to true. I use a TPanel align alTop with a button for create some another panels.
procedure TForm2.Button1Click(Sender: TObject);
var
t :TPanel;
begin
t := TPanel.Create(self);
t.Parent := self;
t.Align := alTop;
end;
The form doesn't auto size. If I want to see all my panels I have to move the form (or try to resize, ....).
Have you any idea's ?
This is indeed a change in behaviour. I can reproduce what you report. Namely that your code results in the form size changing in XE2, but not in XE6.
To work around this you can manually call AdjustSize:
procedure TForm1.Button1Click(Sender: TObject);
var
Panel: TPanel;
begin
Panel := TPanel.Create(self);
Panel.Parent := Self;
Panel.Top := ClientHeight;
Panel.Align := alTop;
AdjustSize;
end;
Not align, use anchors:
t.Anchors:=[TAnchorKind.akTop];
This is from my XE5 (have no XE6)
I have tried to embed a form inside a Scrollbox:
procedure TfrmMain.FormCreate(Sender: TObject);
var
Control:TControlView;
begin
Control := TControlView.Create(Self);
Control.BorderIcons := [];
Control.parent := ListControls;
Control.width := 800;
ListControls.AddObject(Control);
Control.Visible:= True;
end;
However the form is displayed behind tfrmMain and outside the bouns of the form.
My idea is put a form inside a panel, and both inside scrollbox. Each form represent a complex item with several controls and stuff (the reason to not use ListBox? Firemonkey control creation is far harder than simply do a form and embed it)
The secret is in how you design your child form.
You need to create a control as a container, say a TLayout (no styling), TRectangle (Basic styling) or TPanel. I'd go with the TLayout. Decide on a name for your container, say 'Container' for the sake of argument. Now create you child form and simply assign the Parent of Container to your parent object.
So, from your code above (I'm assuming TControlView is your child form):
procedure TfrmMain.FormCreate(Sender: TObject);
var
Control:TControlView;
begin
Control := TControlView.Create(Self);
Control.Container.parent := ListControls;
Control.Container.width := 800;
end;
You have to set the container control's ClipChildren property to true.
Here is a step by step instruction:
Design your embedded form. Place a TLayout with alignment alClient onto your form. Place all controls inside this layout:
TFormEmbedded = class(TForm)
LayoutMain: TLayout;
//....
end;
Design your master form.
Place a Layout onto your master form, that shall later contain the subform.
Add the following code to FormCreate of your master form:
procedure TFormMaster.FormCreate(Sender: TObject);
var
SubForm: TFormEmbedded;
begin
SubForm := TFormEmbedded.Create(Self);
SubForm.LayoutMain.Parent := Self.LayoutSubForm;
end;
Thanks to nexial for the original description.
I have an application having one TEdit which is disabled when the application runs. After some calculations it will be enabled. My requirement is to set the Font.Color of this disabled TEdit as Blue instead of Grey (Disabled Font Color).
This is not supported by the standard TEdit. You could set the edit to ReadOnly instead of Disabled - this way the font color is preserved but user can't change the value of the edit. Ie to "disable" the edit
Edit1.ReadOnly := True;
Edit1.Font.Color := clBlue;
and to enable it again
Edit1.ReadOnly := False;
Edit1.Font.Color := clWindowText;
See Peter Below's two suggestions for accomplishing your objective on Torry's Delphi Pages at this link. Judging from your comment about what you Googled, his first suggestion will be simpler for you to implement. Drop a TPanel on a form and drag a TEdit onto the TPanel (i.e., TPanel is TEdit's parent. Then drop a Button on the form to simulate when your calculations are done.
procedure TForm1.btnToggleEnabledClick(Sender: TObject);
begin
if Panel1.Enabled then
begin
{Calcs are not done, so disable the TEdit}
Panel1.Enabled := false;
Edit1.Font.Color := clBlue;
Edit1.Text := 'Calcs not done';
end
else
begin
{Calcs are done, so enable the TEdit}
Panel1.Enabled := true;
Edit1.Font.Color := clWindowText;
Edit1.Text := 'Calcs all done';
end;
end;