MessageBox.Show method can't be compiled.

8 posts, 2 answers
  1. algot
    algot avatar
    57 posts
    Member since:
    Nov 2011

    Posted 30 Nov 2011 Link to this post

    Hello all.

    I'm trying to learn Telerik with following materials and can't perform following example.
    http://www.telerik.com/automated-testing-tools/support/documentation/user-guide/code-samples/general/add-messagebox.aspx

    I added System.Windows.Forms to the list of Project References but compilation of my test is failed:
    MessageBox.tstest.cs: Line 78: (CS0117) 'TestProject1.MessageBox' does not contain a definition for 'Show'
  2. Anthony
    Admin
    Anthony avatar
    19 posts

    Posted 30 Nov 2011 Link to this post

    Hi Alexander,

    You probably just need to add a using statement for System.Windows.Forms to the code-behind file. The Messagebox article has been updated with that information. 

    Regards,
    Anthony
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. algot
    algot avatar
    57 posts
    Member since:
    Nov 2011

    Posted 30 Nov 2011 Link to this post

    using was added before.
    See all my settings here
    http://clip2net.com/s/1msdu
    http://clip2net.com/s/1mseW
  4. Answer
    Anthony
    Admin
    Anthony avatar
    19 posts

    Posted 30 Nov 2011 Link to this post

    Hi Alexander,

    Thank you for the screen shots.

    The issue is with the name of your test. It matches the MessageBox command exactly. This is confusing the compiler. Once you rename the test to something different, everything should be fine. 

    Regards,
    Anthony
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. algot
    algot avatar
    57 posts
    Member since:
    Nov 2011

    Posted 01 Dec 2011 Link to this post

    I have another question. My message box appears in background. What shoud I do to get it in foreground?
  6. Anthony
    Admin
    Anthony avatar
    19 posts

    Posted 01 Dec 2011 Link to this post

    Hello Alexander,

    First I'd like you to be aware of our Manual Step feature which accomplishes the same goal without code.

    If you'd still like to continue in code, see below. First click the View Class button to see the code-behind file. Then edit your existing code to this:

    [CodedStep(@"New Coded Step")]
    public void BingMessageBox_CodedStep()
    {
        //MessageBox.Show("This is a message!");
         
        //Edit "desktop" to match your machine name
        System.Diagnostics.Process[] pro = System.Diagnostics.Process.GetProcessesByName("iexplore", "desktop");
        System.Windows.Forms.MessageBox.Show(new WindowWrapper(pro[0].MainWindowHandle),"This is a test");
    }
     
    public class WindowWrapper : System.Windows.Forms.IWin32Window
    {
        public WindowWrapper(IntPtr handle)
        {
            _hwnd = handle;
        }
         
        public IntPtr Handle
        {
            get
            {
                return _hwnd;
            }
        }
         
        private IntPtr _hwnd;
    }

    Be aware that this won't work for browsers other than IE and might not work if you have more than one instance of IE opened. 

    Regards,
    Anthony
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  7. algot
    algot avatar
    57 posts
    Member since:
    Nov 2011

    Posted 28 Dec 2011 Link to this post

    Your solution works not every time I run it. Sometimes Message Box appears not in focus
    See video
    http://screencast.com/t/d3D0J3t5
  8. Answer
    Anthony
    Admin
    Anthony avatar
    19 posts

    Posted 28 Dec 2011 Link to this post

    Hello Alexander,

    You are correct; that solution can be unreliable as it uses the iexplore process as a reference point. 

    Try this new implementation, which breaks the dependence of the separate WindowWrapper class. That class can now be removed from the code-behind file.

    Replace the contents of your coded step with the following lines:

    NativeWindow a = new NativeWindow();
    a.AssignHandle(ActiveBrowser.Window.Handle);
    System.Windows.Forms.MessageBox.Show(a, "This is a test");

    Kind regards,
    Anthony
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top