473,773 Members | 2,334 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

class reuse btween console & winforms

I have a class with a number of functions. For some form
of errors I wanted to use the MessageBox function of
Window.Forms.

I want to reuse this code in a console application, but
now I see I would have to remove all the MessageBox calls
for error messages and return the errors. Is there a way
to include that functionality in a console applic. I am
just doing the classes in console to save a bit of time.

Thanks Andrew
Nov 15 '05 #1
3 1506
"andrewcw" <an************ @boeing.com> wrote in message news:13******** *************** *****@phx.gbl.. .
Is there a way
to include that functionality in a console applic. I am
just doing the classes in console to save a bit of time.
I've not tried this, but you could try something like....

// create an interface for error UI
public interface IErrorUI {
void ShowError( string err );
}

// create WinForms version
public class WinFormsErrUI: IErrorUI{
public void ShowError( string err ){
MessageBox.Show ( "There was an error: " + err );
}
}

//create a Console Version
public class ConsoleErrUI : IErrorUI{
public void ShowError( string err ){
Console.Error.W riteLine( "There was an error: " + err );
}
}

// then, an example class
public class SomeClass{
public void DoSomething( IErrorUI errUI ){
try{
//some operation here that may throw exception
} catch( Exception e ) {
errUI.ShowError ( e.Message );
}
}
}

Quite a lot of effort doing it this way, but it may buy you flexibility. You might want to look into the Abstract Factory pattern, which could be used to instantiate the correct type (Console/WinForms) objects depending on the "mode" you're running in.

Hope this helps!

Tobin Harris

Thanks Andrew

Nov 15 '05 #2
Just add a reference of System.Windows. Forms in your console application.
and add a using statement
using System.Windows. Forms;
in your console application code. Then you can debug the console application
with MessageBoxes.

Thanks,
-Srinivaasan, M

"andrewcw" <an************ @boeing.com> wrote in message
news:13******** *************** *****@phx.gbl.. .
I have a class with a number of functions. For some form
of errors I wanted to use the MessageBox function of
Window.Forms.

I want to reuse this code in a console application, but
now I see I would have to remove all the MessageBox calls
for error messages and return the errors. Is there a way
to include that functionality in a console applic. I am
just doing the classes in console to save a bit of time.

Thanks Andrew

Nov 15 '05 #3
Thanks ! This is what I needed
-----Original Message-----
Just add a reference of System.Windows. Forms in your console application.and add a using statement
using System.Windows. Forms;
in your console application code. Then you can debug the console applicationwith MessageBoxes.

Thanks,
-Srinivaasan, M

"andrewcw" <an************ @boeing.com> wrote in message
news:13******* *************** ******@phx.gbl. ..
I have a class with a number of functions. For some form
of errors I wanted to use the MessageBox function of
Window.Forms.

I want to reuse this code in a console application, but
now I see I would have to remove all the MessageBox calls for error messages and return the errors. Is there a way to include that functionality in a console applic. I am
just doing the classes in console to save a bit of time.

Thanks Andrew

.

Nov 15 '05 #4

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

Similar topics

2
6133
by: Volly | last post by:
Helo ! I want write console application and I want to reuse my old class, but inside it is used Image class (and System.Drawing.Imaging namespace). I can't complile it. The error is: The type or namespace name 'Drawing' does not exist in the class or namespace 'System' (are you missing an assembly reference?)
3
4144
by: MuZZy | last post by:
Hi, Consider i have a class: class CTest { public static int Counter = 0; public CTest() { <...> Counter ++;
1
4806
by: noleander | last post by:
Hi. I've got a C++ program written in Visual C++ 2003. The program is trivial, created with the Program-creation wizard: used the .NET "Form" template. The program has a trivial single-pane form GUI. I've got some stdout print statements in the code ... but I cannot find where in the world the output text is appearing. For printing I tried both: printf ("Hello world\n"); and Console::Write ("Hello World\n");
6
2619
by: Robert Dobson | last post by:
In Java you can execute a single class from the command line using the command: java.exe <classname> As long as the class in question has a method declared as "public static final main( String args )" How might I execute a Visual Basic .Net class from the command line *without* building it as a separate "console" project?
3
1936
by: Trammel | last post by:
Hi, I recently upgraded to VB.net from VB6.. and woah... I feel lost :¬O One of my reasons for upgrading is I was told that VB.net can do class inheritance and subclassing easier. Would someone be so kind as to provide a small demo about classes for some
5
1966
by: Rob | last post by:
In many articles related to VB.net the word "class" is used... How many meanings are there to this word ? "possible to derived a class from another" "forms are full-fledged classes" "base class"
7
2017
by: Ant | last post by:
Hi, I'm using the Random class to return 5 random numbers which then are added to a string. When I do it in a controls event, such as button_ click, the numbers are random as expected, but when I call the random function as a method of a class, all the numbers are the same for each call to the class. For example: (Button click calls the myRandomObject.ReturnValue method) button click produces 5,5,5
6
4362
by: Joe | last post by:
We pass args to our WinForms app and would like the console to wait until the program ends before returning. For example: C:MyApp.exe -r something This returns even though the process is still running (Task manager, processes). I would like it to wait until the process is done.
15
2792
by: Michael C | last post by:
Is it possible to have an app that is both a console app and a windows app? If there are no command line switches then it will run as a console app, if there are command line switches then it will be a windows app. If I make it a windows app then I can't write to the console. If I make it a console app then it starts a console if the user runs it from the start menu so from what I see it's not possible. Thanks in advance, Michael
0
10264
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
10106
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
10039
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
8937
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...
1
7463
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6717
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5355
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4012
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
2
3610
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.