problems dynamically moving a control

EDIT: solved @ MSDN

EDIT: added whole project:

http://www.filefactory.com/file/2e3287/

http://files.filefront.com/MyMoOrar/;8536933;/file

I have this array of picture boxes that hold bitmaps representings stars. I made a textbox that resizes itself as i type text in it or delete it(representing the name of the star). I need the custom textbox control to dynamically dock beneath the star. Logically this wasn't hard except i run into trouble thats why i'm here. The textbox docks and centers itself x-wise but not y-wise. It behaves like it ignores completely the

Parent.Controls[myStarIndex].Height

bit in the following code, but it behaves perfectly regarding the x part of the point calulations, can somebody help?

edit: Link to another thread i'm using to get help: http://forums.microsoft.com/MSDN/Sh...SiteID=1&mode=1

Also more of the code that could cause this behaviour but wich i also doubt it does.

private void StarName_Resize(object sender, EventArgs e)
{

if (Parent != null)
{

Point point = new Point();
int myTextBoxIndex = Parent.Controls.GetChildIndex(this);
int myStarIndex = myTextBoxIndex - 1;

point.X = Parent.Controls[myStarIndex].Location.X + Parent.Controls[myStarIndex].Width / 2 - Width / 2;

point.Y = Parent.Controls[myStarIndex].Location.Y + Parent.Controls[myStarIndex].Height;

Location = point;

}
}

the indexes are like this:

1 4 7 10 ...these are the cusom Star controls(image boxes)

2 5 8 11 ...these are the custom StarName controls(textboxes)

3 6 9 12 ...some other control i docked above the Star control

no poblem here i debugged and saw these numbers are proper, also if they weren't the textbox controls wouldn't dock anywhere near the Star control.
[1939 byte] By [w0lfshad3] at [2007-11-20 10:41:00]
# 1 Re: problems dynamically moving a control
You presumably don't realise that this:Parent.Controls[myStarIndex].Location.Yis the same as this:Parent.Controls[myStarIndex].Topand this:Parent.Controls[myStarIndex].Location.Y + Parent.Controls[myStarIndex].Heightis the same as this:Parent.Controls[myStarIndex].BottomNow, there's some real inefficiency going on there. For a start, you're going to the Parent's Controls collection four times and getting the same control every time. If it's the same control then just get it once.

Apart from all that, I strongly suggest that you create your own UserControl. It should contain the PictureBox, the TextBox and the other control, plus the logic to resize and reposition the TextBox in relation to the PictureBox. All you have to do then is add multiple instances of that UserControl to your form and Bob's your uncle. The form doesn't have to know anything about any of that logic and neither does the TextBox. It's really a butcher job that the TextBox's internal logic relies on some other control that may or may not be on its Parent control. The UserControl should manage a set of three related controls and then the form can mange the UserControls.
jmcilhinney at 2007-11-9 11:35:48 >
# 2 Re: problems dynamically moving a control
With ".Bottom" still doesn't work but it is more efficient thanks for that.
I need to do it like this and i'm explaining next why. Still not working. So not obvious why too...

Link to another thread i'm using to get help: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2129643&SiteID=1&mode=1

Also more of the code that could cause this behaviour but wich i also doubt it does.

I allready did a custom control containing all that in a TableLayoutPanel, but, i don't want that overlapping any other controls by mistake. For instance if the textbox happens to be the widest in that control then the TableLayoutPanel width has to be that wide, and as high as the textbox + picture box + someothercontrol over the picture box 20 px high. And doing message filtering for the TableLayoutPanel looks awfully messy, not to mention that i would do it for the first time and need time researching into it.

point.Y = Parent.Controls[myStarIndex].Location.Y + Parent.Controls[myStarIndex].Height;
00000142 lea eax,[ebp-48h]
00000145 mov dword ptr [ebp-6Ch],eax
00000148 mov ecx,ebx
0000014a call 7AA3E018
0000014f mov esi,eax
00000151 mov ecx,esi
00000153 cmp dword ptr [ecx],ecx
00000155 call 7AA3E1F8
0000015a mov esi,eax
0000015c mov edx,dword ptr [ebp-50h]
0000015f mov ecx,esi
00000161 mov eax,dword ptr [ecx]
00000163 call dword ptr [eax+000000A4h]
00000169 mov esi,eax
0000016b lea edx,[ebp-74h]
0000016e mov ecx,esi
00000170 cmp dword ptr [ecx],ecx
00000172 call 7AA3E07C
00000177 lea edi,[ebp-5Ch]
0000017a lea esi,[ebp-74h]
0000017d movq xmm0,mmword ptr [esi]
00000181 movq mmword ptr [edi],xmm0
00000185 lea ecx,[ebp-5Ch]
00000188 call 7A218490
0000018d mov edi,eax
0000018f mov ecx,ebx
00000191 call 7AA3E018
00000196 mov esi,eax
00000198 mov ecx,esi
0000019a cmp dword ptr [ecx],ecx
0000019c call 7AA3E1F8
000001a1 mov esi,eax
000001a3 mov edx,dword ptr [ebp-50h]
000001a6 mov ecx,esi
000001a8 mov eax,dword ptr [ecx]
000001aa call dword ptr [eax+000000A4h]
000001b0 mov esi,eax
000001b2 mov ecx,esi
000001b4 cmp dword ptr [ecx],ecx
000001b6 call 7AA3E0F4
000001bb mov esi,eax
000001bd add edi,esi
000001bf mov edx,edi
000001c1 mov ecx,dword ptr [ebp-6Ch]
000001c4 call 7A2184B0
000001c9 nop


point.Y = Parent.Controls[myStarIndex].Bottom;
00000142 lea esi,[ebp-48h]
00000145 mov ecx,ebx
00000147 call 7A87E018
0000014c mov edi,eax
0000014e mov ecx,edi
00000150 cmp dword ptr [ecx],ecx
00000152 call 7A87E1F8
00000157 mov edi,eax
00000159 mov edx,dword ptr [ebp-50h]
0000015c mov ecx,edi
0000015e mov eax,dword ptr [ecx]
00000160 call dword ptr [eax+000000A4h]
00000166 mov edi,eax
00000168 mov ecx,edi
0000016a cmp dword ptr [ecx],ecx
0000016c call 7A883584
00000171 mov edi,eax
00000173 mov edx,edi
00000175 mov ecx,esi
00000177 call 7A0584B0
0000017c nop
w0lfshad3 at 2007-11-9 11:36:49 >