Multiple pages on a form

I would like from my main form open another form that is contained in the main form area and continuing having the focus on the main form, something like a MDI form. I tried to use a MDI form but I found I can't make its border invisible (BorderStyle:=BsNone). For me it's very important open the new form (like a page) without any other border and without loosing the focus. I think using a standard SDI form it is not possible keep the focus on the main form (but it's possible to hide its border). Finally, I would like to show on the main form different things (using a toolbar to choose it); I think I can get something like I want with a TabControl (or maybe with a PageControl) but I don't know how can I create different tabs with different controls (if I move a control on the TabControl, it is displayed in every tabs). Is there a component where I can put all my controls and then use it to display on the form ??? I tried with DataModule, but it hold only non-visual components.
gianlucaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

LischkeCommented:
Hi gianluca,

you already had the right idea but somehow used in wrong :-) The key for this kind of application (apart from the focus issue) is to use a page control. Below is code I'm using in a project window which can contain a variable amount of edits (just like the editor in the Delphi IDE). For your case you mainly need to change what to create (a TForm I think) and its setup.

function TProjectForm.AddEdit(const FileName: String; Focus: Boolean = False; ReadOnly: Boolean = False): TSyntaxEdit;

// adds a new page control sheet with an edit window and loads the given file
// into the edit (if file name is not empty)

var NewSheet: TTabSheet;
    NewIndex: Integer;

begin
  Result := EditFromFilename(FileName);
  if Result = nil then
  begin
    // create new sheet where the edit will be placed on
    if PageControl.PageCount > 0 then NewIndex := PageControl.ActivePage.PageIndex + 1
                                 else NewIndex := 0;
    NewSheet := TTabSheet.Create(PageControl);
    NewSheet.PageControl := PageControl;
    NewSheet.Caption := PureName(FileName);
    NewSheet.PageIndex := NewIndex;
    NewSheet.ImageIndex := ApplicationData.SystemImages.GetImageIndex(Filename, False, False, []);

    // create new editor window
    Result := TSyntaxEdit.Create(NewSheet);
    with Result do
    begin
      Parent := NewSheet;
      Keystrokes := GlobalSettings.EditorCommands;
      Cursor := crIBeam;
      Align := alClient;
      BevelEdges := [beLeft, beTop];
      BevelInner := bvNone;
      BevelKind := bkFlat;
      BorderStyle := bsNone;
      BookMarkOptions.XOffset := 24;
      CharWidth := 8;
      Ctl3D := True;
      Font.Name := GlobalSettings.EditorFontName;
      Font.Size := GlobalSettings.EditorFontSize;
      GutterWidth := 30;
      Options := GlobalSettings.EditOptions + [eoWantTabs, eoReadOnlySelection];
      if ReadOnly then Options := Options + [eoReadOnly];
      TabSize := GlobalSettings.TabSize;
      IndentSize := GlobalSettings.BlockIndent;
      MaxUndo := GlobalSettings.UndoLimit;
      MarkColor.Foreground := GlobalSettings.EditorMarkForeground;
      MarkColor.Background := GlobalSettings.EditorMarkBackground;
      MaxRightChar := 256;
      PopupMenu := EditorPopup;
      ScrollbarMode := GlobalSettings.ScrollBarMode;
      Scrollbars := ssBoth;
      if FileExists(FileName) then
      begin
        Lines.LoadFromFile(FileName);
        NewSheet.Tag := FileAge(FileName);
      end
      else NewSheet.Tag := 0;
      Modified := False;
      Info := FileName;
      Highlighter := HighlighterFromFileExt(ExtractFileExt(FileName));
      OnCaretChange := EditCaretChange;
      OnChange := EditChange;
    end;
  end;

  ReindexSheets;
  if Focus then
  begin
    PageControl.ActivePage := PageControl.Pages[Result.Tag];
    PageControlChange(PageControl);
  end;
end;


Ciao, Mike
0
RBertoraCommented:
TPageControl in the Win32 tab of the component pallette is very good especially for what you want.

have a look at it
Rob ;-)
0
RBertoraCommented:
Oh yes TPageControl : remember to right click on the component to add/remove new pages.

Rob;-)
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

karooCommented:
qianlunca,

did the same in a project i'm working on now, try this:

override the constructor and Loaded and CreateParams methods of a form ie:

protected
  procedure CreateParams(var Params: TCreateParams); override;
  procedure Loaded; override;
public
  constructor Create(AOwner: TComponent; AParent: TWinControl; override;

now the constructor:
constructor TForm1.Create(AOwner: TComponent; AParent: TWinControl;
begin
  FTempParent := AParent;
  inherited Create(AOWner);
end;

the Loaded method:
procedure TForm1.Loaded;
begin
  inherited;
  Parent := FTempParent;
  Anchors := [];
  Align := alClient;
  BorderIcons := [];
  BorderStyle := bsNone;    
end;

the CreateParams method:
procedure TForm1.CreateParams(var Params: TCreateParams);
begin
  inherited CreateParams(Params);
  {inform Windows to create the Form as a Child window}
  if FAsChild then Params.Style := Params.Style or WS_CHILD;
end;

add this form to the repository and inherit your new form from it.
Drop a TPanel on your main form and when you dynamically create the new form pass the TPanel as the AParent parameter. The new form will be created on the TPanel.

works like a charm.

regards Ben:)
0
karooCommented:
oh forgot to mention

add the private variable to form1:
private
  FTempParent: TWinControl;
0
karooCommented:
doh!

change:
>>if FAsChild then Params.Style := Params.Style or WS_CHILD;
to:
Params.Style := Params.Style or WS_CHILD;
0
RBertoraCommented:
Yuck to MDI!
Rob;-)
0
RadlerCommented:
spying...
Õ¿Õ
/o/

0
kretzschmarCommented:
its all said
0
gianlucaAuthor Commented:
Lischke answer is correct but I prefere the karoo answer because let you write your code in different units allowing a more stable and clear design. Regarding the Create method, I suppose you pass the TPanel object only to create the new form with the same dimensions, but can I use the MainForm object to do the same ?? In this way I only need to pass the owner.
0
karooCommented:
gianluca,

>>but can I use the MainForm object to do the same
yep you can pass any TWinControl as the parent,
i just like using a panel because the resizing and alligning can be encapsulated nicely... many ways to skin a cat.

Rob, i agree:)

Regards
Ben.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
LischkeCommented:
gianluca, I can't quite follow your argumentation, but this is unimportant as long as you get the answer you need...

Next time perhaps,

Ciao, Mike
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.