473,387 Members | 3,684 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Use MessageBox without using Form's libraries

Hi guys,

I need show an exception with a MessageBox but it take place in one project which mustn't use Form libraries. Maybe something like this.

Expand|Select|Wrap|Line Numbers
  1. public static void Main()
  2.         {
  3.             try
  4.             {
  5.                 hallo(4);
  6.             }
  7.             catch (ArgumentOutOfRangeException ex)
  8.             {
  9.                 MessageBox.Show(ex);
  10.             }
  11.  
  12.         }
  13.  
  14.         public static int hallo(int i)
  15.         {
  16.             int a;
  17.             try
  18.             {
  19.                 int[] hola = {1, 2, 3};
  20.                 a = hola[i];
  21.             }
  22.             catch (Exception ex){ throw ex; }
  23.             return a;            
  24.         }
  25.  
Thank you in advance.
Jul 21 '09 #1
5 2329
Solved, using API MessageBox you void this.
Jul 21 '09 #2
Are you designing a web form or a Windows Forms application?

If it's the latter, I recommend using a DialogResult object to embed the Messagebox and it can be coded like this example:

Expand|Select|Wrap|Line Numbers
  1. DialogResult photoWarning =
  2.                 MessageBox.Show("A photo already existis for this user." +
  3.                         " Do you want to overwrite it with a new one?",
  4.                          "Work Staff Directory",
  5.                          MessageBoxButtons.YesNo,
  6.                          MessageBoxIcon.Exclamation);
  7.  
However, I think its better to actually have a try/catch clause within your method as well as a message Box, if you have time to implement it.

Cheers
Matt
Jul 21 '09 #3
Plater
7,872 Expert 4TB
@raulbolanos
That still uses form libraries, just not the .NET wrapper libraries
Jul 21 '09 #4
Sorry for not reading all of your initial question raulbolanos but why, exactly, do you not want to use the library classes?

Have you thought of using JavaScript boxes like so:

Expand|Select|Wrap|Line Numbers
  1. string msg = "<script> confirm('" + here is my message + "')</script>";
  2. Response.Write(msg);
I know this works on web forms but I don't know if it does on Windows forms.
Worth a try though

Matt
Jul 21 '09 #5
IanWright
179 100+
mbewers1,

Javascript code certainly won't work on WinForms.
Jul 21 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Drew Lettington | last post by:
I'm making a simple call to display error messages in a MessageBox from a Windows form and the MessageBox is not behaving in a modal fashion. My modal form displays, the user clicks a button and...
4
by: Gerry Viator | last post by:
Hi all, Whats going on. Testing messagebox, text isn't showing up. Public Class Form1 Inherits System.Windows.Forms.Form #Region " Windows Form Designer generated code "
3
by: s-galit | last post by:
hi, i have a module that created a form, and the messageBox is shown in the closing event , but when the im choosing the "cancel" button in the messageBox the messageBox and also the form is...
4
by: Mystery Man | last post by:
We have developed a CSharp program that has a secondary thread that is used to perform background operations. This secondary thread may display some MessageBoxes or Forms. However, if the...
20
by: Peter E. Granger | last post by:
I'm having a strange problem (or at least it seems strange to me) trying to display a MessageBox in a VC++ .NET forms application. If I put the call to MessageBox::Show in the form's .h file, it...
13
by: Chris | last post by:
I can create Javascript confirm message boxes during page creation, etc adding them to the button attributes (many good posts on this!). But how can I add this event after the button is pressed? I...
16
by: Al Santino | last post by:
Hi, It appears displaying a messagebox in a validating event will cancel the subsequent event. In the program below, button 2's click event doesn't fire if you open a dialog box in button 1's...
4
by: TonyJ | last post by:
Hello! I have a small program that just copy a file and make some checks in main then I just want to inform the user about something by using a MessageBox. I tried to use this in the...
6
by: Goran Djuranovic | last post by:
Hi all, I have a VB.NET windows application that uses MDI form. When I try to delete a datagrid row from one of the MDI children forms, I use a MessageBox YesNo confirmation, which, after confirmed,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...

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.