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 | | | | re: how does MessageBox work?
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...[color=blue]
> 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
>
>[/color] | | | | re: how does MessageBox work?
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...[color=blue]
> Public class MyMessageBox
> {
> public static DialogResult Show(....)
> {
> //code here
> }
> }
>
> --
> Michael Culley
>
>
> "Saso Zagoranski" <saso.zagoranski@guest.arnes.si> wrote in message[/color]
news:bop4t0$1cl$1@planja.arnes.si...[color=blue][color=green]
> > Hi!
> >
> > I'm trying to make my own MessageBox... What I would like to know is,[/color][/color]
how[color=blue][color=green]
> > 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[/color][/color]
static[color=blue][color=green]
> > Show() method, which
> > returns a DialogResult value...
> >
> > a few tips on how to create that would be really appreciated!
> >
> > Thanks,
> > saso
> >
> >[/color]
>
>[/color] | | | | re: how does MessageBox work?
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...[color=blue]
> 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...[color=green]
> > Public class MyMessageBox
> > {
> > public static DialogResult Show(....)
> > {
> > //code here
> > }
> > }
> >
> > --
> > Michael Culley
> >
> >
> > "Saso Zagoranski" <saso.zagoranski@guest.arnes.si> wrote in message[/color]
> news:bop4t0$1cl$1@planja.arnes.si...[color=green][color=darkred]
> > > Hi!
> > >
> > > I'm trying to make my own MessageBox... What I would like to know is,[/color][/color]
> how[color=green][color=darkred]
> > > 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[/color][/color]
> static[color=green][color=darkred]
> > > Show() method, which
> > > returns a DialogResult value...
> > >
> > > a few tips on how to create that would be really appreciated!
> > >
> > > Thanks,
> > > saso
> > >
> > >[/color]
> >
> >[/color]
>
>[/color] | | | | re: how does MessageBox work?
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...[color=blue]
> No, the idea is to not create and instance of MyMessageBox. You could just[/color]
call MessageBox.Show if you like, or you could use the[color=blue]
> MessageBox API call, or you could show a form that looks like a[/color]
messagebox.[color=blue]
>
> --
> Michael Culley
>
>
> "Saso Zagoranski" <saso.zagoranski@guest.arnes.si> wrote in message[/color]
news:bop6m2$306$1@planja.arnes.si...[color=blue][color=green]
> > 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...[color=darkred]
> > > Public class MyMessageBox
> > > {
> > > public static DialogResult Show(....)
> > > {
> > > //code here
> > > }
> > > }
> > >
> > > --
> > > Michael Culley
> > >
> > >
> > > "Saso Zagoranski" <saso.zagoranski@guest.arnes.si> wrote in message[/color]
> > news:bop4t0$1cl$1@planja.arnes.si...[color=darkred]
> > > > Hi!
> > > >
> > > > I'm trying to make my own MessageBox... What I would like to know[/color][/color][/color]
is,[color=blue][color=green]
> > how[color=darkred]
> > > > 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[/color]
> > static[color=darkred]
> > > > Show() method, which
> > > > returns a DialogResult value...
> > > >
> > > > a few tips on how to create that would be really appreciated!
> > > >
> > > > Thanks,
> > > > saso
> > > >
> > > >
> > >
> > >[/color]
> >
> >[/color]
>
>[/color] | | | | re: how does MessageBox work?
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 | | | | re: how does MessageBox work?
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
[color=blue]
> MBForm form = new MBForm;
> return form.ShowDialog();[/color]
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...[color=blue]
> 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...[color=green]
> > No, the idea is to not create and instance of MyMessageBox. You could just[/color]
> call MessageBox.Show if you like, or you could use the[color=green]
> > MessageBox API call, or you could show a form that looks like a[/color]
> messagebox.[color=green]
> >
> > --
> > Michael Culley
> >
> >
> > "Saso Zagoranski" <saso.zagoranski@guest.arnes.si> wrote in message[/color]
> news:bop6m2$306$1@planja.arnes.si...[color=green][color=darkred]
> > > 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[/color][/color]
> is,[color=green][color=darkred]
> > > 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
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >[/color]
> >
> >[/color]
>
>[/color] | | | | re: how does MessageBox work?
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...[color=blue]
> Everything derives from System.Object, if something derives directly from[/color]
system.object then it is possibly simple. Have a look at[color=blue]
> how many levels there are between Form and object. In the case of the[/color]
messagebox class, it would simply call the windows api[color=blue]
> functions, so would be fairly simple.
>
> If you want to show a form as a messagebox then you should use this code
>[color=green]
> > MBForm form = new MBForm;
> > return form.ShowDialog();[/color]
>
> The ShowDialog functon returns a DialogResult enum. In your form you can[/color]
give the OK button the DialogResult property a value of[color=blue]
> DialogResult.OK and the Cancel button a value of DialogResult.Cancel.
>
> --
> Michael Culley
>
>
> "Saso Zagoranski" <saso.zagoranski@guest.arnes.si> wrote in message[/color]
news:bop7ut$44k$1@planja.arnes.si...[color=blue][color=green]
> > 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[/color][/color]
it[color=blue][color=green]
> > 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[/color][/color]
as it[color=blue][color=green]
> > looks... :)
> >
> > saso
> >
> >
> > "Michael Culley" <mculley@NOSPAMoptushome.com.au> wrote in message
> > news:eNRZkI%23pDHA.2268@TK2MSFTNGP12.phx.gbl...[color=darkred]
> > > No, the idea is to not create and instance of MyMessageBox. You could[/color][/color][/color]
just[color=blue][color=green]
> > call MessageBox.Show if you like, or you could use the[color=darkred]
> > > MessageBox API call, or you could show a form that looks like a[/color]
> > messagebox.[color=darkred]
> > >
> > > --
> > > Michael Culley
> > >
> > >
> > > "Saso Zagoranski" <saso.zagoranski@guest.arnes.si> wrote in message[/color]
> > news:bop6m2$306$1@planja.arnes.si...[color=darkred]
> > > > 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[/color][/color][/color]
message[color=blue][color=green][color=darkred]
> > > > news:bop4t0$1cl$1@planja.arnes.si...
> > > > > > Hi!
> > > > > >
> > > > > > I'm trying to make my own MessageBox... What I would like to[/color][/color][/color]
know[color=blue][color=green]
> > is,[color=darkred]
> > > > 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[/color][/color][/color]
the[color=blue][color=green][color=darkred]
> > > > static
> > > > > > Show() method, which
> > > > > > returns a DialogResult value...
> > > > > >
> > > > > > a few tips on how to create that would be really appreciated!
> > > > > >
> > > > > > Thanks,
> > > > > > saso
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >[/color]
> >
> >[/color]
>
>[/color] | | | | re: how does MessageBox work?
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:
[color=blue][color=green][color=darkred]
> > > MBForm form = new MBForm;
> > > form.ShowDialog();[/color][/color][/color]
Console.WriteLine(form.MyReturnedString);
--
Michael Culley
"Saso Zagoranski" <saso.zagoranski@guest.arnes.si> wrote in message news:bopaqc$5v3$1@planja.arnes.si...[color=blue]
> 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...[color=green]
> > Everything derives from System.Object, if something derives directly from[/color]
> system.object then it is possibly simple. Have a look at[color=green]
> > how many levels there are between Form and object. In the case of the[/color]
> messagebox class, it would simply call the windows api[color=green]
> > functions, so would be fairly simple.
> >
> > If you want to show a form as a messagebox then you should use this code
> >[color=darkred]
> > > MBForm form = new MBForm;
> > > return form.ShowDialog();[/color]
> >
> > The ShowDialog functon returns a DialogResult enum. In your form you can[/color]
> give the OK button the DialogResult property a value of[color=green]
> > DialogResult.OK and the Cancel button a value of DialogResult.Cancel.
> >
> > --
> > Michael Culley
> >
> >
> > "Saso Zagoranski" <saso.zagoranski@guest.arnes.si> wrote in message[/color]
> news:bop7ut$44k$1@planja.arnes.si...[color=green][color=darkred]
> > > 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[/color][/color]
> it[color=green][color=darkred]
> > > 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[/color][/color]
> as it[color=green][color=darkred]
> > > 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[/color][/color]
> just[color=green][color=darkred]
> > > 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[/color][/color]
> message[color=green][color=darkred]
> > > > > news:bop4t0$1cl$1@planja.arnes.si...
> > > > > > > Hi!
> > > > > > >
> > > > > > > I'm trying to make my own MessageBox... What I would like to[/color][/color]
> know[color=green][color=darkred]
> > > 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[/color][/color]
> the[color=green][color=darkred]
> > > > > static
> > > > > > > Show() method, which
> > > > > > > returns a DialogResult value...
> > > > > > >
> > > > > > > a few tips on how to create that would be really appreciated!
> > > > > > >
> > > > > > > Thanks,
> > > > > > > saso
> > > > > > >
> > > > > > >
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >[/color]
> >
> >[/color]
>
>[/color] |  | Similar C# / C Sharp bytes | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,449 network members.
|