473,473 Members | 1,956 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

how does MessageBox work?

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 like the solution used by MessageBox, where you call the static
Show() method, which
returns a DialogResult value...

a few tips on how to create that would be really appreciated!

Thanks,
saso
Nov 15 '05 #1
8 2421
Public class MyMessageBox
{
public static DialogResult Show(....)
{
//code here
}
}

--
Michael Culley
"Saso Zagoranski" <sa*************@guest.arnes.si> wrote in message news:bo**********@planja.arnes.si...
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 like the solution used by MessageBox, where you call the static
Show() method, which
returns a DialogResult value...

a few tips on how to create that would be really appreciated!

Thanks,
saso

Nov 15 '05 #2
Hi Michael!

I know that part... the question is what goes into the Show method?
do I create an instance of MyMessageBox in there?

"Michael Culley" <mc*****@NOSPAMoptushome.com.au> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Public class MyMessageBox
{
public static DialogResult Show(....)
{
//code here
}
}

--
Michael Culley
"Saso Zagoranski" <sa*************@guest.arnes.si> wrote in message

news:bo**********@planja.arnes.si...
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 like the solution used by MessageBox, where you call the static Show() method, which
returns a DialogResult value...

a few tips on how to create that would be really appreciated!

Thanks,
saso


Nov 15 '05 #3
No, the idea is to not create and instance of MyMessageBox. You could just call MessageBox.Show if you like, or you could use the
MessageBox API call, or you could show a form that looks like a messagebox.

--
Michael Culley
"Saso Zagoranski" <sa*************@guest.arnes.si> wrote in message news:bo**********@planja.arnes.si...
Hi Michael!

I know that part... the question is what goes into the Show method?
do I create an instance of MyMessageBox in there?

"Michael Culley" <mc*****@NOSPAMoptushome.com.au> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Public class MyMessageBox
{
public static DialogResult Show(....)
{
//code here
}
}

--
Michael Culley
"Saso Zagoranski" <sa*************@guest.arnes.si> wrote in message

news:bo**********@planja.arnes.si...
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 like the solution used by MessageBox, where you call the static Show() method, which
returns a DialogResult value...

a few tips on how to create that would be really appreciated!

Thanks,
saso



Nov 15 '05 #4
do you mean something like this:

class MBForm : Form
{
...
}

class MyMessageBox
{
public static DialogResult Show(...)
{
MBForm form = new MBForm;
form.Show();
}
}

If I do it like this I still wouldn't get any input from MBForm... and it
wouldn't make any difference if I didn't even use the MyMessageBox...
In a way, I would like a form, which I could call with a static show()
method... and would return a selected value,
when I press something on that form...

I just looked at MSDN Library and read that MessageBox derives from
System.Object... it could be that the MessageBox class isn't as simple as it
looks... :)

saso
"Michael Culley" <mc*****@NOSPAMoptushome.com.au> wrote in message
news:eN****************@TK2MSFTNGP12.phx.gbl...
No, the idea is to not create and instance of MyMessageBox. You could just call MessageBox.Show if you like, or you could use the MessageBox API call, or you could show a form that looks like a messagebox.
--
Michael Culley
"Saso Zagoranski" <sa*************@guest.arnes.si> wrote in message

news:bo**********@planja.arnes.si...
Hi Michael!

I know that part... the question is what goes into the Show method?
do I create an instance of MyMessageBox in there?

"Michael Culley" <mc*****@NOSPAMoptushome.com.au> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Public class MyMessageBox
{
public static DialogResult Show(....)
{
//code here
}
}

--
Michael Culley
"Saso Zagoranski" <sa*************@guest.arnes.si> wrote in message

news:bo**********@planja.arnes.si...
> 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 like the solution used by MessageBox, where you call the

static
> Show() method, which
> returns a DialogResult value...
>
> a few tips on how to create that would be really appreciated!
>
> Thanks,
> saso
>
>



Nov 15 '05 #5
Try
http://msdn.microsoft.com/library/de...ClassTopic.asp

