473,574 Members | 3,173 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Static Form, that work like MessageBox?

Bry
Is it possible to produce a Windows Dialog form that can be used like
MessageBox.Show Dialog(), but returns a custom object type

e.g.

myObject = MyForm.ShowDial og();

rather than

// This method doesn't return the object either and ShowDialog can't be
// overriden to make it behave like that
MyForm frmMyForm = new MyForm();
frmMyForm.ShowD ialog();

Can anyone suggest any soloution to this?

Thanks.

Dec 14 '05 #1
4 9679
Bry,

MessageBox does not have a ShowDialog method. It has a Show method
which is not related to ShowDialog at all. You can create your own class
with a static method and have it return whatever you want.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"Bry" <br*********@gm ail.com> wrote in message
news:11******** **************@ g44g2000cwa.goo glegroups.com.. .
Is it possible to produce a Windows Dialog form that can be used like
MessageBox.Show Dialog(), but returns a custom object type

e.g.

myObject = MyForm.ShowDial og();

rather than

// This method doesn't return the object either and ShowDialog can't be
// overriden to make it behave like that
MyForm frmMyForm = new MyForm();
frmMyForm.ShowD ialog();

Can anyone suggest any soloution to this?

Thanks.

Dec 14 '05 #2
The MessageBox class is not a windows form or a dialog. It's just a regular
class that happens to have a static Show method. This method instantiates a
new form object, displays it, returns the result.

So you can very easily write the same thing.

"Bry" <br*********@gm ail.com> wrote in message
news:11******** **************@ g44g2000cwa.goo glegroups.com.. .
Is it possible to produce a Windows Dialog form that can be used like
MessageBox.Show Dialog(), but returns a custom object type

e.g.

myObject = MyForm.ShowDial og();

rather than

// This method doesn't return the object either and ShowDialog can't be
// overriden to make it behave like that
MyForm frmMyForm = new MyForm();
frmMyForm.ShowD ialog();

Can anyone suggest any soloution to this?

Thanks.

Dec 14 '05 #3
If you want it to work exactly that way, where the static method you
call returns an object, the only way I can think of to do it is to use
a class inbetween the main form and the dialog box.

Code for main form:

object test = TestClass.Show( );
MessageBox.Show (test.ToString( ));

-----------------------------------------------------------------
class TestClass
{
private object whatever;
private static TestClass instance;
protected TestClass() {}
public static object Show()
{
instance = new TestClass();
TestForm tf = new TestForm();
tf.FormClosing += new FormClosingEven tHandler(tf_For mClosing);
tf.ShowDialog() ; //must use show dialog so the return waits for
the form to close
return instance.whatev er;
}

private static void tf_FormClosing( object sender,
FormClosingEven tArgs e)
{
instance.whatev er = ((TestForm)send er).whatever2;
}
}

-------------------------------
TestForm

The TestForm in this example would just have to have an instance
variable called whatever2. Hopefully this gives you a general idea of
how you could do it. You have to use .ShowDialog() on the test form so
the return line waits for the form to close to do the return.

Dec 14 '05 #4
Bry
Many thanks to all for the replies. I was under the impression the
MessageBox class was a windows form class.

Now that I've got that cleared up, I've managed to do what I was trying
to do.

Thanks.

Dec 14 '05 #5

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

Similar topics

0
284
by: .pd. | last post by:
Hello, If I have a static control and 2 forms, each of which references the static. When I return from the 2nd and go back to the first, the reference to static control appears to have been removed altogether. It disappears from the first form. If you run the following example, click "DerivedForm1" then close it (ok). Then click...
1
20966
by: Kevin Carter | last post by:
Hi there...hoping somebody can help me out because I am almost ready to pull out my hair. My problem is as follows: In a method in my main form (non MDI app), I instantiate and .Show another form. As a result of the .Show, the form's Load event is called and I have a population routine fires off. Normally, all is well and good and the...
4
1784
by: Sebastian Bargmann | last post by:
Hi, I've run into a weird problem with the form designer. I have three classes: a messagebox class and two forms (Base and Derived which is derived from Base): (note: only relevant code below)
8
4925
by: CJack | last post by:
hy, I have an mdi application, i create a child form and I want to know when a button is pressed while that child form is loaded. I have this code: private void frmTestBaby_KeyUp(object sender, System.EventArgs e) { MessageBox.Show("keyboard button pressed!"); } Following is the code to load the frmTestBaby
15
5737
by: Sharon | last post by:
I’m trying to build a generic Publisher-Subscriber that will work over the net, so I’m using the Remoting. I wish that the subscriber user will be notify about the messages sent by the remote publisher, so I used delegate that the user will be able to set on it his own function for that purpuse. The trouble is that this delegate must...
5
8895
by: Jon E. Scott | last post by:
I'm a little confused with "static" methods and how to access other unstatic methods. I'm a little new to C#. I'm testing a callback routine within a DLL and the callback function returns a string as one of the arguments. As shown below, I have no problems showing the string in the Report() method in a messagebox or console window, but...
6
3480
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, minimizes the MDI form. Why is this happening and how can I prevent it? Important thing to say is, if I use just "OK" MessageBox, it DOES NOT...
1
2026
by: Gary Brown | last post by:
Hi, I have a dialog box that must behave as MessageBox does with regard to the TopMost property. It must be TopMost if and only if the calling form is TopMost. A static method creates the dialog box. Is there a way of determining if the application is TopMost from a static method? There are some inelegant workarounds but I would...
0
973
by: Cristo4 | last post by:
I have a class that is able to detect a global key press. However, I don't seem to be able to create a working event that notifies the Form1 of a global keypress. The function "HookCallback" is static and for some reason it does work to the point of " MyAKeyWasPressed(int vkKeyCode)" displaying it's 2 messageboxes but the function in Form1...
0
7758
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...
0
8100
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. ...
0
8137
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5651
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...
0
5335
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...
0
3773
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...
0
3793
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1369
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1099
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...

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.