473,761 Members | 4,082 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

using System.Windows. Forms - can't find namespace?

I am using a C# solution that somebody kindly sent me.
It was a console application.

I am trying to get use of the MessageBox.

I have added the following using directive to the namespaces at the
start of the program : -

using System;
// I've added this...
using System.Windows. Forms;
//----------------------------------------------
using System.Collecti ons.Generic;
using System.Text;
using System.IO;
using System.Text.Reg ularExpressions ;

However i get a compile error that the type of namespace windows does
not exist.
I have selected the properties of the project and changed the output to
console, but that didn't help.

Why am i getting that error?

Thanks,

Gary-

Dec 12 '06 #1
9 13339
That should have read changed the output to 'windows'
TIA,

Gary-

garyuse...@mywa y.com wrote:
I am using a C# solution that somebody kindly sent me.
It was a console application.

I am trying to get use of the MessageBox.

I have added the following using directive to the namespaces at the
start of the program : -

using System;
// I've added this...
using System.Windows. Forms;
//----------------------------------------------
using System.Collecti ons.Generic;
using System.Text;
using System.IO;
using System.Text.Reg ularExpressions ;

However i get a compile error that the type of namespace windows does
not exist.
I have selected the properties of the project and changed the output to
console, but that didn't help.

Why am i getting that error?

Thanks,

Gary-
Dec 12 '06 #2
Hello,

You need to add a reference to System.Windows. Forms.dll to your project.
Right-click the References node in Solution Explorer in Visual Studio to
do that.
Oliver Sturm
--
http://www.sturmnet.org/blog
Dec 12 '06 #3
Many Thanks Oliver,

Gary-

Oliver Sturm wrote:
Hello,

You need to add a reference to System.Windows. Forms.dll to your project.
Right-click the References node in Solution Explorer in Visual Studio to
do that.
Oliver Sturm
--
http://www.sturmnet.org/blog
Dec 12 '06 #4
I'm still pretty new to programming using C# and the .NET environment,
but to knowledge you can't simply add the System.Windows. Forms
namespace to a console application and be able to make use of the
WinForms controls.

I'm sure someone else can elaborate on this more.
-- Lance

ga********@mywa y.com wrote:
I am using a C# solution that somebody kindly sent me.
It was a console application.

I am trying to get use of the MessageBox.

I have added the following using directive to the namespaces at the
start of the program : -

using System;
// I've added this...
using System.Windows. Forms;
//----------------------------------------------
using System.Collecti ons.Generic;
using System.Text;
using System.IO;
using System.Text.Reg ularExpressions ;

However i get a compile error that the type of namespace windows does
not exist.
I have selected the properties of the project and changed the output to
console, but that didn't help.

Why am i getting that error?

Thanks,

Gary-
Dec 12 '06 #5
Hello Lance,
>I'm still pretty new to programming using C# and the .NET environment,
but to knowledge you can't simply add the System.Windows. Forms
namespace to a console application and be able to make use of the
WinForms controls.

I'm sure someone else can elaborate on this more.
Well, yes you can. What makes you think you can't? Try it!
Oliver Sturm
--
http://www.sturmnet.org/blog
Dec 13 '06 #6
As I said I'm still very new and learning. You are right it is
possible, so I stand corrected.

Thanks,
-- Lance

Oliver Sturm wrote:
Hello Lance,
I'm still pretty new to programming using C# and the .NET environment,
but to knowledge you can't simply add the System.Windows. Forms
namespace to a console application and be able to make use of the
WinForms controls.

I'm sure someone else can elaborate on this more.

Well, yes you can. What makes you think you can't? Try it!
Oliver Sturm
--
http://www.sturmnet.org/blog
Dec 13 '06 #7
Lance,

Not so fast. You may have been right the first time. There is a
critical piece of code that is automatically generated by VS when you
create windows project that is not created for a console project. All
windows controls and forms must be hosted on a thread with a message
loop for them to work correctly. A call to Application.Run will set
that up for you.

Brian

Lance wrote:
As I said I'm still very new and learning. You are right it is
possible, so I stand corrected.

Thanks,
-- Lance
Dec 13 '06 #8
Hello Brian,

It seems to me that this is all becoming a matter of definition now - the
OP's question was clear and the answer pretty simple.

The general question "can I add a reference to System.Windows. Forms.dll to
a console application and use Windows Forms controls" must clearly be
answered "yes", if you ask me - for instance you can add said reference
and use a line like

MessageBox.Show ("Hi");