protected void button1_Click(object sender, System.EventArgs e) {
if(textBox1.Text == "") {
MessageBox.Show("You must enter a name.", "Name Entry Error",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
else {
// Code to act on the data entered would go here.
}
}

You may need to change to MessageBoxButtons.OKCancel or YesNoCancel

Alternatively:
http://msdn.microsoft.com/library/de...sshowtopic.asp
private void validateUserEntry2()
{

// Checks the value of the text.

if(serverName.Text.Length == 0)
{

// Initializes the variables to pass to the MessageBox.Show
method.

string message = "You did not enter a server name. Cancel this
operation?";
string caption = "No Server Name Specified";
MessageBoxButtons buttons = MessageBoxButtons.YesNo;
DialogResult result;

// Displays the MessageBox.

result = MessageBox.Show(this, message, caption, buttons,
MessageBoxIcon.Question, MessageBoxDefaultButton.Button1,
MessageBoxOptions.RightAlign);

if(result == DialogResult.Yes)
{

// Closes the parent form.

this.Close();

}

}

}

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.537 / Virus Database: 332 - Release Date: 06/11/2003
Nov 15 '05 #6
Everything derives from System.Object, if something derives directly from system.object then it is possibly simple. Have a look at
how many levels there are between Form and object. In the case of the messagebox class, it would simply call the windows api
functions, so would be fairly simple.

If you want to show a form as a messagebox then you should use this code
MBForm form = new MBForm;
return form.ShowDialog();
The ShowDialog functon returns a DialogResult enum. In your form you can give the OK button the DialogResult property a value of
DialogResult.OK and the Cancel button a value of DialogResult.Cancel.

--
Michael Culley
"Saso Zagoranski" <sa*************@guest.arnes.si> wrote in message news:bo**********@planja.arnes.si... do you mean something like this:

class MBForm : Form
{
...
}

class MyMessageBox
{
public static DialogResult Show(...)
{
MBForm form = new MBForm;
form.Show();
}
}

If I do it like this I still wouldn't get any input from MBForm... and it
wouldn't make any difference if I didn't even use the MyMessageBox...
In a way, I would like a form, which I could call with a static show()
method... and would return a selected value,
when I press something on that form...

I just looked at MSDN Library and read that MessageBox derives from
System.Object... it could be that the MessageBox class isn't as simple as it
looks... :)

saso
"Michael Culley" <mc*****@NOSPAMoptushome.com.au> wrote in message
news:eN****************@TK2MSFTNGP12.phx.gbl...
No, the idea is to not create and instance of MyMessageBox. You could just

call MessageBox.Show if you like, or you could use the
MessageBox API call, or you could show a form that looks like a

messagebox.

--
Michael Culley
"Saso Zagoranski" <sa*************@guest.arnes.si> wrote in message

news:bo**********@planja.arnes.si...
Hi Michael!

I know that part... the question is what goes into the Show method?
do I create an instance of MyMessageBox in there?

"Michael Culley" <mc*****@NOSPAMoptushome.com.au> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
> Public class MyMessageBox
> {
> public static DialogResult Show(....)
> {
> //code here
> }
> }
>
> --
> Michael Culley
>
>
> "Saso Zagoranski" <sa*************@guest.arnes.si> wrote in message
news:bo**********@planja.arnes.si...
> > 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 like the solution used by MessageBox, where you call the
static
> > Show() method, which
> > returns a DialogResult value...
> >
> > a few tips on how to create that would be really appreciated!
> >
> > Thanks,
> > saso
> >
> >
>
>



Nov 15 '05 #7
Thanks Michael!

I get it now...

One other question... what if the form doesn't just have simple buttons and
some text... and I would like to
return a string (or something else) instead of DialogResult?

"Michael Culley" <mc*****@NOSPAMoptushome.com.au> wrote in message
news:%2*****************@TK2MSFTNGP11.phx.gbl...
Everything derives from System.Object, if something derives directly from system.object then it is possibly simple. Have a look at how many levels there are between Form and object. In the case of the messagebox class, it would simply call the windows api functions, so would be fairly simple.

If you want to show a form as a messagebox then you should use this code
MBForm form = new MBForm;
return form.ShowDialog();
The ShowDialog functon returns a DialogResult enum. In your form you can

give the OK button the DialogResult property a value of DialogResult.OK and the Cancel button a value of DialogResult.Cancel.

--
Michael Culley
"Saso Zagoranski" <sa*************@guest.arnes.si> wrote in message

news:bo**********@planja.arnes.si...
do you mean something like this:

class MBForm : Form
{
...
}

class MyMessageBox
{
public static DialogResult Show(...)
{
MBForm form = new MBForm;
form.Show();
}
}

If I do it like this I still wouldn't get any input from MBForm... and it wouldn't make any difference if I didn't even use the MyMessageBox...
In a way, I would like a form, which I could call with a static show()
method... and would return a selected value,
when I press something on that form...

I just looked at MSDN Library and read that MessageBox derives from
System.Object... it could be that the MessageBox class isn't as simple as it looks... :)

saso
"Michael Culley" <mc*****@NOSPAMoptushome.com.au> wrote in message
news:eN****************@TK2MSFTNGP12.phx.gbl...
No, the idea is to not create and instance of MyMessageBox. You could just
call MessageBox.Show if you like, or you could use the
MessageBox API call, or you could show a form that looks like a

messagebox.

--
Michael Culley
"Saso Zagoranski" <sa*************@guest.arnes.si> wrote in message

news:bo**********@planja.arnes.si...
> Hi Michael!
>
> I know that part... the question is what goes into the Show method?
> do I create an instance of MyMessageBox in there?
>
> "Michael Culley" <mc*****@NOSPAMoptushome.com.au> wrote in message
> news:%2****************@TK2MSFTNGP10.phx.gbl...
> > Public class MyMessageBox
> > {
> > public static DialogResult Show(....)
> > {
> > //code here
> > }
> > }
> >
> > --
> > Michael Culley
> >
> >
> > "Saso Zagoranski" <sa*************@guest.arnes.si> wrote in
message > news:bo**********@planja.arnes.si...
> > > 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 like the solution used by MessageBox, where you call

the > static
> > > Show() method, which
> > > returns a DialogResult value...
> > >
> > > a few tips on how to create that would be really appreciated!
> > >
> > > Thanks,
> > > saso
> > >
> > >
> >
> >
>
>



Nov 15 '05 #8
Store the string in a module level variable on the form and return it via a property. Then access that property in your Show
function:
MBForm form = new MBForm;
form.ShowDialog();
Console.WriteLine(form.MyReturnedString);

--
Michael Culley
"Saso Zagoranski" <sa*************@guest.arnes.si> wrote in message news:bo**********@planja.arnes.si...
Thanks Michael!

I get it now...

One other question... what if the form doesn't just have simple buttons and
some text... and I would like to
return a string (or something else) instead of DialogResult?

"Michael Culley" <mc*****@NOSPAMoptushome.com.au> wrote in message
news:%2*****************@TK2MSFTNGP11.phx.gbl...
Everything derives from System.Object, if something derives directly from

system.object then it is possibly simple. Have a look at
how many levels there are between Form and object. In the case of the

messagebox class, it would simply call the windows api
functions, so would be fairly simple.

If you want to show a form as a messagebox then you should use this code
MBForm form = new MBForm;
return form.ShowDialog();


The ShowDialog functon returns a DialogResult enum. In your form you can

give the OK button the DialogResult property a value of
DialogResult.OK and the Cancel button a value of DialogResult.Cancel.

--
Michael Culley
"Saso Zagoranski" <sa*************@guest.arnes.si> wrote in message

news:bo**********@planja.arnes.si... do you mean something like this:

class MBForm : Form
{
...
}

class MyMessageBox
{
public static DialogResult Show(...)
{
MBForm form = new MBForm;
form.Show();
}
}

If I do it like this I still wouldn't get any input from MBForm... and it wouldn't make any difference if I didn't even use the MyMessageBox...
In a way, I would like a form, which I could call with a static show()
method... and would return a selected value,
when I press something on that form...

I just looked at MSDN Library and read that MessageBox derives from
System.Object... it could be that the MessageBox class isn't as simple as it looks... :)

saso
"Michael Culley" <mc*****@NOSPAMoptushome.com.au> wrote in message
news:eN****************@TK2MSFTNGP12.phx.gbl...
> No, the idea is to not create and instance of MyMessageBox. You could just call MessageBox.Show if you like, or you could use the
> MessageBox API call, or you could show a form that looks like a
messagebox.
>
> --
> Michael Culley
>
>
> "Saso Zagoranski" <sa*************@guest.arnes.si> wrote in message
news:bo**********@planja.arnes.si...
> > Hi Michael!
> >
> > I know that part... the question is what goes into the Show method?
> > do I create an instance of MyMessageBox in there?
> >
> > "Michael Culley" <mc*****@NOSPAMoptushome.com.au> wrote in message
> > news:%2****************@TK2MSFTNGP10.phx.gbl...
> > > Public class MyMessageBox
> > > {
> > > public static DialogResult Show(....)
> > > {
> > > //code here
> > > }
> > > }
> > >
> > > --
> > > Michael Culley
> > >
> > >
> > > "Saso Zagoranski" <sa*************@guest.arnes.si> wrote in message > > news:bo**********@planja.arnes.si...
> > > > 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 like the solution used by MessageBox, where you call the > > static
> > > > Show() method, which
> > > > returns a DialogResult value...
> > > >
> > > > a few tips on how to create that would be really appreciated!
> > > >
> > > > Thanks,
> > > > saso
> > > >
> > > >
> > >
> > >
> >
> >
>
>



Nov 15 '05 #9

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

Similar topics

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 "
1
by: Kevin R | last post by:
I'm running the HelloWorldForm example from Microsoft to learn how to use ..net. I'm using Microsoft Visual Studio .NET 2003, 1.1 framework. I run the HelloWorldForm example. The example runs...
18
by: Daniel Billingsley | last post by:
Or seem to anyway. ===== string abc; if ((abc=getString()) != "") { MessageBox.Show(abc); } private string getString() {
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...
5
by: Robert Heuvel | last post by:
Hi, this is what I did: public struct SWaitCursor:IDisposable { public SWaitCursor (int i) { Cursor.Current = Cursors.WaitCursor; } void System.IDisposable.Dispose() { Cursor.Current =...
10
by: Russ | last post by:
I've been trying to figure out how to show a simple messagebox with an OK button in my web client program (C#). I have looked at every reference to JScript and MessageBox that seemed even remotely...
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,...
9
by: sovht | last post by:
System: Intel, Windows XP Pro, SP2 IDE: VC++ 6.0 Problem: *Very* simple program to create a MessageBox only ever displays the first character of the given string. I checked the spec for the...
19
by: Michael C | last post by:
If we have something like this object x = null; MessageBox.Show(x.ToString()) we get an error. That kindof makes sense but there is no reason the behaviour couldn't be to return an empty...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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,...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
0
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...

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.