Solved

How do you shift focus from one mdi child to another?

Posted on 2001-07-11
8
285 Views
Last Modified: 2010-04-06
How do you shift focus from one mdi child to another?

* given:
  2 mdi child forms with an alClient stringgrid and a pop-  up menu each (properties: keypreview=true)
  > mdichild1 and mdichild2

* problem:
  while focus in on mdichild1 ... a "right click event"   of the stringgrid in mdichild2 does not shift the focus from mdichild1 to mdichild2.

* what i want to happen:
  "right click event" of mdichild2 shifts the focus from mdichild1 to mdichild2 so that activemdichild=mdichild2

thanks :)
 
0
Comment
Question by:ttanyag
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 1

Expert Comment

by:alx512
ID: 6275768
In OnMouseDown event handler write this code:

procedure TForm2.StringGrid1MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  Show;
  StringGrid1.SetFocus;
end;
0
 
LVL 9

Expert Comment

by:ITugay
ID: 6276318
Hi ttanyag,

.......
implemenatation
uses
   Unit2;
........

procedure TForm3.StringGrid1MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  if Button = mbRight then
    Form2.Show; // Form2 is another MDIChild form.
end;

-----
Igor.
0
 
LVL 1

Accepted Solution

by:
piscean earned 100 total points
ID: 6279218
procedure TForm3.StringGrid1MouseDown(Sender: TObject;
 Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  if right button was pressed then
    Application.MainForm.Next;
end;
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:alx512
ID: 6279702
You accept a wrong answer, this code work only if you have two Child windows, and what will be if there are three windows?
0
 
LVL 1

Expert Comment

by:piscean
ID: 6279742
I just want to make it clear to you that repeatedly calling the Next method of a MDIParent will switch through all the child forms (no matter how many children are there).  Haven't you passed through this info in the Help file (at least...)  I wonder what happened in your code why the thing you were saying happened!  I can explain these things to you if you want info (huh!)
0
 
LVL 1

Expert Comment

by:alx512
ID: 6279759
Look:

  Form1 - MDI
  Form2 - Child
  Form3 - Child and Focused
  Form4 - Child

You click in Form2 - then Form2 must be Focused,
but your code activate the Form4.
 
0
 
LVL 1

Expert Comment

by:piscean
ID: 6284930
My answer was based on the situation given by "ttanyag".  And that definitely filled his needs so you don't have to be rude saying what I provided was incorrect ('coz it's not!).  The only missing stuff there is the checking whether mdichild2 is in focus or not.  It should be this way rather...

procedure OnMouseDownEvent;
begin
  if right_click and (application.mainform.activemdichild.handle <> handle) then
  application.mainform.next;
end;

Although what you've posted before (Form.Show) was correct, there's a rule here of avoiding duplications so I posted a different one which in turn produces the same result.  The only difference is that I've posted it as an answer and you made yours a comment so it was me that was rated.  We're in the Delphi world man ... one problem has lots of solutions. And that makes us above the others!

About your discussion on having 3 (or more) children.  You're right in saying that the answer I've provided was wrong.  But that can only be WRONG if the problem states that it really will have 3 or more forms!  BUT it was clearly stated that IT HAS ONLY TWO! I should have posted a different answer if the problem said it will have >3 children.  So I guess that cleared your discussion.

And BTW, about this ...
"Look:
Form1 - MDI
Form2 - Child ...".  This will only work on right clicks (not just clicks).  Try left click and everything goes strange ...

0
 
LVL 1

Expert Comment

by:alx512
ID: 6285018
Ok. No problem. I really try to give a common answer.
Good luck!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question