Solved

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

Posted on 2001-07-11
8
284 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
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!

 
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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Internet Explorer View Settings Question 15 122
Performance of SQL statement 37 137
tvirtualstringtree freeze when load too manny images 10 80
Base1 Encode/Decode 3 86
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…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

756 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