|
Hi,
Ive been playing with the culturalInfo example provided in MSDN, and although I understand it, I dont understand what need there is for it.
If I have the following code:
TextBox1.Text = DateTime.Now.ToString("D");
I still get the correct date format, whether my Windows Regional Settings are set to English or Hungarian.
So why do I need the CulturalInfo class?
Regards
Mark
|
|
|
|
|
Whenever a value is formatted or parsed in a way that can be culturally dependent, a CultureInfo or a FormatInfo object is used. Even if you don't specify one, one is used. Every time, without exception.
For an example, this statement:
TextBox1.Text = DateTime.Now.ToString("D");
is equivalent to:
TextBox1.Text = DateTime.Now.ToString("D", CultureInfo.CurrentCulture);
Sometimes you want the format to use the current culture of the user, but sometimes you want a specific format that is independent of the culture. For that you can specify a custom format, create a specific CultureInfo or FormatInfo object, or use CultureInfo.InvariantCulture.
---
b { font-weight: normal; }
|
|
|
|
|
Here is a concrete example:
We had an application that was crashing on one device but worked fine with all the others.
The problem was coming from the culture and the parsing of a string. All the devices were in english excepted the one that kept crashing who was a French Pocket PC french. When we did something like Double.Parse("2.00") it would crash on the french device because the decimal separator in that culture is a comma and not a dot...
|
|
|
|
|
Hi Monkey,
so what was the answer to this? How did you fix the statement Double.Parse("2.00") to be multicultural?
|
|
|
|
|
There is two solution to that particular problem:
-generate number according to the culture info (myDouble.ToString() does that). In that case the number is generated with the current culture and can be parsed with Double.Parse() because it's the same culture (the current culture)
- Double.Parse is surcharged, it has a version with a second parameter which specify how to parse it. I don't have visual studio right now so I can't tell what it is but you can look it up.
That makes ou feel very dumb when you find such bug : what I'm not even able to do such a basic thing as parsing number!?!
|
|
|
|
|
how can i exit event handler..and dont execute code in this event handler when some condition occurs
|
|
|
|
|
Use the return statement
--------------------------------------------------------
My portfolio & development blog
Q:What does the derived class in C# tell to it's parent?
A:All your base are belong to us!
|
|
|
|
|
if(Condition is true)
{
e.handle=true;
return ;
}
sameer
|
|
|
|
|
Please help me,
I have a final year project on Audio Video Logging System.
I basically want to do some motion detection, for which i have got some articles from CodeProject.com... this is the only small part of my Project
A big issue is that i want to do indexing on Video ie i want to do "Content Base Retrivel of Audio & Vedio Data"..
I have a server which always capturing Video in a office room, say, and store it in a database.... now if i want to do query on thoes store video, How can i do it.... Please help me.....
Any suggesstion will be appreciated.....
aLi
|
|
|
|
|
first we need to know how they are stored
It is Good to be Important but!
it is more Important to be Good
|
|
|
|
|
Hi,
How can i randomly add text in 50 labels at once instead of one at the time?
The labels are called:
label1
label2
label3
......
......
label50
Thanks in advance!
|
|
|
|
|
Wow, 50 labels, that must be one big form
Anyway, this should work:
<br />
foreach(Control label in this.Controls)<br />
{<br />
if(label.GetType().ToString() == "System.Windows.Forms.Label")<br />
{<br />
label.Text = "Hello";<br />
}<br />
}<br />
|
|
|
|
|
Hi The Undefeated,
Thank you very much for your reply!
Its going to be a calculation application for the kids
Instead of "Hello" how can i randomly give it sums like this:
2+6=
5+4=
....
....
Thanks in advance!
|
|
|
|
|
Hmm, you could do this then:
<br />
Random rnd = new Random();<br />
<br />
foreach(Control label in this.Controls)<br />
{<br />
if(label.GetType().ToString() == "System.Windows.Forms.Label")<br />
{<br />
label.Text = rnd.Next(0, 20) + " + " + rnd.Next(0, 20) + " =";<br />
}<br />
}<br />
on the rnd.Next part, you have to set the minimum and maximum values (in this case 0 and 20)
If you wanted to include minus questions to could do this:
Random rnd = new Random();<br />
Random sign = new Random();<br />
<br />
foreach(Control label in this.Controls)<br />
{<br />
switch(sign.Next(0, 2).ToString())<br />
{<br />
case "0": <br />
if(label.GetType().ToString() == "System.Windows.Forms.Label")<br />
{<br />
label.Text = rnd.Next(0, 20) + " + " + rnd.Next(0, 20) + " =";<br />
}<br />
break;<br />
<br />
case "1":<br />
if(label.GetType().ToString() == "System.Windows.Forms.Label")<br />
{<br />
int large = rnd.Next(1, 20); <br />
int small = rnd.Next(0, 20);<br />
while(large < small)
{<br />
small = rnd.Next(0, 20);<br />
}<br />
<br />
label.Text = large + " - " + small + " =";<br />
}<br />
break;<br />
}<br />
}
And use a switch to change between + or -
-- modified at 9:30 Sunday 15th October, 2006
|
|
|
|
|
Hi,
Thank you for your reply!
The 0, 20 has to be random aswel. This is what i had in mind to do it:
int number1;
int number2;
int answer;
answer = number1 + number2;
The answer is a number which the application will get from a textbox. The user will give up a maximum number in the textbox.
Suppose the user types 100, than number1 + number2 = can never cross the 100.
Thanks in advance!
|
|
|
|
|
The (0, 20) cannot be random, and if it was it would be pointless.
int n1 = rnd.Next(0, 51);
int n2 = rnd.Next(0, 51);
n1+n2 would never be greater than 100, and the lowest would be 0, but the answer could be anything inbetween.
As for storing the answerm you can put it in the tag, and check it later
Random rnd = new Random();<br />
<br />
foreach(Control label in this.Controls)<br />
{<br />
if(label.GetType().ToString() == "System.Windows.Forms.Label")<br />
{<br />
int n1 = rnd.Next(0, 20);<br />
int n2 = rnd.Next(0, 20);<br />
int answer = n1+n2;<br />
<br />
label.Tag = answer;<br />
label.Text = n1 + " + " + n2 + " =";<br />
}<br />
}<br />
You'd have to make sure that each text box was referencing the right label though, if you keep all the default names the textBox1 should reference label1
To get the answer back to check it simply:
int answer = (int)label1.Tag;
|
|
|
|
|
Hi The Undefeated,
Thanks for your reply!
I'll just make a few extra variables than
Thanks for your time and help The Undefeated!!!!!
|
|
|
|
|
The Undefeated,
How do i reference the textbox to the right labels?
|
|
|
|
|
The Undefeated wrote:
foreach(Control label in this.Controls)
{
if(label.GetType().ToString() == "System.Windows.Forms.Label")
{
label.Text = "Hello";
}
}
I recommend not to use a string comparison to determine the type of an object. Use typeof() instead.
foreach(Control label in this.Controls)
{
if( label.GetType() == typeof( System.Windows.Forms.Label ) )
{
label.Text = "Hello";
}
}
Regards,
Tim
|
|
|
|
|
Hi Tim,
Thanks for your reply!
I've changed that in to:
if(label is Label)
Regards,
Yustme
|
|
|
|
|
I'm just trying to send a string to another PC, i got my IP, set up the stuff, and it didn't work. Then i realised that im on a router so the IP address is actually wrong
So, i can only think of two things, sending it to the MAC address, or getting some other IP for the computer.
I know quite a bit about computers, but my knowledge of networking is err, lacking... so im not exactly sure what to do.
Thanks in advance, i'll keep searching.
EDIT: My IP is '192.168.1.3' - but of course, that will only work for computers connected to my router won't it? (Its also subject to change)
-- modified at 8:30 Sunday 15th October, 2006
|
|
|
|
|
I doesn't matter what Your IP is, nor that it is on a private network. You need to send to the IP of the OTHER computer. The router's IP should be your computers gateway address, then the router will route the message correctly.
We need to graduate from the ridiculous notion that greed is some kind of elixir for capitalism - it's the downfall of capitalism. Self-interest, maybe, but self-interest run amok does not serve anyone. The core value of conscious capitalism is enlightened self-interest.
Patricia Aburdene
|
|
|
|
|
Aww, im still confused, or at least somebody is.
My computer, and the computer downstairs, both have the same IP (when checked at whatsmyip.org or whatever) except for the IP on the network, downstairs has 192.168.1.2 because it connected before i did.
So if i wanted to send something to that, what would i put? (Well I could put in the IP on our network, but what if i was somewhere else completely?)
|
|
|
|
|
Hello
Just as a guidline, use System.Net.NetworkInformation namespace, and use IPGlobalProperties.GetActiveTcpConnections() to get the activve Tcp/Ip connections. Now foreach connection use Dns.Resolve() to get the Hostname, and compare it with the computer's name of the other computer.
Regards
|
|
|
|
|
Greetings,
I just need to have a progressbar that updates from a seperate thread that acts as a timer to show a countdown to refresh, and then refresh a datagrid with data, how would i make thread safe calls to the progressbar? because at debug i receive the exception
Message="Cross-thread operation not valid: Control 'pbarAutoRefresh' accessed from a thread other than the thread it was created on."
i have searched all over, some of the examples i've seen have delegates, if i need to create a delegate for the progressbar class what would the delegate class be?
Thanks in advance.
|
|
|
|