473,394 Members | 1,715 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,394 software developers and data experts.

Override MessageBox.Show

110 100+
Anyone please provide me with sample code on how do i override the MessageBox class? or more specifically MessageBox.Show()?

Thanks a LOT


Reason: I have a desktop app to which im adding a command line interface. I need to override MessageBox.Show() to not have popups based on certain conditions
Oct 14 '08 #1
6 6951
joedeene
583 512MB
I don't get what you're asking, what do you mean "Override"? Like make it whenever a messagebox is called not to show? This might be possible in your own form...If it's not what you're asking, please clarify, if you could...

joedeene

Edit: Could some mod delete this? i posted this before he added the reason, and i cant seem to delete this myself
Oct 14 '08 #2
Plater
7,872 Expert 4TB
Edit: Could some mod delete this? i posted this before he added the reason, and i cant seem to delete this myself
No reason to delete, it'll be fine.

As to the stopping of MessageBoxes, if its your code, just don't execute the code?
If you want to stop all MessageBox calls from everyprogram, well if it *can* be done, you willd need to check in with the c++/windows guys for some win32_API to stop them. Possibly a "kiosk" mode type of thing?
Oct 14 '08 #3
developing
110 100+
Sorry about the 'edit' confusion because of lack of reason. I should have added the "EDITED" caption....

Anyways, by 'override', I meant having the implementation of the override keyword. For example. ToString() is defined for every type, but you can still use the 'override' keyword and define a custom ToString() function.

I was hoping for something like that (of course, it wouldnt be using the override keyword) for MessageBox.Show()...

So I have this GUI application with three seperate classes and I am adding a command line interface to it. Everything works fine. The app can figure out when it got called by GUI and when it called throuh CLI.

I *COULD* have if statements everywhere where MessageBox.Show is used but that will get nasty in some places and seems like there has to be a better way to do it....any suggestions are appreciated

Not really sure by "kiosk' mode, but I was hoping I could provide my own implementation of MessageBox.Show to the system...
Oct 15 '08 #4
Plater
7,872 Expert 4TB
You could be abstracting out the messagebox.show.

Such as like:
Expand|Select|Wrap|Line Numbers
  1. public static void DisplayMessage(string msg)
  2. {
  3.    //some logic to determine if GUI or commandline
  4.    //if gui:
  5.    MessageBox.Show(msg);
  6.    //if commandline:
  7.    //whatever you want to do with the commandline.
  8. }
  9.  
then instead of calling MessageBox.Show(), you call DisplayMessage()
Oct 15 '08 #5
Curtis Rutland
3,256 Expert 2GB
As to specifically overriding that method, you cant. You can't derive classes from static classes, so you wouldn't be able to create a child class that you could override the method in.
Oct 15 '08 #6
developing
110 100+
Yup, I was thinking about abstracting it out too. Except that I will have to go through the source and replace MessageBox.Show()....worse comes to worse, thats what I am gonna do...

I did realize that Show is a static method...so I guess abstraction is the best way to go.

Thanks people
Oct 15 '08 #7

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

Similar topics

0
by: Bhavna | last post by:
I have a datetimepicker (dtp) on my windows form the user initially selects a date and then selects the rooms they wish to book The problem i have is that when the user goes back and tries to...
11
by: Rich Tasker | last post by:
I have a strange situation. A simple call to MessageBox.Show("XXX", "YYY") does not display the message in the messagebox with a visible font. Based on the content of the messagebox, the box...
2
by: Dennis C. Drumm | last post by:
This is a restatement of an earlier post that evidently wasn't clear. I am building a custom MessageBox dialog that has, among other things, a few new button options (yes to all, no to all, etc.)...
8
by: Saso Zagoranski | last post by:
Hi! I'm trying to make my own MessageBox... What I would like to know is, how the MessageBox class is implemented? I could have something like: new MyMessageBox().ShowDialog(); but I would...
11
by: songie D | last post by:
Does c# support overriding by name and not signature For instance I am building a custom collection class, that ca only take a certain type of object For this, I have added an override for add...
3
by: Sin | last post by:
I'm currently evaluating VC.NET as the new platform for the company I work for and things are looking grim... We're up against another IDE which took me about 5 minutes to master and I've been...
0
by: alex_f_il | last post by:
The class centers MessageBox inside the parent rectangle. Enjoy! using System; using System.Windows.Forms; using System.Text; using System.Drawing; using System.Runtime.InteropServices; ...
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...
14
by: Dave Booker | last post by:
It looks like the language is trying to prevent me from doing this sort of thing. Nevertheless, the following compiles, and I'd like to know why it doesn't work the way it should: public class...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.