1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Floating and Position-controlled Dialog Box

Discussion in 'C#' started by Coffee99, Apr 22, 2007.

  1. Coffee99

    Coffee99 New Member

    Joined:
    Apr 22, 2007
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    I'm new to C# but I need to make a floating messagebox that I can position from the code. My code so far pops up the message box and waits for user input. But it does not float above other windows and it does not come up where I want it to. So far I have:

    DialogResult dir = MessageBox.Show("Keep Going?", "Coninue" ,MessageBoxButtons.YesNoCancel);
    if (dir == DialogResult.No)
    {
    Console.WriteLine(" We are NOT done " ) ;
    }


    Thanks for your help.
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,283
    Likes Received:
    364
    Trophy Points:
    83
    You need to specify the parent window to the MessageBox to make it above the current window.

    Something like
    Code:
    MessageBox.Show (IWin32Window, String, String, MessageBoxButtons) 
    Displays a message box in front of the specified object identified by IWin32Window and rest of the params are same as used by you.
     
  3. Coffee99

    Coffee99 New Member

    Joined:
    Apr 22, 2007
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    The field "IWin32Window" is unknown to compiler. Do I need ot incldue another "using " ?
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,283
    Likes Received:
    364
    Trophy Points:
    83
    What do you mean by unknown to compiler.
     
  5. Coffee99

    Coffee99 New Member

    Joined:
    Apr 22, 2007
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    I get error:

    System.Windows.Forms.IWin32Window is a 'type' but used like a variable

    Not sure what to do.

    gary
     
  6. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,283
    Likes Received:
    364
    Trophy Points:
    83
    That is the type of parameter and you need to pass the this pointer provided you are calling the function in the Window class (Form or something similar)
     

Share This Page