473,320 Members | 1,969 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,320 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 6946
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.