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

Re: how does MessageBox work? by Michael

Michael
Mon Nov 10 17:02:23 CST 2003

Public class MyMessageBox
{
public static DialogResult Show(....)
{
//code here
}
}

--
Michael Culley


"Saso Zagoranski" <saso.zagoranski@guest.arnes.si> wrote in message news:bop4t0$1cl$1@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
>
>



Re: how does MessageBox work? by Saso

Saso
Mon Nov 10 17:23:28 CST 2003

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" <mculley@NOSPAMoptushome.com.au> wrote in message
news:%23GDK069pDHA.2440@TK2MSFTNGP10.phx.gbl...
> Public class MyMessageBox
> {
> public static DialogResult Show(....)
> {
> //code here
> }
> }
>
> --
> Michael Culley
>
>
> "Saso Zagoranski" <saso.zagoranski@guest.arnes.si> wrote in message
news:bop4t0$1cl$1@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
> >
> >
>
>



Re: how does MessageBox work? by Michael

Michael
Mon Nov 10 17:26:59 CST 2003

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" <saso.zagoranski@guest.arnes.si> wrote in message news:bop6m2$306$1@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" <mculley@NOSPAMoptushome.com.au> wrote in message
> news:%23GDK069pDHA.2440@TK2MSFTNGP10.phx.gbl...
> > Public class MyMessageBox
> > {
> > public static DialogResult Show(....)
> > {
> > //code here
> > }
> > }
> >
> > --
> > Michael Culley
> >
> >
> > "Saso Zagoranski" <saso.zagoranski@guest.arnes.si> wrote in message
> news:bop4t0$1cl$1@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
> > >
> > >
> >
> >
>
>



Re: how does MessageBox work? by hirf-spam-me-here

hirf-spam-me-here
Mon Nov 10 17:29:27 CST 2003

* "Michael Culley" <mculley@NOSPAMoptushome.com.au> scripsit:
> Public class MyMessageBox
> {
> public static DialogResult Show(....)
> {

\\\
MyMessageBox foo = new MyMessageBox();
return foo.ShowDialog();

///

> }
> }

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

<http://www.plig.net/nnq/nquote.html>

Re: how does MessageBox work? by Saso

Saso
Mon Nov 10 17:45:40 CST 2003

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" <mculley@NOSPAMoptushome.com.au> wrote in message
news:eNRZkI%23pDHA.2268@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" <saso.zagoranski@guest.arnes.si> wrote in message
news:bop6m2$306$1@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" <mculley@NOSPAMoptushome.com.au> wrote in message
> > news:%23GDK069pDHA.2440@TK2MSFTNGP10.phx.gbl...
> > > Public class MyMessageBox
> > > {
> > > public static DialogResult Show(....)
> > > {
> > > //code here
> > > }
> > > }
> > >
> > > --
> > > Michael Culley
> > >
> > >
> > > "Saso Zagoranski" <saso.zagoranski@guest.arnes.si> wrote in message
> > news:bop4t0$1cl$1@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
> > > >
> > > >
> > >
> > >
> >
> >
>
>



Re: how does MessageBox work? by ukdlf

ukdlf
Mon Nov 10 18:19:22 CST 2003

Try
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemWindowsFormsMessageBoxClassTopic.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/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformsmessageboxclassshowtopic.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



Re: how does MessageBox work? by Michael

Michael
Mon Nov 10 18:18:44 CST 2003

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" <saso.zagoranski@guest.arnes.si> wrote in message news:bop7ut$44k$1@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" <mculley@NOSPAMoptushome.com.au> wrote in message
> news:eNRZkI%23pDHA.2268@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" <saso.zagoranski@guest.arnes.si> wrote in message
> news:bop6m2$306$1@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" <mculley@NOSPAMoptushome.com.au> wrote in message
> > > news:%23GDK069pDHA.2440@TK2MSFTNGP10.phx.gbl...
> > > > Public class MyMessageBox
> > > > {
> > > > public static DialogResult Show(....)
> > > > {
> > > > //code here
> > > > }
> > > > }
> > > >
> > > > --
> > > > Michael Culley
> > > >
> > > >
> > > > "Saso Zagoranski" <saso.zagoranski@guest.arnes.si> wrote in message
> > > news:bop4t0$1cl$1@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
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>



Re: how does MessageBox work? by Saso

Saso
Mon Nov 10 18:34:27 CST 2003

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" <mculley@NOSPAMoptushome.com.au> wrote in message
news:%23jx0el%23pDHA.648@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" <saso.zagoranski@guest.arnes.si> wrote in message
news:bop7ut$44k$1@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" <mculley@NOSPAMoptushome.com.au> wrote in message
> > news:eNRZkI%23pDHA.2268@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" <saso.zagoranski@guest.arnes.si> wrote in message
> > news:bop6m2$306$1@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" <mculley@NOSPAMoptushome.com.au> wrote in message
> > > > news:%23GDK069pDHA.2440@TK2MSFTNGP10.phx.gbl...
> > > > > Public class MyMessageBox
> > > > > {
> > > > > public static DialogResult Show(....)
> > > > > {
> > > > > //code here
> > > > > }
> > > > > }
> > > > >
> > > > > --
> > > > > Michael Culley
> > > > >
> > > > >
> > > > > "Saso Zagoranski" <saso.zagoranski@guest.arnes.si> wrote in
message
> > > > news:bop4t0$1cl$1@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
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>



Re: how does MessageBox work? by Michael

Michael
Mon Nov 10 20:05:14 CST 2003

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" <saso.zagoranski@guest.arnes.si> wrote in message news:bopaqc$5v3$1@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" <mculley@NOSPAMoptushome.com.au> wrote in message
> news:%23jx0el%23pDHA.648@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" <saso.zagoranski@guest.arnes.si> wrote in message
> news:bop7ut$44k$1@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" <mculley@NOSPAMoptushome.com.au> wrote in message
> > > news:eNRZkI%23pDHA.2268@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" <saso.zagoranski@guest.arnes.si> wrote in message
> > > news:bop6m2$306$1@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" <mculley@NOSPAMoptushome.com.au> wrote in message
> > > > > news:%23GDK069pDHA.2440@TK2MSFTNGP10.phx.gbl...
> > > > > > Public class MyMessageBox
> > > > > > {
> > > > > > public static DialogResult Show(....)
> > > > > > {
> > > > > > //code here
> > > > > > }
> > > > > > }
> > > > > >
> > > > > > --
> > > > > > Michael Culley
> > > > > >
> > > > > >
> > > > > > "Saso Zagoranski" <saso.zagoranski@guest.arnes.si> wrote in
> message
> > > > > news:bop4t0$1cl$1@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: