473,406 Members | 2,345 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Problem finding location of controls (nested)

Hi, I am having a problem finding the right location of a control if it is found on a form that is on an MDI parent.
On mouse click, i want to bring out a "pop up window" that will display extra information and options., but the form itself is being displayed in odd locations i wonder why i have iterated up until the MDI.
anyone can help please?
Thanks.

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3.  public partial class Form1 : Form
  4.     {
  5.         Point loc;
  6.         Form f = new Form();
  7.  
  8.         private void Form1_Load(object sender, EventArgs e)
  9.         {
  10.             HookEvents(this);
  11.             f.Show();
  12.             f.FormBorderStyle = FormBorderStyle.None;
  13.         }
  14.  
  15.         void HookEvents(Control c) 
  16.         {
  17.             foreach (Control s in c.Controls) 
  18.             {
  19.                 s.Click += new EventHandler(s_Click);
  20.                 if (s.HasChildren) 
  21.                 {
  22.                     HookEvents(s);
  23.                 }
  24.             }
  25.         }
  26.  
  27.         void s_Click(object sender, EventArgs e)
  28.         {
  29.             loc = new Point(0, 0);
  30.             loc = getloc((Control)sender );
  31.             f.Location = loc;
  32.             f.BringToFront();
  33.         }
  34.  
  35.         private Point getloc(Control control)
  36.         {
  37.             if (control.Parent != null)
  38.             {
  39.                 loc.Offset(control.Location);
  40.                 getloc(control.Parent);
  41.             }
  42.             return loc;
  43.         }
  44. }
  45.  
  46.  
Jul 19 '07 #1
1 1381
Plater
7,872 Expert 4TB
The Location of nested controls is in relation to their direct parent, not the overall Form.
So if you get the coord from a nested control, they'd be something like (3,3) which would mean that it's 3pixels from the top corner of it's parent control.
And then when you use them to display the popup, you're using that (3,3) against the overall Form, putting your popup in the top left area, and not right over your control.

Also you appear to be using loc in ways that could cause some values to be changed.
Jul 19 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: michael haller | last post by:
In my project i have a textfile witch i import in my c# application. The datas in the textfile i show the datas in the textfile in my datagrid..ok that ist not my problem. Now i have a...
4
by: Arif Çimen | last post by:
Hi to everybody, I have chnged a button text in design mode. But After compiling and executing the program the text of the button do not change to new value. Any Ideas? Thaks for helps.
0
by: Curtis Hatter | last post by:
I apologize if this has been answered, but on the .NET 247 site I saw a thread titled "Datagrid's ItemCommand Event", and had similar troubles with the Datagrid not properly firing the delete event...
7
by: BradC | last post by:
(VB.NET 2002, Windows app). I'm going to be provided a two-letter string like "BV" or "TP" that represents a location. I then need to perform some actions on several form controls that have...
3
by: Geraldine Hobley | last post by:
Hello, In my project I am inheriting several forms. However when I inherit from a form and add additional subroutines and methods to my inherited form I get all sorts of problems. e.g. I sometimes...
4
by: Rod Gill | last post by:
Hi, I have a form that when opened in the designer appears of the screen. The form selector can't be dragged (or resized) and if I scroll right and down to centralise it the form simply jumps...
30
by: dbuchanan | last post by:
ComboBox databindng Problem == How the ComboBox is setup and used: My comboBox is populated by a lookup table. The ValueMember is the lookup table's Id and the DisplayMember is the text from a...
10
by: Clayton | last post by:
Hi all, I'm trying to develop a server that listens to incoming calls using the asycnhronous methods BeginAccept / EndAccept. I start the server (till this point it is ok) and few seconds later...
7
by: Brad Baker | last post by:
I am trying to programmatically set a placeholder control in csharp which is nested inside a repeater control between <ItemTemplateand </ItemTemplate> tags, however I am running into problems. I've...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.