473,323 Members | 1,622 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,323 software developers and data experts.

How would I find out to which control a given control is docked against...

Hi,

Is there a way to find to which control the current control is docked
against?

For example, let's say I have panel1 and panel2 docked to left within a
form. The panel1 is the first one on the left and the panel2 is the second
one docked against panel1. I want to be able to find out to which
control/form the specified panel.

I wish, Microsoft had provided a feature similar to the following.

System.ComponentModel.IContainer DockedAgainst for all the control.

Would appreciate any input.

thanks!
-Yasutaka

Nov 15 '05 #1
8 1119
Cor
Hi Yasutaka Ito

You mean this one?

Myparent = MyControl.Parent.Name.ToString

I hope this was what you where looking for?

Cor

Is there a way to find to which control the current control is docked
against?

For example, let's say I have panel1 and panel2 docked to left within a
form. The panel1 is the first one on the left and the panel2 is the second
one docked against panel1. I want to be able to find out to which
control/form the specified panel.

I wish, Microsoft had provided a feature similar to the following.

System.ComponentModel.IContainer DockedAgainst for all the control.

Would appreciate any input.

Nov 15 '05 #2
Oops, seems like I wasn't explaining it properly.
By saying 'dock', I meant, setting the control's Dock property.

So, according to the example I gave in my previous post, I'm setting the
Dock property of panel1 and panel2. The panel1 is docked against the left of
its container (the form), and the panel2 is docked against the panel1.

The results I'm expecting from the above example is.... when I'm given
panel2, I should be able to find out as a result that it is docked against
panel1

thanks!
-Yasutaka
"Cor" <no*@non.com> wrote in message
news:Oo**************@TK2MSFTNGP11.phx.gbl...
Hi Yasutaka Ito

You mean this one?

Myparent = MyControl.Parent.Name.ToString

I hope this was what you where looking for?

Cor


Nov 15 '05 #3
Cor
Hi Yasutako,
So, according to the example I gave in my previous post, I'm setting the
Dock property of panel1 and panel2. The panel1 is docked against the left of
its container (the form), and the panel2 is docked against the panel1.
So the parent from panel1 is the form
and the parent from panel2 is panel1 I asume or maybe also the form
The results I'm expecting from the above example is.... when I'm given
panel2, I should be able to find out as a result that it is docked against
panel1


So you want to know

if (panel2.docked != Dockstyle.None)

What do I see wrong?

Cor
Nov 15 '05 #4
wow ! I thought Yasutako was pretty clear, but lets try it like this:

given a form that contains a number of panel objects ( all panels have the
form as parent ) and all panels have docked == Dockstyle.Left - how does any
given panel determine which other panel is directly to its left ?

"Cor" <no*@non.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hi Yasutako,
So, according to the example I gave in my previous post, I'm setting the
Dock property of panel1 and panel2.

The panel1 is docked against the left of
its container (the form), and the panel2 is docked against the panel1.


So the parent from panel1 is the form
and the parent from panel2 is panel1 I asume or maybe also the form
The results I'm expecting from the above example is.... when I'm given
panel2, I should be able to find out as a result that it is docked against panel1


So you want to know

if (panel2.docked != Dockstyle.None)

What do I see wrong?

Cor

Nov 15 '05 #5
I'm not sure, but I think the dock is refered always to the "container".
When an control is docked left means that the distance between the container
left border and the control left border is always constant
If you want to know which control is docked left of an other control, I
think you have to calculate all the distance between this control and all
the other controls inside the container.
"gerry" <ge**@hotmail.com> schrieb im Newsbeitrag
news:OD**************@TK2MSFTNGP11.phx.gbl...
wow ! I thought Yasutako was pretty clear, but lets try it like this:

given a form that contains a number of panel objects ( all panels have the
form as parent ) and all panels have docked == Dockstyle.Left - how does any given panel determine which other panel is directly to its left ?

"Cor" <no*@non.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hi Yasutako,
So, according to the example I gave in my previous post, I'm setting the Dock property of panel1 and panel2.

The panel1 is docked against the left of
its container (the form), and the panel2 is docked against the panel1.


So the parent from panel1 is the form
and the parent from panel2 is panel1 I asume or maybe also the form
The results I'm expecting from the above example is.... when I'm given
panel2, I should be able to find out as a result that it is docked against panel1


So you want to know

if (panel2.docked != Dockstyle.None)

What do I see wrong?

Cor


Nov 15 '05 #6
Hi Yasutaka,

There is no method in the frame work to do that.
However you can use the way the control layouts its children and found it
yourself.
Controls starts layouting the contols from the last in the Controls
collection moving backwords to the index 0. So if you can get the index of
the control in question and move form this index to the end of collection.
The control you are looking for is the first sibling with the same value for
the Dock property.

If no control is found that means the control is docked against the edge of
its parent.
The check doesn't make sense if the Dock is set to Fill or None because in
the first case it is docked against the all surrounding siblings; the second
case is obvious.

this is an example of how to do it:

public Control DockAgainst(Control ctrl)
{
if(ctrl.Dock == DockStyle.None || ctrl.Dock == DockStyle.Fill)
{
return null;
}
Control parent = ctrl.Parent;
int index = parent.Controls.GetChildIndex(ctrl);

for(int i = index + 1; i < parent.Controls.Count; i++)
{
Control nextCtrl = parent.Controls[i];
if(ctrl.Dock == nextCtrl.Dock)
{
return nextCtrl;
}
}

return null;
}
--
HTH
B\rgds
100

