|
-
May 7th, 2003, 11:29 PM
#1
Thread Starter
Member
Play sounds/Using WMP Control in C#
See my last post! 
here's the code for VB .net
Code:
Select Case e.KeyChar
Case "1"c, "2"c, "3"c '...to "0"c
' All valid character for use in Textbox1
' Do Nothing
Case Microsoft.VisualBasic.ControlChars.Back
' BackSpace
' Do Nothing
Case Else
' Ignore all others
e.Handled = True
End Select
How to do the same thing in C#??
Note. I'm migrating all of my VB .net projects to C# now. I wish I can learn to handle the language by doing this and wish this (my asking many questions) not to bring you guys too much problems
See my last post!
Last edited by session; May 12th, 2003 at 07:21 PM.
-
May 8th, 2003, 12:46 AM
#2
PowerPoster
Here:
Code:
// Check to see if it is a number, if not, go in and check to see if
// it is a backspace (char)8. If not a backspace, set the handled
// to true.
if(!char.IsNumber(e.KeyChar))
{
if(!(e.KeyChar == (char)8))
{
e.Handled = true;
}
}
-
May 8th, 2003, 01:32 AM
#3
Thread Starter
Member
hmmmmm... what if i just wanna let users to enter 'some' numbers eg... say, only 1, 2, 3 are allowed? and what if i don't want user to enter *any number but letters? :S
-
May 8th, 2003, 05:32 AM
#4
You can add cases together:
Code:
case 'a':
case 'b':
case 'c':
// do something
break;
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
May 8th, 2003, 10:03 AM
#5
PowerPoster
There is also the IsLetter method of the char object.
-
May 8th, 2003, 06:14 PM
#6
Thread Starter
Member
Originally posted by CornedBee
You can add cases together:
Code:
case 'a':
case 'b':
case 'c':
// do something
break;
er... what i meant was how to prevent anything other than 1, 2, 3 entered in textbox
-
May 8th, 2003, 10:04 PM
#7
Thread Starter
Member
-
May 8th, 2003, 10:46 PM
#8
PowerPoster
PHP Code:
int key;
try
{
key = int.Parse(e.KeyChar.ToString());
switch(key)
{
// Just add a return statement below each number you
// want to accept.
case 1:
return;
case 2:
return;
case 3:
return;
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
case 0:
e.Handled = true;
break;
default:
e.Handled = true;
break;
}
}
catch
{
if(e.KeyChar == (char)8)
{
return;
}
else
{
e.Handled = true;
return;
}
}
Try something like this.
Last edited by hellswraith; May 8th, 2003 at 10:50 PM.
-
May 8th, 2003, 11:02 PM
#9
Thread Starter
Member
thank you for help and it works great! btw i just got your pm after i sent an email to you. im sorry for that.
Last edited by session; May 8th, 2003 at 11:13 PM.
-
May 8th, 2003, 11:27 PM
#10
PowerPoster
Glad it works for you. There is probably more efficient ways though, I didn't take a whole lot of time on it.
-
May 9th, 2003, 05:10 AM
#11
You can of course bundle the accepted keys together just like the non-accepted. Makes for less returns
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
May 9th, 2003, 06:27 PM
#12
Thread Starter
Member
First off, I wanna make only 1, 2, 3 avaliable when a variable intNumber greater or equal to 3, when intNumber is = or < 2, only 1 and 2 is avaliable to be entered in this textBox. I'm just wondering how do I code for intNumber>=3 in C#?
Code:
if(intNumber _____ 3)
{
<code>
}
else if(intNumber _____ 2)
{
<code>
}
else
{
<code>
}
what should I put int the blanks? just put <= or >= ???
2nd-ly, what should I use in C# to replace Len function in VB .NET?
3rd,
i found these somewhere but there's no definition and explanations for those, can anyone explain for me?
Assignment: = *= /= %= += -= <<= >>= &= ^= |=
Logical AND &
Logical XOR ^
Logical OR |
Conditional AND &&
Conditional OR ||
Multiplicative * / %
Additive + -
Shift << >>
Relational and type testing < > <= >= is as
And what is the symbol/expression for not equal??? :s
Finally,
How do i use Exit Sub in C#?? break?
Thanks for help!
Last edited by session; May 9th, 2003 at 07:45 PM.
-
May 9th, 2003, 09:49 PM
#13
PowerPoster
1. <= means less than or equal to
>= means greater than or equal to
See number 3 for a lot more information about these and other operators.
2. By Len, do you mean get the length of a string? Just use the Length property of the string if that is the case. Example:
string myString = "Hello";
int stringLength = myString.Length;
// stringLength should now equal 5
3. Just a link for you:
http://msdn.microsoft.com/library/de...poperators.asp
4. Use return; That will exit the method.
-
May 9th, 2003, 09:54 PM
#14
Thread Starter
Member
-
May 9th, 2003, 11:20 PM
#15
Thread Starter
Member
oh btw, could you tell me some more useful function or stuff?
eg. (in VB/VB .NET)
InStr
Mid
ToLower (LCase)
ToUpeer (UCase)
(of the following 3, I believe we use Try... Catch... Finally...)
On Error GoTo <tag>
On Error Resume Next
resume Next
Date
Time...
Some string/variable handle functions and something that you think are basic and I should know?
Thanks a lot!
-
May 10th, 2003, 11:09 AM
#16
PowerPoster
InStr I believe is now the IndexOf method of the string itself:
int foundAt = myString.IndexOf("Hello");
You can add arguments as it is an overloaded method. You can start the search at any position in the string.
Mid is now SubString() method:
string myMidString = myWholeString.SubString(startIndex, length);
ToLower and ToUpper are pretty simple also:
string myUpperString = myOriginalString.ToUpper();
string myLowerString = myOriginalString.ToLower();
You are right, you use try...catch...finally blocks to do error handling.
To create a datetime variable:
DateTime myDateTime = DateTime.Now;
That will get the current date time. You can do a whole lot with the DateTime object, so use the intellisense to look around at its methods and properties.
The best place to look for information is at:
www.msdn.microsoft.com/library
Just do a search, and don't get discouraged if you don't find it right away...it is there...change the terms a little till you get what you need. There is very little that is not there at the msdn library.
-
May 10th, 2003, 11:29 AM
#17
Thread Starter
Member
thank you so much for help. I just added them to myu c# note!
-
May 10th, 2003, 09:18 PM
#18
Thread Starter
Member
if and #if
when i was looking around at msdn, i saw there's an introduction on #if (http://msdn.microsoft.com/library/de...poperators.asp). Just wondering what the differences are between if and #if, else and #else
A
Code:
#if (DEBUG && !VC_V7)
Console.WriteLine("DEBUG is defined");
#elif (!DEBUG && VC_V7)
Console.WriteLine("VC_V7 is defined");
#elif (DEBUG && VC_V7)
Console.WriteLine("DEBUG and VC_V7 are defined");
#else
Console.WriteLine("DEBUG and VC_V7 are not defined");
#endif
B
Code:
if (DEBUG && !VC_V7)
{Console.WriteLine("DEBUG is defined");}
else if (!DEBUG && VC_V7)
{Console.WriteLine("VC_V7 is defined");}
else if (DEBUG && VC_V7)
{Console.WriteLine("DEBUG and VC_V7 are defined");}
else
{Console.WriteLine("DEBUG and VC_V7 are not defined");}
//What are the differences between A and B
appreciate your help!
Last edited by session; May 10th, 2003 at 09:23 PM.
-
May 10th, 2003, 09:41 PM
#19
#if is a preproccesor directive. When you compile, the preprocessor goes through and evaluates your #if..#endif blocks. For example, consider your example:
Code:
#if (DEBUG && !VC_V7)
Console.WriteLine("DEBUG is defined");
#elif (!DEBUG && VC_V7)
Console.WriteLine("VC_V7 is defined");
#elif (DEBUG && VC_V7)
Console.WriteLine("DEBUG and VC_V7 are defined");
#else
Console.WriteLine("DEBUG and VC_V7 are not defined");
#endif
suppose DEBUG is true and VC_V7 is true. Your compiled code will contain only the following statement:
Code:
Console.WriteLine("DEBUG and VC_V7 are defined");
whereas if you wrote it with the standard if...endif blocks, the expressions would be evaluated at run time.
Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.
-
May 10th, 2003, 10:19 PM
#20
Thread Starter
Member
so do you mean that #if code will run before run-time :S and if code block is running during run time?
-
May 10th, 2003, 10:23 PM
#21
correct. #if...#end if is evaluated at compile time.
Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.
-
May 11th, 2003, 12:34 AM
#22
Thread Starter
Member
so what can we use #if...#end if? D'we need to do anything in compile time?
-
May 12th, 2003, 03:58 AM
#23
yay gay
imagine u have a code that u only want to run in debug mode..for example that has various debug boxes in it..u just put the code for that debug boxes inside of:
Code:
#if DEBUG
code
...
#end-if
and then when u put the project to compile to RELEASE you'll see as that boxes and things wont appear in your app and you still didnt have to go throgh all the code deleting that code that you later might want again for debuggin reasons
\m/  \m/
-
May 12th, 2003, 07:21 PM
#24
Thread Starter
Member
Thanks! 
How d'I play a sound in C#?
I tried to use Windows Media Player control it doesn't seem to work.
Code:
if(dtTimeNow.Hour==Convert.ToInt16(txtHour.Text) && dtTimeNow.Minute==Convert.ToInt16(txtMin.Text))
{
axWMP.URL="D:\type.wav";
}
and btw, how to change the information for your program (like adding author's name, company and information so when you right click on the exe file, the information will show up?)
Last edited by session; May 12th, 2003 at 10:37 PM.
-
May 13th, 2003, 03:56 AM
#25
Please post new threads for that stuff.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|