This is a migrated thread and some comments may be shown as answers.

MessageBox.Show method can't be compiled.

7 Answers 263 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
algot
Top achievements
Rank 1
algot asked on 30 Nov 2011, 12:43 PM
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'

7 Answers, 1 is accepted

Sort by
0
Anthony
Telerik team
answered on 30 Nov 2011, 04:46 PM
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
0
algot
Top achievements
Rank 1
answered on 30 Nov 2011, 04:53 PM
using was added before.
See all my settings here
http://clip2net.com/s/1msdu
http://clip2net.com/s/1mseW
0
Accepted
Anthony
Telerik team
answered on 30 Nov 2011, 05:45 PM
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
0
algot
Top achievements
Rank 1
answered on 01 Dec 2011, 09:42 AM
I have another question. My message box appears in background. What shoud I do to get it in foreground?
0
Anthony
Telerik team
answered on 01 Dec 2011, 05:12 PM
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
0
algot
Top achievements
Rank 1
answered on 28 Dec 2011, 02:47 PM
Your solution works not every time I run it. Sometimes Message Box appears not in focus
See video
http://screencast.com/t/d3D0J3t5
0
Accepted
Anthony
Telerik team
answered on 28 Dec 2011, 05:14 PM
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
Tags
General Discussions
Asked by
algot
Top achievements
Rank 1
Answers by
Anthony
Telerik team
algot
Top achievements
Rank 1
Share this question
or