I have datagridviews on windows form, i am adding records to datagridview using small add dialogs, i want them to animate in, when the user presses the button on which they are loaded. I am using
[DllImport("user32")]
static extern bool AnimateWindow(IntPtr hwnd, int time, int flags);
Source: http://www.c-sharpcorner.com/UploadFile/kirtan007/761/
The Dialogs are animating in but at the top left of the screen. I am using belowcode on the Load event of the add dialog:
//Set the Location negative values are being returned when my dialog appears
this.Location = new Point(LocationMainX + WidthOfMain, locationMainy + 10);
//Animate form
AnimateWindow(this.Handle, 750, AW_SLIDE | AW_HOR_POSITIVE);
In the Parent form i am passing its location to child add form
AddForm form = new AddForm (this.DesktopLocation)
form.ShowDialog(); //I have also noticed doing form.Show(); messes with the position of dialog
My Main Form loads within another form so I am guessing it is returning relative location. But i tried:
AddForm form = new AddForm (this.Parent.DesktopLocation)
form.ShowDialog();
this doesnt return negative values but returns (0,24) which is also incorrect. as dialog is animating about 150 pixels above parent form.
when i set the form relative too this.Parent.Parent.Location then it appears right, so i guess is there any formal way of accessing the root parent of an application rather than doing this.parent.parent…..
Per your edit, you can just use
this.ParentForminstead ofthis.Parent. Check for null, just in case, etc.Update:
Not really sure where you want this form to show up. Maybe just use some pinvoke:
And then to show the form:
The form will show up to the right of the button.