|
First, changing the DateTimePicker to only allow these things either drastically cuts down on the user interface - thereby making the control unnecessary bloat - or pisses off the user because they think they can select a date but only the month and year are used. From a UI perspective, this is a bad thing.
Now, while you can't change the UI in that way (other than overriding WndProc and attempting to use windows messages and notifications to do so), you can specify a custom format that the textbox portion of the DateTimePicker displays with the CustomFormat or Format property. This way, at least the user has some idea that only the month and / or year is valid.
When you get the Value (a DateTime structure), just grab the month and / or year and forget the rest.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
In the end I have opted for combo boxes.
The reason being is that I wanted to restrict the visuallity of the pickers so that on drop down they only showed Year or Month/Year. This would have also bypassed the problem of the user knowing that the particular picker will only allow them to choose a Year or Month/Year.
It would have been feasible to use the pickers as they are and just pull the necessary data from the resulting value, but this would mean problems for the user when selecting wildly different dates (i.e. if March 1953 is currently selected, it would take a while to get to April 2005 - now they could type the value, but that defeats the point of a picker)
After much fiddling, and your comments, it is obvious that combo boxes are the best way to go.
post.mode = signature;
SELECT everything FROM everywhere WHERE something = something_else;
> 1 Row Returned
> 42
|
|
|
|
|
How can I convert a string to System.Drawing.Color?
I'm saving a color in a xml file:
xw.WriteAttributeString("BackColor", theButton.BackColor.ToString());
The file contains:
BackColor="Color [A=255, R=255, G=255, B=0]"
or
BackColor="Color[Black]"
I then read it back:
strColor = reader.Value;
Thanks in advance for your help ,
Thomas
|
|
|
|
|
thomasa wrote:
How can I convert a string to System.Drawing.Color?
For named colors: Color.FromName
Of course for the other you will have parse the colors and push them in via Color.FromArgb
Rocky <><
www.GotTheAnswerToSpam.com
|
|
|
|
|
Given:
System.Drawing.Color obj;
string name;
Color to String:
name = obj.ToString();
String to Object:
obj = System.Drawing.Color.FromName(name);
|
|
|
|
|
I've built my Windows Form application with form's localizable property set to true, then configure support for different languages by setting Language property to fr, fr-CA, fr-fr, de, en, en-US, en-UK. I checked, the satellite assemblies were all there in the right subfolders after I compiled the application.
I execute the application on my machine, and since it's a "en-us" machine, I get the corresponding UI elements displayed with the corresponding english labels.
But, how can I change the CurrentUICulture of my "machine" - so I can see what the GUI looks like under different machine culture setting? I tried Control Panel>Regional and Language Options. I changed settings on "Regional Options" tab, but nothing I did seems to affect how my application chooses its satellite assembly: It always chooses "en-US" despite of the changes???
Thanks in advance.
|
|
|
|
|
Changing the regional settings - unless you have the appropriate MUI packs for the version of Windows you're running (only on 2000 and XP currently, I believe) - doesn't change your language.
Instead, you need to provide a way to change it in your application. If you make a user preference to do this, you have to reset the controls based on the localization information in the satellite assembly. You don't have to re-instantiate the controls or add the controls to their would-be parent's Controls collection, but you do have to do practically everything else.
An easier way would be to add a key/value pair (say, "language", then the 5-digit lang-culture pair as the value) to your <appSettings> . In your application - either as the first lines in the main forms's constructor, or before you call Application.Run - read the setting with ConfigurationSettings.AppSettings["language"] . If a setting exists, set Thread.CurrentUICulture = new Culture(myLangSetting) . Any other threads that are spawned from the main thread (which the UI must add, remove, and usually update controls on) should inherit the setting from the thread that spawned them.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Thanks, I can see what you're getting at. I'll just put a Dropdown box and let user to select CurrentUICulture.
|
|
|
|
|
Actually, I think you missed my point. If you use a drop-down, this implies that you're UI is already running (unless you use a modal dialog before calling Application.Run , which can be tricky depending on a number of factors). If you do this, to change the UI culture you have to completely reset EVERY SINGLE CONTROL in your application. This is especially tedious when you have multiple forms. Switching languages while a program is running - especially larger programs - is definitely not a trivial thing.
If users require different languages on their Windows machine, then they might just have the appropriate MUI pack installed and enabled. They will see the appropriate localized UI automatically. If you just require this for testing, use the config file. If nothing else, companies that require a different localized UI can change the config file when - for native applications - they would change the registry (using the registry for .NET apps is not recommended). It's not like users are going to be changing the UI culture often, right? Why make it much more difficult on yourself.
That's what I was getting at - keep it simple. Assign the UI Culture before you start your application (which means the main UI thread, which will effect all threads spawned from it). You'll save yourself A LOT of trouble.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
You're right, configure it before loading the application or UI is constructed. Point well taken.
|
|
|
|
|
Hello,
How can i create avi file or any other movie file from a collection of images. I want to know, which dll i can use to buil a movie file.
bye.
|
|
|
|
|
There is nothing in the .NET Framework Base Class Library (BCL) that can do this. You should download Microsoft DirectX 9.0 with the managed classes that will allow you to use C#. Read the docs so that you understand the concepts, which is basically to string readers, decoders, encoders, and writers together. In your case, it's slightly different. You should also search this site because I'm sure I've seen an example or two on this topic.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Hello,
Thank u Heath Stewart, let me download Microsoft DirectX 9.0 with the managed classes. Let me also search more this into this site and then i will decide what can i do.
Khurram.
|
|
|
|
|
OK, I have spent hours trying to figure this out on my own. I think I just don't know what the correct terminology is.
I am trying to call a form enter some data and pass that data back to the calling form. I am using a custom form and not a built in dialog.
Can someone point me in the right direction. I can't seem to even find an example on CP, MSDN, or a mayrid of other websites as well as two C# books.
Jeff Patterson
Programmers speak in Code.
http://www.anti-dmca.org[^]
|
|
|
|
|
Jeff,
You should check into delegates, events, and eventargs. You can derive a class from EventArgs from which you can specify whatever values you want to pass. Events allow you to register delegates which are held in some-what of a linked-list fashion which are then invoked when the event fires. There are several good articles available, some which are on CP (check out Chris Sell's article: .NET Delegates: A C# Bedtime Story[^]). Hope this is of some help. Here is just one example of how delegates and events work together:
using System;
using System.Windows.Forms;
namespace Test
{
class Class1 : System.Windows.Forms.Form
{
public Class1(){}
public delegate void MyEventHandler(int i);
public event MyEventHandler MyEvent;
static void Main(string[] args)
{
Class1 cls = new Class1();
cls.MyEvent += new MyEventHandler(SomeMethod);
cls.MyEvent += new MyEventHandler(AnotherMethod);
if(cls.MyEvent != null)
cls.MyEvent(6);
cls.ShowDialog();
}
public static void SomeMethod(int i)
{
MessageBox.Show("Hello from SomeMethod. " +
i + " was passed in.");
}
public static void AnotherMethod(int i)
{
MessageBox.Show("Hello from AnotherMethod. " +
i + " was passed in.");
}
}
}
-Nick Parker
DeveloperNotes.com
|
|
|
|
|
Thanks Nick, I will have to study this a little more indepthly. I read the "Bed Time Story" before I posted this message and it looked like it was more complicated that what I was trying to do. I guess not.
Thanks
Jeff Patterson
Programmers speak in Code.
http://www.anti-dmca.org[^]
|
|
|
|
|
Hi guys,
I am currently implementing an application which needs to support paths like:
%windir%\Microsoft.NET\Framework\
The pointers (eg %windir%) are supported by .NET, so i can access file listings easily.
However, Directory.Exists returns some wierd results:
Directory.Exists("%windir%") => false
Directory.Exists("%windir%\Microsoft.NET\") => true
Does anyone know of a way to validate these directories properly. I can just request a directory listing, and wait for an exception but this isn't good coding and will slow down the process too much as potentially hundreds will need to be evaluated.
Thanks,
Tatham Oddie
Developer, SSW (www.ssw.com.au
|
|
|
|
|
These are actually called environment variables, not pointers. Windows 98 and ME don't always support the same environment variables as Windows NT. It is better to use Environment.GetFolderPath , since this is supported by all operating systems that currently support the CLR. The functions that this method use are actually used by Windows Explorer, Windows Installer, various Microsoft and non-Microsoft applications, and the .NET Framework, of course. It is far more reliable and more robust to use this like so:
string system = Environment.GetFolderPath(Environment.SpecialFolder.System);
string windir = Directory.GetParent(system).FullName;
string framework = Path.Combine(windir, "Microsoft.NET\\Framework"); A little long-winded, but - as I said - is supported on any OS supporting the CLR and uses the paths that administrators might set up in a roaming profile or for home directories and what not (overriding the defaults).
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Is there any way to have a function that accepts a function name as a parameter and is then able to call it?
EXAMPLE:
public void MyFunc(Function func)
{
func();
}
Help is greatly appreciated.
|
|
|
|
|
May be you can use Delegate and pass out delegate function.
|
|
|
|
|
The following is a quick example of a delegate in C#.
using System;
namespace Test
{
class Class1
{
delegate void Func(int i);
static void Main(string[] args)
{
Func f = new Func(SomeMethod);
f(4);
}
public static void SomeMethod(int i)
{
Console.WriteLine("Hello from SomeMethod. " +
i + " was passed in.");
Console.Read();
}
}
}
-Nick Parker
DeveloperNotes.com
|
|
|
|
|
Call the funcitzon "by name":
public void MyFunc(Function func)
{
//get the type of the object containing the method
Type type = this.GetType();
//get the method
System.Reflection.MethodInfo methodInfo = type.GetMethod(func, BindingFlags.Default);
String result;
if(methodInfo == null){
result = TextConstants.MSG_MethodNotFound.Replace("Method not found");
}else{
//call the method
result = methodInfo.Invoke(this, null).ToString();
}
}
|
|
|
|
|
I'm working on an app where I have some objects that are displayed onscreen and the user needs to be able to link them together by dragging and dropping a field from one to the other (just like a graphical sql query designer does only this is with business objects).
I need to do the bit where the lines are drawn that link the objects together visually. I can easily draw a straight line between them and keep track of the anchor points, but this doesn't look very nice compared to programs that route the lines efficiently.
Before I re-invent the wheel, anyone know of any source of info on this?
I support two teams: the Canucks and whoever is playing the Leafs!
|
|
|
|
|
does anyone have good examples of where attributes are put to good use in C#? MSDN have decent examples on "HOW TO" use them, but pretty thin on the "WHY" to use them section.
Phil.C
|
|
|
|
|
Why use attributes? Because it makes somethings easier. Attributes are metadata that is exposed so that other bits of software can discover what your code does and can interface appropriately to it.
NUnit (A unit/regression testing tool) use attributes to define test methods. Why? So that when you create a testing method you can put the attribute to tell NUnit that this is a test method with the code that does the test, rather than in, say, some secondary file which won't get updated properly, or contain errors because it was updated badly, etc.
You can use attributes when you are creating serializable classes to assist with the process. (They help define how it gets serialized). Why? Because it keeps the information next to the place that exposes the value, if something should happen to the value, the attribute can be updated easily.
If you create custom controls, the attributes you place on properties let the IDE know what should and should not go in the designer, what icon to use in the toolbox etc. Why? To keep together the information about the property with the property. If the property changes, so might the information and it would be much easier if all the changes are in the one place.
--Colin Mackay--
"In the confrontation between the stream and the rock, the stream always wins - not through strength but perseverance." (H. Jackson Brown)
|
|
|
|