Hi,
Is it possible to set the location of the UltraMessageBox on the screen? The Windows version of messageBox always appears in the center of the screen. is it possible to set the location to be the center of the parent window?
Thanks
Hello,
Unfortunately as the UltraMessageBox is not an exposed dialog, there is no simple way to center the dialog to the invoking form. At this time, the UltraMessageBox is manually centered to the screen. If you would like to see the ability to specify the start location of the UltraMessageBox, I would suggest entering a feature request to possibly have this functionality added in a future release.
It is possible to implement this functionality on your own. Due to the protection level of the UltraMessageBox ("MessageBoxDialog") and its modal state, you will have to handle the Deactivate event on the invoking form and accessing the Form.ActiveForm to get a reference to the dialog. However, you will have to delay accessing of the Form.ActiveForm property until after the Deactivate event completes using BeginInvoke().
Try the following code:
private void Form1_Deactivate(object sender, EventArgs e) { this.BeginInvoke(new MethodInvoker(MoveMessageBox)); } private void MoveMessageBox() { Form f = Form.ActiveForm; if (f != null && f.GetType().Name == "MessageBoxDialog" && f.Owner != null) { Rectangle ownerBounds = f.Owner.Bounds; Size messageBoxSize = f.Size; Point centerOfOwner = new Point(ownerBounds.Left + ownerBounds.Width / 2, ownerBounds.Top + ownerBounds.Height / 2); Point offsetLocation = new Point(centerOfOwner.X - messageBoxSize.Width / 2, centerOfOwner.Y - messageBoxSize.Height / 2); f.Location = offsetLocation; } }
Let me know if you need any further assistance.
Chris
This is awesome.
Thanks.
You could also use the IUIElementCreationFilter.BeforeCreateChildElements for this.
You have to create your own class that inherits from UltraMessageBoxManager. Check out his post: http://community.infragistics.com/forums/p/54137/279813.aspx#279813
You can use the code from Torrey and add:
messagebox_form.Location = /* new position here */