473,385 Members | 1,356 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,385 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

Jul 21 '05 #1
8 1576
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.

Jul 21 '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


Jul 21 '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
Jul 21 '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

Jul 21 '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


Jul 21 '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

Jul 21 '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


Jul 21 '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

Jul 21 '05 #9

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

Similar topics

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
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...
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...
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...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...

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.