I need to change the message box location. I don't want it to be in the center of the page.
MessageBox.Show("Hello");
Normally, you can't change startup location of standard message box.
Solutions for your question:
Create your own custom message box.
There is example of creation on
CodeProject.
Complicated way using Windows Hook
Procedure (WinAPI) (KB180936).
You will need to create a new form that inherits from the MessageBox form. That is the only way to access the position properties.
There is a way to change the location, but its way too complicated for such a small task.
If you really need to change its location, you could display it, then use GetForegroundWindow to get a window handle, then MoveWindow to your desired location.
But, as I already mensioned, this is way too complicated. Just create your own form with a label on it an a "OK" button. Set the button as the default window button, and then, in Form1 do MyWndName.ShowDialog();
What you can do is to create a new window, set the property AllowsTransparency to true and set the Background to Transparent. In that window you can put a TextBlock, or a label and also add Yes/No Buttons. Set the location of this window using Canvs.SetTop(Window,TopPosition) and Canvas.SetLeft(Window,LeftPosition). next, call the window with the method Show() or ShowDialog().
Since I already use AutoIt for several other tasks in my project so I just create another thread to move the Message box
using System.Threading;
using AutoIt;
//Namespace, class, function stuffs
//New thread BEFORE create message box - safety measure
Thread autoItThread = new Thread(delegate ()
{
AutoItX.WinWait("New Message box");
AutoItX.WinMove("New Message box", "This box will be moved", 400, 300);
});
autoItThread.Start();
MessageBox.Show("This box will be moved", "New Message box");
Please note
The coordinate 400,300 is absolute. 0,0 will be top left corner.
This is screen-dependent. If you want to be exact, other code to determine location is needed
This task is to change the absolute position of the Message box rather than move it.
How to get/install AutoIt is not addressed here. Please look for instruction on that if you need to.
Related
I am using WPF NotifyIcon to create a System Tray service. When I show a messagebox, it shows up for half a second and then disappears immediately without waiting for input.
This kind of situation has happened before, and the usual advice is to use an overload which accepts a Window parameter. However, being a System Tray service, there is no window to use as a parent, and null is not accepted in its place.
Is there any way to make the MessageBox wait for user input short of creating a custom MessageBox window myself?
You don't need to create a proxy window for this. Just add MessageBoxOptions.DefaultDesktopOnly to your message box and it will fire on your desktop without disappearing.
Example
MessageBox.Show("My Message", "Title", MessageBoxButton.OK,
MessageBoxImage.Information, MessageBoxResult.OK,
MessageBoxOptions.DefaultDesktopOnly);
According to the answer here, a workaround is to actually open an invisible window and use that as the parent of the MessageBox:
Window window = new Window()
{
Visibility = Visibility.Hidden,
// Just hiding the window is not sufficient, as it still temporarily pops up the first time. Therefore, make it transparent.
AllowsTransparency = true,
Background = System.Windows.Media.Brushes.Transparent,
WindowStyle = WindowStyle.None,
ShowInTaskbar = false
};
window.Show();
...then open the MessageBox with the appropriate parameter:
MessageBox.Show(window, "Titie", "Text");
...and don't forget to close the window when you're done (possibly on application exit):
window.close();
I tried this and it works well. It's undesirable to have to open an extra window, but it's better than making your own messagebox window just for the sake of making this work.
I'm using MessageBox.Show() in a console application for a purpose. But, the header text displayed in the MessageBox is trimmed as it displays ending characters as "...".
Can I set the MessageBox window width to handle this behavior.
Please help me in this regard.
Thanks in advance.
No, in the default MessageBox its not possible to change the size of it. But if you want it, you can create your own message box. Just create a new form, put some buttons inside, in icon if you wanto and some text. And when you want it to show, just simply call ut, like you open the form
See
here
C# formatting a MessageBox
It can't be done. You have to create your own Form mimicking that behavior.
You can try to use the Win32 call SetWindowPos As suggested here.
Any idea how to display textBox control in MessageBox.
I'm working on winforms projcet c#.
Thank you in advance.
You can't. MessageBox is a special container designed to only show a message and buttons. Instead, you can create your own Form with whatever controls you want, and use .ShowDialog() on it.
You can simply add an Input box from VB.NET into your C# project.
First add Microsoft.VisualBasic to your project References, then use the following code:
string UserAnswer = Microsoft.VisualBasic.Interaction.InputBox("Your Message ", "Title", "Default Response");
And that should work properly.
It will be better to add a new Form in you application which you can customize the way you want.
and just call it from where ever required.
you could create a classic win form that looks like a message box and opening it as a modal form
perhaps using Form.ShowDialog
more info at
http://msdn.microsoft.com/en-us/library/c7ykbedk.aspx
You cannot customise the MessageBox, its better you use a popup designed using Windows Form separately and use its instance to invoke.
customPopup popup = new customPopup();
popup.ShowDialog();
Place your controls on the popup form and set their access modifiers to public if you want to access the textboxes or labels etc in your previous form.
customPopup popup = new customPopup();
popup.msgLabel.Text= "Your message";
popup.ShowDialog();
As I know there is no way to do that.
You can create a winform change it's style to look like a MessageBox and add your own controls.
Yes, as krillgar mentioned,you should create your own form. And
1. Encapsulate the form in a static class or function, so you may just call MyMessageBox.Show().
2. The textbox should have readonly=true, so the end users won't be able to change the text displayed, while they could select text and copy to clipboard.
Regarding to item 2, I believe many Windows build applications and MS Office use such approach.
using Microsoft.VisualBasic;//add reference
var Password = Interaction.InputBox("Message", "Title" ,"information in textbox", -1,-1);
In the variable "password" it receives the information that is entered from the text box.
Remember to add the reference "Microsoft.VisualBasic" in the solution explorer
Solution in here, you can create windows form and design it, set form is dialog, when you call form, it is auto show. In form you design, you set value some parameter static where other class in project, but you should set when you close form design that, OK, come back form init call show dialog, you create interval call when have == null return call, when != null you stop call back and using parameter in class static it !
I'm calling my custom dialog window with this code:
GUI.SLDialog sd = new GUI.SLDialog();
if (sd.ShowDialog() == false)
{
return;
}
But sd.ShowDialog() always returns nothing (i think), because the function breaks, but the waypoint at return; isn't reached.
Dialog is automaticly closing when I add to button:
this.DialogResult = false;//or true
Anybody know what am I doing wrong?
Thanks in advance for your help.C.H.
#edit
This is my SLDialog:
xaml: http://wklej.org/hash/9fb67fb0c7c/
cs: http://wklej.org/hash/16e3ccc6c0d/
I don't think I can tell you much here unless you post the code for the dialog but I do have a suggestion in the mean time.
Since you're already unhappy with the standard dialog boxes and customization is clearly an option why not move towards what people are coming to expect? Instead of your standard dialog why not just create a user control that lays over the rest of your UI and blurs everything out from the background? Much like a jquery dialog box you might see on a web page.
Modality is easier to control since it's just a matter of covering your entire app window with a translucent rectangle and then make the dialog window appear however you want.
Just a suggestion.
How can I create a Popup balloon like you would see from Windows Messenger or AVG or Norton or whomever?
I want it to show the information, and then slide away after a few seconds.
Edit: It needs to be blocking like Form.ShowDialog() because the program exits after displaying the notification
You can use the notifyIcon control that's part of .NET 2.0 System.Windows.Forms. That allows you to place an icon for your application in the System Tray. Then, you can call the ShowBalloonTip(int timeOut) method on that. Be sure however to first set the text, and icon properties on the notifyIcon for it to work. Small code sample:
private void button1_Click(object sender, EventArgs e)
{
this.notifyIcon1.BalloonTipText = "Whatever";
this.notifyIcon1.BalloonTipTitle = "Title";
this.notifyIcon1.Icon = new Icon("icon.ico");
this.notifyIcon1.Visible = true;
this.notifyIcon1.ShowBalloonTip(3);
}
EDIT: Ok, so notifyIcon won't work for you. My second suggestion would then be to create your own control for this. Actually, I would use a form. A simple form, with no borders, and no control box and just have a timer running so you can set the Opacity for fade in/out. Then, you can easily get the bottom right of the screen using the Rectangle Screen.PrimaryScreen.WorkingArea. Then just show your form at that position.
Don't create a modal (blocking) balloon. Please. A big part of the design of these UIs is that they are not dialogs: they're transient, potentially non-interactive elements, intended to provide incidental information to a user without necessarily interrupting their workflow. A balloon that steals focus and blocks user input would be irritating at best - if you need a dialog, then use a dialog.
The .NET 1.1 Visual Basic Power Pack had a toaster control.