VS2005 DialogResult

R

rk

According to the docs, I would expect to check the result of an
OpenFileDialog in a VS 2005 CLR Windows Forms application this way:

if (openFileDialog1->ShowDialog()==
DialogResult::OK)

However, this does not work, and I have to use:

if (openFileDialog1->ShowDialog()==
System::Windows::Forms::DialogResult::OK)

Did I miss anything, or is this a bug?

Thanks
Richard
 
J

Jochen Kalmbach [MVP]

Hi rk!
According to the docs, I would expect to check the result of an
OpenFileDialog in a VS 2005 CLR Windows Forms application this way:

if (openFileDialog1->ShowDialog()==
DialogResult::OK)

However, this does not work, and I have to use:

if (openFileDialog1->ShowDialog()==
System::Windows::Forms::DialogResult::OK)

Did I miss anything, or is this a bug?

The short-version only works, if you have added

using System::Windows::Forms;

at the top (or at least before you use the above code).
Or did I miss something in your post?

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
 
C

Carl Daniel [VC++ MVP]

Jochen Kalmbach said:
Hi rk!

The short-version only works, if you have added

using System::Windows::Forms;

using namespace System::Windows::Forms;

that is...

-cd
 
R

rk

Hi Jochen,

I had added

using namespace System::Windows::Forms;

but this did not prevent the problem. I know, that

if (openFileDialog1->ShowDialog()==
System::Windows::Forms::DialogResult::OK)

and

using namespace System::Windows::Forms;
if (openFileDialog1->ShowDialog()==DialogResult::OK)

should be equivalent. So I would expect it to be a bug if they are not.

Or not?

Richard
 
J

Jochen Kalmbach [MVP]

Hi rk!
using namespace System::Windows::Forms;

but this did not prevent the problem. I know, that

if (openFileDialog1->ShowDialog()==
System::Windows::Forms::DialogResult::OK)

and

using namespace System::Windows::Forms;
if (openFileDialog1->ShowDialog()==DialogResult::OK)

should be equivalent. So I would expect it to be a bug if they are not.

What prolems do you get???
For me it works without any problems in VS2003 and VS2005...

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
 
R

R.Kaiser

Hi Jochen,

strange. When compiling

private: System::Void openToolStripMenuItem_Click(System::Object^
sender, System::EventArgs^ e) {

if (openFileDialog1->ShowDialog()== DialogResult::OK)
//System::Windows::Forms::DialogResult::OK) // this works
{
richTextBox1->LoadFile(openFileDialog1->FileName);
}
}


I get

1>c:\vs2005\projekt1\projekt1\Form1.h(156) : error C2039: 'OK': Ist
kein Element von 'System::Windows::Forms::Form::DialogResult'
1> c:\vs2005\projekt1\projekt1\Form1.h(23): Siehe Deklaration
von 'System::Windows::Forms::Form::DialogResult'
1>c:\vs2005\projekt1\projekt1\Form1.h(156) : error C2065: 'OK':
nichtdeklarierter Bezeichner
1>Das Buildprotokoll wurde unter
"file://c:\VS2005\Projekt1\Projekt1\Debug\BuildLog.htm" gespeichert.
1>Projekt1 - 2 Fehler, 0 Warnung(en)

If this works for you - what could I have done wrong?

I am using

Microsoft Visual Studio 2005
Version 8.0.50727.42 (RTM.050727-4200)
Microsoft .NET Framework
Version 2.0.50727
Installierte Edition: Professional

Thanks
Richard
 
J

Jochen Kalmbach [MVP]

Hallo R!

private: System::Void openToolStripMenuItem_Click(System::Object^
sender, System::EventArgs^ e) {

if (openFileDialog1->ShowDialog()== DialogResult::OK)
{
richTextBox1->LoadFile(openFileDialog1->FileName);
}
}


I get

1>c:\vs2005\projekt1\projekt1\Form1.h(156) : error C2039: 'OK': Ist
kein Element von 'System::Windows::Forms::Form::DialogResult'
1> c:\vs2005\projekt1\projekt1\Form1.h(23): Siehe Deklaration
von 'System::Windows::Forms::Form::DialogResult'

Ok! Now I see the problem!
You are using this inside a Form-derived class...
The Form itself contains a member called "DialogResult".
The compiler is using this member instead of the enum...

Also if you enter "::" after "DialogResult" you get the "correct" hint
(you have only "get" or "set" and no values of the enum!).

AFAIK the shortest version is:
Windows::Forms::DialogResult::OK

Inside a Form...

By the way: Es gibt auch eine deutschsprachige newsgroup für managed C++
/ C++/CLI:
microsoft.public.de.german.entwickler.dotnet.vc

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
 
R

R.Kaiser

Jochen said:
Hallo R!



Ok! Now I see the problem!
You are using this inside a Form-derived class...
The Form itself contains a member called "DialogResult".

Thanks, that would be an explanation.

But where does this member come from? I have not inserted it.
The compiler is using this member instead of the enum...

Also if you enter "::" after "DialogResult" you get the "correct" hint
(you have only "get" or "set" and no values of the enum!).

AFAIK the shortest version is:
Windows::Forms::DialogResult::OK

Inside a Form...

By the way: Es gibt auch eine deutschsprachige newsgroup für managed C++
/ C++/CLI:
microsoft.public.de.german.entwickler.dotnet.vc

Vielen Dank

Richard Kaiser
 
J

Jochen Kalmbach [MVP]

M

Marcus Heege

Regarding the scope of identifiers, C++/CLI is very picky. You are probably
facing a problem related to this. Check if you have defined something (e. g.
a member of your class) "DialogResult". This can easily cause such a
problem.

Here is another example:

#using "System.Drawing.dll"
using namespace System::Drawing;
ref struct X
{
property Size Size
{
// the line below fails even though the namespace System::Drawing is
opened
Size get() // type name Size conficts with property name Size
{
return Size();
}
// workaround
// System::Drawing::Size get() // type name Size conficts with property
name Size
// {
// return System::Drawing::Size();
// }
}
};

Marcus Heege

This code is untested. Please test it
 
J

Jochen Kalmbach [MVP]

Hi Marcus!
Regarding the scope of identifiers, C++/CLI is very picky. You are probably
facing a problem related to this. Check if you have defined something (e. g.
a member of your class) "DialogResult". This can easily cause such a
problem.

Have you a pointer to the docu???
Because the same code works perfectly in VS2003...

By the way: The member "DialgResult" is defined in
"System::Windows::Forms::Form"... so the problem occurs in *every*
Form-derived class.

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top