|
Is there any way I can globally change DateTime.ToString() to use a 24hr clock instead of am/pm? From initial googling it appears that this is controlled by culture settings, but I'm not having any luck finding specifics.
If not I could do a global search/replace and feed a format string into each call, but that would leave any new additions open to a bug if I overlooked making the change there.
|
|
|
|
|
Do you mean change it globally on your PC? To do that you would:
1) Open Window's Control Panel.
2) Click on "Regional and Language Options".
3) Click the Customize button in the Regional Tab.
4) Select the Time tab.
5) Enter/select the following Time format: "HH:mm:ss"
|
|
|
|
|
No, just for my application.
|
|
|
|
|
Try this...
System.Globalization.CultureInfo info;<br />
info = System.Globalization.CultureInfo.CurrentCulture;<br />
info = new System.Globalization.CultureInfo(info.LCID, true);<br />
info.DateTimeFormat.ShortTimePattern = "HH:mm:ss";<br />
info.DateTimeFormat.LongTimePattern = "HH:mm:ss";<br />
System.Threading.Thread.CurrentThread.CurrentCulture = info;
|
|
|
|
|
Thank you for pointing me in the right direction, the one I actually needed to change was FullDateTimePattern.
|
|
|
|
|
hello, i have a listbox with some items in it, in this form:
client #1 - 255.255.255.255:8000
where the ip, port, and client number changes length (number of digits). how can i convert the client # in this to an int (stored in a variable), but not get anything else in it? (using clients.SelectedValue)
thanks in advance,
sam kline
|
|
|
|
|
You can use string mashing, or you could use a regular expression
client #(\d*)
seems to me like it would capture the number for you
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
how exactly would i do that? everything i try gives me exceptions.
thanks in advance,
sam kline
|
|
|
|
|
What did you try ?
string s = "client #1 - 255.255.255.255:8000";
Match match = Regex.Match(s, @"client #(\d*)", RegexOptions.IgnoreCase);
MessageBox.Show(match.Groups[1].Value);
This shows '1' in a message box.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
thanks a lot! it worked.
try
{
Match match = Regex.Match(connectedusers.SelectedItem.ToString(), @"client #(\d*)", RegexOptions.IgnoreCase);
return Convert.ToInt32(match.Groups[1].Value);
}
catch (FormatException)
{
return 0;
}
catch (NullReferenceException)
{
return 0;
}
|
|
|
|
|
I want to use GDI to draw some images in a "fullscreen" mode. What is the best way to do this? When I seem to hide pieces of my form turn it black and make it the resolution of the monitor there seems to be a "pause" when covering up the start menu. This makes me think I'm not approaching it the right way. Anyone know the proper way to do this?
|
|
|
|
|
Just resize your window so that the non client areas are outside the bounds of the screen.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I order to switch to a "fullscreen" mode you must set the Window class's
dwExStyle=WS_EX_APPWINDOW;
dwStyle=WS_POPUP;
And force the window to fill the entire screen.
I think the changes to the window class I mentioned above can be achived if you set the border property of a window to none. And, if you have problems with the TaskBar, set the TopMost property to true
I hope you understand...because is a rough world out there...
|
|
|
|
|
How would you program a generic collection class to allow only classes inherited from, say Person, class. Here is the code article by Mahesh Kumar on this subject. He codes this for any type, but suppose in his sample, employee and customer are of a particular type, say, "Worker" how would this code be changed.
smh1
|
|
|
|
|
Not used VS 2005 yet but from a little bit of reading around the subject I'd guess that you would use generic constraints for this type of problem.
Not sure of the syntax from memory but something like
Collection<Employee> where Employee : Worker
i.e., Employee has to inherit from Worker or implement an interface called Worker (IWorker for .NET of course).
Kevin
|
|
|
|
|
In VS2005, you'd do this
ArrayList<Worker> list = new ArrayList<Worker>;
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
There is no generic ArrayList in VS2005.The generic equivelant of the Arraylist is List<T>.So you could write
List<Worker> list = new List<Worker>();
-- modified at 18:31 Tuesday 22nd November, 2005
|
|
|
|
|
*blush* I did notice that, actually. But I forgot.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I think I did not formulate this properly (partly because I don't understand it fully). Question is; what is the syntax in C# for using multiple contraints on a generic collection class that uses the collectionbase.
The sample that I show in my text is from an article that appeared here where Mahesh uses the CollectionBase for a generic collectionclass but does not use multiple contraints. So that is my problem.
If I don't use CollectionBase I have to use an array, I guess, which I didn't want to use because the Collectionbase code for insert and remove is so nice.
Thanks
smh1
|
|
|
|
|
Hi, I have a problem validating with a XmlValidatingReader and a .xsd file
the validation breaks when the importDate attribute is parsed
< Info importDate = "1967-08-13" />
in the .xsd is defined as
< xs:attribute name="importDate" type="xs:date" use="required" />
and the error message is
"The 'importDate' attribute has an invalid value accordint to its data type. An error occurred at, (12, 44)"
Anyone has an idea why this happens, when I validate the same XML file in the XMLSpy it works fine, then i run my program and it breaks in that line, if I remove the line then everything works
Thanks in Advance
Isaac B
|
|
|
|
|
hi,
im having trouble trying to dynamically create and add a textboxes to cells in a datagrid im just wondeing if this is possible and if so does anyone have any idea of how exactly to go about doin it.Thanks in advance
Tim
|
|
|
|
|
A DataGrid displays data and let's you modify it into a special control derived from the DataGridColumnStyle . The TextBox-looklike contol that is avaliable on a DataGrid actualy is a DataGridTextBoxColumn .
When you set a DataGrid's Data Source if a Custom TalbeStyle is not provided, then a standard one is created. So basicly you don't have acces to the "TextBoxes into the cells".
But if you do not supply a Custom TableStyle and make changes to the DataSource (table) you may see the correct results onto the Grid. (na. adding more columns to the table, or if you do have a table style - lets say you preffer the columns to be sorted - be sure to update the table style afther adding a new column)
I hope you understand...because is a rough world out there...
|
|
|
|
|
I have application, that creates 2 threads, Both threads use the same resources and I want, they to be synchronised using Mutex.
I am using code like this
public class Test
{
protected Mutex mutex;
public Test()
{
mutex = new Mutex(false);
Thread A = new Thread(new ThreadStart(TF1));
Thread B = new Thread(new ThreadStart(TF2));
A.Start();
B.Start();
}
void TF1()
{
while(true)
{
mutex.WaitOne();
Console.Write("do some work 1");
mutex.Release();
Thread.Sleep(100);
}
}
void TF2()
{
while(true)
{
mutex.WaitOne();
Console.Write("do some work 2");
mutex.Release();
Thread.Sleep(100);
}
}
}
--------------------------------------------
It works fine some time, but one moment
both Threads are waiting for something, for example
Console Input or Window Resize.
And I do not understand why.
(Of course, I am not using "Console.Read" function in a Thread functions. )
|
|
|
|
|
Try switching your Thread.Sleep(100) with your mutex.Release(). Since Thread.Sleep() is a static method you can't be sure which thread is sleeping if you have released the synchronization
Also, I don't think your implementation is correct. Since your threads do not own the Mutex I do not believe they will be synchronized. You should have both threads call the same function so the Mutex can protect the resource.
public class Test
{
protected Mutex mutex;
public Test()
{
mutex = new Mutex(false);
Thread A = new Thread(new ThreadStart(TF));
Thread B = new Thread(new ThreadStart(TF));
A.Start();
B.Start();
}
void TF()
{
while(true)
{
mutex.WaitOne();
Console.Write("do some work {0}", Thread.CurrentThread.Name);
Thread.Sleep(100);
mutex.ReleaseMutex();
}
}
}
and since your synchronization is inside an infinite while loop I don't know what will happen as far as sharing process time
-- modified at 16:11 Tuesday 22nd November, 2005
|
|
|
|
|
Thank you! I'll try to make it static now.
BIG Thanks!
|
|
|
|