By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,671 Members | 1,393 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,671 IT Pros & Developers. It's quick & easy.

How do I combine enumerated constants?

P: n/a
Hi Gang,

I'm a long time VB programmer and in that language I now how to
combine constants. Can somebody give me the correct syntax for
combining constants in C# for the following dialog:

using Microsoft.VisualBasic;

Interaction.MsgBox("Can you even see the form yet?",
(MsgBoxStyle.Question | MsgBoxStyle.OkOnly), "Debug");

Thanks I know this is easy, but heh I'm a noob.

Thanks,
Christian

Jul 13 '08 #1
Share this Question
Share on Google+
8 Replies


P: n/a
On Sat, 12 Jul 2008 22:57:10 -0700, Christian Blackburn
<ch*****************@yahoo.comwrote:
I'm a long time VB programmer and in that language I now how to
combine constants. Can somebody give me the correct syntax for
combining constants in C# for the following dialog:

using Microsoft.VisualBasic;

Interaction.MsgBox("Can you even see the form yet?",
(MsgBoxStyle.Question | MsgBoxStyle.OkOnly), "Debug");

Thanks I know this is easy, but heh I'm a noob.
I don't understand the question. What's not working about the code you
posted?
Jul 13 '08 #2

P: n/a
Hi Peter,

Thanks for helping.
I don't understand the question. *What's not working about the code you*
posted?
Specifically I can't combine the styles question and OkOnly below:
(MsgBoxStyle.Question | MsgBoxStyle.OkOnly)

Thanks,
Christian
Jul 13 '08 #3

P: n/a
Except that you have! The code works fine for me... I get a message
box with just an OK, and a question. Note that you need to do this in
a method (here I've used the Main entry-point), otherwise you get the
error "A namespace does not directly contain members such as fields or
methods".

(note: asking a question with only one possible answer [other than
closing the form] might seem unusual...)

using Microsoft.VisualBasic;
static class Program
{
static void Main()
{
Interaction.MsgBox("Can you even see the form yet?",
MsgBoxStyle.Question | MsgBoxStyle.OkOnly, "Debug");
}
}

Note that you can drop the VB reference and use the main framework
version:

using System.Windows.Forms;
static class Program
{
static void Main()
{
MessageBox.Show("Can you even see the form yet?", "Debug",
MessageBoxButtons.OK, MessageBoxIcon.Question);
}
}

Marc
Jul 13 '08 #4

P: n/a
Hi Marc,

Thanks for all the help, I appreciate knowing how to combine constants
and do it the .net native way, because frankly the VB way was a pain
Interaction.MsgBox is certainly more than I want to type. Sometimes
object oriented programming sucks, with all that extra typing. I will
do it the native way from now on MessageBox.Show.

Thanks,
Christian
Jul 13 '08 #5

P: n/a
with all that extra typing
Well, 3 characters on the method call, but actually the VB way is
probably less chars overall, thanks to the length of MessageBoxButtons
and MessageBoxIcon

Of course, intellisense to the rescue, with [tab] auto-completion, or
alternatively the "mbox" snippet (type mbox[tab][tab]).

Marc
Jul 13 '08 #6

P: n/a
Hi Marc,

I really like the mbox thing, while I get I can make my own snippets,
do you know of a website that lists the most common built in
snippets?

Thanks,
Christian
Jul 14 '08 #7

P: n/a
You can look at them in the IDE, or at least you can in VS2008 (I don't
have 2005 to hand)...

To be honest, the most common one I use is "svm" (static void Main) -
while setting up throw-away test projects ;-p
If you do a lot of WF / WPF then the attached/dependency properties
["propa"/"propdp"] might be handy - but in most cases I find it easier
to just type ;-p

Back in C# 2, arguably the "prop" snippet was useful, but not so much in
C# 3. And I have a bespoke "nonull" - but again, most often I just type
the code I want.

Tools =Code Snippets Manager [Ctrl]+K, [Ctrl]+B.

Marc
Jul 14 '08 #8

P: n/a
Hi Marc,
You can look at them in the IDE, or at least you can in VS2008 (I don't
have 2005 to hand)...
Yes, I'm still kicking it with 2005 (I don't use new programming
languages and new applications in general, I like letting other people
find/fix the bugs, I'll come along when it's stable).
>
To be honest, the most common one I use is "svm" (static void Main) -
while setting up throw-away test projects ;-p
If you do a lot of WF / WPF then the attached/dependency properties
["propa"/"propdp"] might be handy - but in most cases I find it easier
to just type ;-p
Hey those are great, but I didn't notice any difference between propa
and propdp, am I missing something?.
Back in C# 2, arguably the "prop" snippet was useful, but not so much in
C# 3. And I have a bespoke "nonull" - but again, most often I just type
the code I want.
That's fine when you really know what you're doing :). I'm not there
yet :).
>
Tools =Code Snippets Manager [Ctrl]+K, [Ctrl]+B.
Oh boy! There's a ton of them, that's terrific. I really like
that.
Marc
Thanks,
Christian
Jul 14 '08 #9

This discussion thread is closed

Replies have been disabled for this discussion.