Click here to Skip to main content
15,893,814 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

is it set Parent window to MessageBox Alert..(Not in Javascript)?
Alert box Using DialogResult in C# coding...
Here is my code:
DialogResult result=MessageBox.Show(""+"",MessageBoxButtons.OKCancel,MessageBoxIcon.Information);
if(result==DialogResult.OK)
{///Redirect something;}
else
{///something}

above code is working fine, but if we run more than windows,alert box back to display... Through this code Is possible set front of window or parent...?

Thanks in Advance...
Posted
Updated 2-Feb-11 20:31pm
v4
Comments
ahsan sarfraz 3-Feb-11 4:06am    
pardon me but i am unable to understand the problem.

Depending on the needs you would normally would use the parameters MB_TOPMOST, MB_SYSTEMMODAL or MB_TASKMODAL with the
MsgBox 
win api method.
http://msdn.microsoft.com/en-us/library/sfw6660x%28v=vs.85%29.aspx[^]

But another solution for this is given here in an article to keep the message box on top:
TopMost MessageBox[^]

Good luck!
 
Share this answer
 
Comments
PALANI KUMAR.A 3-Feb-11 7:50am    
thank you...
PALANI KUMAR.A 3-Feb-11 23:30pm    
Hai E.F.Nijboer,
Good Morning..Special Thank to you ...
TopMostMessageBox code working well...
Have a Noce Day..
PALANI KUMAR.A 4-Feb-11 9:39am    
TopMost MessageBox,
Showing a modal dialog box or form when the application is not running in UserInteractive mode is not a valid operation. Specify the ServiceNotification or DefaultDesktopOnly style to display a notification from a service application.
E.F. Nijboer 4-Feb-11 16:29pm    
I think you need to specify the correct MessageBoxOptions to make that work. Have a look here:
http://msdn.microsoft.com/en-us/library/system.windows.forms.messageboxoptions.aspx
<pre lang="xml">&lt;pre&gt;&lt;/pre&gt;While i deploy my application...Again error....
Anybbody help and solve this problem......
Here my code...
&lt;pre lang=&quot;C++&quot;&gt;DialogResult result = TopMostMessageBox.Show(&amp;quot;Your Password will Expire in&amp;quot; + &amp;quot; &amp;quot; + Futdays + &amp;quot; &amp;quot; + &amp;quot;Day(s)&amp;quot; + &amp;#39;\n&amp;#39; + &amp;quot;Do you want Change it now?&amp;quot;, &amp;quot;Financial Management System&amp;quot;,
MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1,
MessageBoxOptions.ServiceNotification);&lt;/pre&gt;


&lt;pre lang=&quot;C++&quot;&gt;static public DialogResult Show(string message, string title, MessageBoxButtons buttons, MessageBoxIcon Icon,MessageBoxDefaultButton Btn,MessageBoxOptions Opt)
{
// Create a host form that is a TopMost window which will be the
// parent of the MessageBox.
Form topmostForm = new Form();
// We do not want anyone to see this window so position it off the
// visible screen and make it as small as possible
topmostForm.Size = new System.Drawing.Size(1, 1);
topmostForm.StartPosition = FormStartPosition.Manual;
System.Drawing.Rectangle rect = SystemInformation.VirtualScreen;
topmostForm.Location = new System.Drawing.Point(rect.Bottom + 10,
rect.Right + 10);
//topmostForm.ShowDialog();
topmostForm.Show();
// Make this form the active form and make it TopMost
topmostForm.Focus();
topmostForm.BringToFront();
topmostForm.TopMost = true;
//topmostForm.
// Finally show the MessageBox with the form just created as its owner
&lt;b&gt;DialogResult result = MessageBox.Show(topmostForm, message, title,buttons,Icon,Btn,opt);&lt;/b&gt;//////error this area...
topmostForm.Dispose(); return result;
}&lt;/pre&gt;

now Servive notifiaction error corrected.. but below error appered...
&lt;b&gt;Show a service notification messagebox with an owner window is not a valid operation.Use the shoe method that does not take an ower.Parameter name:options&lt;/b&gt;</pre>
 
Share this answer
 
Comments
E.F. Nijboer 7-Feb-11 8:15am    
This should work without errors:
MessageBox.Show("Message", "Caption", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
For the topmostForm of the TopMostMessageBox you could change the code and set the owner of the form to null.
PALANI KUMAR.A 10-Feb-11 23:43pm    
if i set topmostform null,alert will open parent window..?
DialogResult result = MessageBox.Show(topmostForm, message, title,buttons,Icon,Btn,opt)-----error line.....
If i invoke topmostform method argumemnt exceptopn error..without topmostform method no error local machine and deploying server..
Any body face this error only after deploying.. not only local machine...

Showing a modal dialog box or form when the application is not running in UserInteractive mode is not a valid operation. Specify the ServiceNotification or DefaultDesktopOnly style to display a...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900