468,760 Members | 1,800 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,760 developers. It's quick & easy.

VS2005 DialogResult

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
Feb 28 '06 #1
11 2414
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/
Feb 28 '06 #2
"Jochen Kalmbach [MVP]" <no********************@holzma.de> wrote in message
news:u9**************@TK2MSFTNGP11.phx.gbl...
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;


using namespace System::Windows::Forms;

that is...

-cd
Feb 28 '06 #3
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
Jochen Kalmbach [MVP] schrieb:
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?

Feb 28 '06 #4
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/
Feb 28 '06 #5
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

Jochen Kalmbach [MVP] schrieb:
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...

Feb 28 '06 #6
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/
Feb 28 '06 #7
Jochen Kalmbach [MVP] schrieb:
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".


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

Feb 28 '06 #8
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.


It is a member of the "Form"-class:
http://msdn2.microsoft.com/en-us/lib...logresult.aspx

Also in the example they use
::DialogResult::OK
as a shortcut... but it does not compile...

Maybe there is a shorted way; but I do not know it currently...

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
Feb 28 '06 #9
Jochen Kalmbach [MVP] schrieb:
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.


It is a member of the "Form"-class:
http://msdn2.microsoft.com/en-us/lib...logresult.aspx
Also in the example they use
::DialogResult::OK
as a shortcut... but it does not compile...

Maybe there is a shorted way; but I do not know it currently...


Vielen Dank
Richard Kaiser
Feb 28 '06 #10
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

"rk" <rk@invalid.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
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
Jochen Kalmbach [MVP] schrieb:
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?

Feb 28 '06 #11
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/
Mar 1 '06 #12

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Frank Maxey | last post: by
2 posts views Thread by dm1608 | last post: by
1 post views Thread by Bill Cart | last post: by
2 posts views Thread by WP | last post: by
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.