Good afternoon! Tell me, is it possible to place msgbox in the center of the panel on the form? or is it easier to create a form as a message and call it centered?
Asked
Active
Viewed 363 times
0
-
Why is this tagged c# _and_ vb.net? Which UI stack are you using? WinForms, WPF, something else? – gunr2171 Aug 13 '21 at 11:43
-
1Does this answer your question? [How do I change the MessageBox location?](https://stackoverflow.com/questions/5289148/how-do-i-change-the-messagebox-location) – gunr2171 Aug 13 '21 at 11:49
-
[How can I make MessageBox appear centered on MainForm?](https://stackoverflow.com/a/2576220/7444103) -- You can probably simplify the procedure using UI Automation's `WindowPatter.WindowOpened` event, to detect when the MessageBox Window is shown, then move it where you please, automatically (using the Event Handler). -- You can further simplify it by building your own MessageBoxes. – Jimi Aug 13 '21 at 12:10
-
You can also use [SetWinEventHook](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setwineventhook) registering [EVENT_SYSTEM_DIALOGSTART](https://learn.microsoft.com/en-us/windows/win32/winauto/event-constants), it will notify you when a Dialog is started, returning its Handle. You can then move it with `SetWindowPos()`. You can use the same procedure described here: [Move window when external application's window moves](https://stackoverflow.com/a/48812831/7444103), just replacing `EVENT_OBJECT_LOCATIONCHANGE`. – Jimi Aug 13 '21 at 14:43
1 Answers
0
You might be able to center a MessageBox
in your Panel
, but it's much easier to create a custom one. This might help you, you can play around with the Location
, the Size
and the other properties.
var myMessageBox = new Form
{
StartPosition = FormStartPosition.Manual,
ShowInTaskbar = false,
Size = new Size(400, 180),
Location = new Point(this.Location.X + panel1.Location.X + panel1.Width / 2 - 200, this.Location.Y + panel1.Location.Y + panel1.Height / 2 - 90),
Text = "MessageBox",
ShowIcon = false,
};
Label label = new Label
{
Name = "label",
Text = "Some text.",
AutoSize = true,
MaximumSize = new Size (myMessageBox.Width - 30, myMessageBox.Height),
Location = new Point(10, 65)
};
myMessageBox.Controls.Add(label);
myMessageBox.ShowDialog();