"Yasutaka Ito" <no****@nonexistent.com> wrote in message
news:ei*************@tk2msftngp13.phx.gbl...
Oops, seems like I wasn't explaining it properly.
By saying 'dock', I meant, setting the control's Dock property.

So, according to the example I gave in my previous post, I'm setting the
Dock property of panel1 and panel2. The panel1 is docked against the left of its container (the form), and the panel2 is docked against the panel1.

The results I'm expecting from the above example is.... when I'm given
panel2, I should be able to find out as a result that it is docked against
panel1

thanks!
-Yasutaka
"Cor" <no*@non.com> wrote in message
news:Oo**************@TK2MSFTNGP11.phx.gbl...
Hi Yasutaka Ito

You mean this one?

Myparent = MyControl.Parent.Name.ToString

I hope this was what you where looking for?

Cor

Nov 15 '05 #7
This is it! This is it! Cool! Thanks!!

Thanks a lot all of you for the big hands. Feel strong to have such fellow
developers.
Have a great day.

thanks!
-Yasutaka

"Stoitcho Goutsev (100) [C# MVP]" <10*@100.com> wrote in message
news:Oh**************@TK2MSFTNGP11.phx.gbl...
Hi Yasutaka,

There is no method in the frame work to do that.
However you can use the way the control layouts its children and found it
yourself.
Controls starts layouting the contols from the last in the Controls
collection moving backwords to the index 0. So if you can get the index of
the control in question and move form this index to the end of collection.
The control you are looking for is the first sibling with the same value for the Dock property.

If no control is found that means the control is docked against the edge of its parent.
The check doesn't make sense if the Dock is set to Fill or None because in
the first case it is docked against the all surrounding siblings; the second case is obvious.

this is an example of how to do it:

public Control DockAgainst(Control ctrl)
{
if(ctrl.Dock == DockStyle.None || ctrl.Dock == DockStyle.Fill)
{
return null;
}
Control parent = ctrl.Parent;
int index = parent.Controls.GetChildIndex(ctrl);

for(int i = index + 1; i < parent.Controls.Count; i++)
{
Control nextCtrl = parent.Controls[i];
if(ctrl.Dock == nextCtrl.Dock)
{
return nextCtrl;
}
}

return null;
}
--
HTH
B\rgds
100


Nov 15 '05 #8
I don't know if there's an easier way, but here's one way. Use the
Control.GetChildAtPoint() method on the form or container. This returns the
name of a control docked above textBox1, which is docked to the top.

One problem with it, though, is that if the controls are on a panel, it just
returns the panel. If they're on the form, it returns the control you want.
There may be a way around the panel issue, but I haven't tried to find it.

Hope this helps,

Dale

private void button2_Click(object sender, System.EventArgs e)
{
MessageBox.Show(this.GetChildAtPoint(new Point(textBox1.Left,
textBox1.Top-1)).Name);
}

"Yasutaka Ito" <no****@nonexistent.com> wrote in message
news:eq**************@TK2MSFTNGP09.phx.gbl...
Hi,

Is there a way to find to which control the current control is docked
against?

For example, let's say I have panel1 and panel2 docked to left within a
form. The panel1 is the first one on the left and the panel2 is the second
one docked against panel1. I want to be able to find out to which
control/form the specified panel.

I wish, Microsoft had provided a feature similar to the following.

System.ComponentModel.IContainer DockedAgainst for all the control.

Would appreciate any input.

thanks!
-Yasutaka

Nov 15 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Yasutaka Ito | last post by:
Hi, Is there a way to find to which control the current control is docked against? For example, let's say I have panel1 and panel2 docked to left within a form. The panel1 is the first one on...
1
by: Bob (remove 'excise-' to reply) | last post by:
I've got a form with three controls: a left-docked richtextbox, a right-docked form, and a right-docked listview. When I resize the form, the listview increases and decreases, the splitter...
4
by: Ron Vecchi | last post by:
Could someone point me in the right direction for creating a control similar to the VS solution explorer where it will auto hide and open when needed. Thanks -- Ron Vecchi
2
by: Sjaakie Helderhorst | last post by:
Hi there, I created my own user control (myControl) containing: myCaption - docked top myGrid - docked.fill (datasource: myDataset) myPanel - docked bottom This control is added to the form:...
7
by: Jportelas | last post by:
Hi everyone: I'm trying to solve a doubt, does the default TabControl provided with the ..Net framework (ver 1.1) support to disable a tabPage? somehow?? Thanks -- Jportelas.
2
by: illegal.prime | last post by:
I'm surprised that I'm only know discovering this problem, but I suppose I've never needed to change the dimension that is opposite to the docking of the control. That is, when I've docked a...
3
by: =?Utf-8?B?UmFodnlu?= | last post by:
Hi All; I am building a Windows form with multiple panels. I have a large panel as the base on the form, with a tab control on top of it, docked to fill, and multiple panels on the tab control....
12
by: Rotsey | last post by:
Hi, I have not had a good answer to this question. I put a menustrip on a form and so it is a main menu in affect. Now I put a webbrowser control on the form and set it dock fill. Of...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.