in your console application without doing anything else, and a lot of more
complex things are also possible.

The question "what may be a list of things I need to do to fully convert
my existing console app to a Windows Forms one" wasn't asked here.
Obviously that list could be pretty long, depending on the existing
functionality implemented for the console app, and yes, it would most
probably contain the entry "add Application.Run (...)" somewhere in your
code.
Oliver Sturm
--
http://www.sturmnet.org/blog
Dec 13 '06 #9
Oliver,

Yeah, I was definitely being pedantic. Too much so perhaps.

Brian

Oliver Sturm wrote:
Hello Brian,

It seems to me that this is all becoming a matter of definition now - the
OP's question was clear and the answer pretty simple.

The general question "can I add a reference to System.Windows. Forms.dll to
a console application and use Windows Forms controls" must clearly be
answered "yes", if you ask me - for instance you can add said reference
and use a line like

MessageBox.Show ("Hi");

in your console application without doing anything else, and a lot of more
complex things are also possible.

The question "what may be a list of things I need to do to fully convert
my existing console app to a Windows Forms one" wasn't asked here.
Obviously that list could be pretty long, depending on the existing
functionality implemented for the console app, and yes, it would most
probably contain the entry "add Application.Run (...)" somewhere in your
code.
Oliver Sturm
--
http://www.sturmnet.org/blog
Dec 13 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1872
by: Simon | last post by:
I need call a LoginUser API from MC++ dll, but when I try to call the I have always the same exception: "System.NullReferenceException: Object reference not set to an instance of an object. at LogonUser(String lpszUsername, String lpszDomain, String lpszPassword, Int32 dwLogonType, Int32 dwLogonProvider, IntPtr phToken)" Thanks in advance
3
4263
by: Richard | last post by:
I have a requirement to put a GDI style circle or rectangle border around the selected row of a datagrid/ It will overlap into the row above and below the selected row. Doing this in a the OnPaint of a subclassed DataGridTextBoxColum dos not seem like a practical way to do it. I have subclassed a DataGrid and overridden the OnPaint as such:
8
2243
by: Burt | last post by:
I am new to VC++ and .NET, so this is a pretty basic question... I want to use OpenFileDialog. Where is the header for it? And in general, how do I find the right header to include in cases like this within .NET? I would thought that #include <OpenFileDialog.h> would do the trick, but there ain't no such beast apparently.
1
1822
by: Chung | last post by:
Hi I am trying to create a Web applicatiion by using windows user control. I am having problem when I trying to load the web page, I got blank screen with a broken image. It is like the web page trying to load an image but the file is not in the Folder. I have set the Execute Permissions to Scipts only in IIS. I have also checked the index.html and Win_Ctrl_Lib.dll
5
1605
by: Davíð Þórisson | last post by:
I've never understood fully, why do I have to td eg: using system; using system.data; I would have thought that the top line imports system and all of its submembers, including data??
14
5802
by: pmud | last post by:
Hi, I need to use an Excel Sheet in ASP.NET application so that the users can enter (copy, paste ) large number of rows in this Excel Sheet. Also, Whatever the USER ENETRS needs to go to the SQL DATABASE, probably by the click of a button. Is this possible? & what is the BEST APPROACH for doing this? & also if any links are there do tell those to me too coz I have no idea how to go about doing it.
8
3924
by: Gary | last post by:
I'm using an Act database. I was stuck on this a year ago and am still having trouble. I have three bits of code like so : - act.CActAppObj objACT = new act.CActAppObj(); act.CAIBaseView objBaseView = new act.CAIBaseView(); act.CAIViews objViewsCollection = new act.CAIViews();
2
4409
by: lewisms | last post by:
Hello all, I am quite new to c++/. Net so please don't shoot me down for being a newbie. Any way I am trying to make a simple multithreading program that is just to learn the ideas behind it (before I incorporate them in another program). I just can’t seem to get a non-static call to work in my thread that has access to the Form1 variables and controls I need. I can call a non-static function using another class but then I can seem to get in...
3
4846
by: David K in San Jose | last post by:
I'm using managed (CLR) C++ in VS2005 to create a Windows app that contains a form named "MyForm". In the code for that form I'm trying to invoke some static functions by using an array of function pointers (delegates). I assume I need to use the array< T keyword to allocate an array of delegates, and then initialize the array by setting each array element to the pointers (handles) of the functions I'll be invoking. I've been trying to...
0
9336
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10111
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9948
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9902
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8770
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5364
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3866
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3446
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2738
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.