|
System.DateTime just returns the current system time when executed. It does not get asynchronously updated by the system.
Geo
|
|
|
|
|
I think I didnt explain it very well
The DateTime will be populated with a value by the calling code. I want the class that returned the DateTime object to know when that happens.
|
|
|
|
|
|
George L. Jackson wrote: Use an event (delegate).
Please excuse my stupidity but how do I actually do that? Can I make an event fire when the value of the datetime object changes?
|
|
|
|
|
Hi,
first of all DateTime is a structure. This means that you don't pass around a real reference but a copy of the structure.
In your case you will probably need a small wrapper class for your DateTime:
public class MyDateTime {
private DateTime _value;
public event EventHandler ValueChanged;
public MyDateTime(DateTime value) {
_value = value;
}
public DateTime Value {
get { return _value; }
set {
_value = value;
OnValueChanged(EventArgs.Empty);
}
}
protected virtual void OnValueChanged(EventArgs ea) {
if (ValueChanged != null)
ValueChanged(this, ea);
}
}
Now whenever someone sets the Value property to a different value the ValueChanged event will be raised.
Your class should then look something like that:
class SomeClass
{
public MyDateTime Field
{
get
{
MyDateTime result = new MyDateTime(new System.DateTime());
result.ValueChanged += new EventHandler(OnFieldValueChanged);
return result;
}
}
private void OnFieldValueChanged(object sender, EventArgs ea) {
}
}
Depending on what you do it might also be necessary to unbind the event at some point. This would also depend on the fact if you really create a new instance of your DateTime on every get on the Field property. Probably something like this is better:
class SomeClass : IDisposable
{
private MyDateTime _field;
public SomeClass() {
_field = new MyDateTime(new System.DateTime());
_field.ValueChanged += new EventHandler(OnFieldValueChanged);
}
public MyDateTime Field
{
get { return _field; }
}
public void Dispose() {
_field.ValueChanged -= new EventHandler(OnFieldValueChanged);
}
private void OnFieldValueChanged(object sender, EventArgs ea) {
}
}
Robert
|
|
|
|
|
|
Hi Robert,
Thanks for your reply. I had thought of doing it this way but the problem is if the user of this code does the following
SomeClass c = new SomeClass();
MyDateTime t = c.Field;
t.Value.AddDays(2);
The event will not fire.
If they do this it would be ok
t.Value = t.Value.AddDays(2);
but I cant enforce this because I cant make the get() return a const
|
|
|
|
|
Looking more closly at the doco there is no method on DateTime that will change its value. The methods that modify the value return a new structure. Our programmers are just going to have to learn to code
someObj.Timestamp = someObj.Timestamp.AddDays()
I really really miss C++'s const-ness
|
|
|
|
|
I thought you were using get/set properties to access the DateTime. Thus, event code can be triggered once the property is accessed.
|
|
|
|
|
Thanks again for your help. Im sorry if I wasnt clear and sent you on a wild goose chase
|
|
|
|
|
Hello!
I have my UserControl which has its own size (in Designer view), and also I have it placed to some form, where it also has its own size.
Question: How can I make so that userControl would resize while placed to form, where it has its own size?
Thank you for your help!
|
|
|
|
|
What?? I don't understand your question!
|
|
|
|
|
I've created a .NET developer search engine using Google's COOP system so I can get more relevant results at www.netbrick.net. It seems to work very well. I would like to invite you to check it out and let me know what you think.
Thanks,
-Tyler
Tyler Jensen
Right tools, right methods!
|
|
|
|
|
I've been trying to install a VS Add-in and although it shows up under the Add-in manager, the add-in (VSDocMan) is unable to insert the MenuItems into the Tools menu. I would suspect a problem with the application but when I try to install the VBCommenter Add-In I get exceptions when it loads. Am I missing some hidden setting that might be preventing the IDE from loading the Add-in correctly? Any help would be appreciated. TIA
Uptight Ex-Military Republican married to a Commie Lib - How weird is that?
|
|
|
|
|
Do you know what is the MOST IMPORTANT BUG in .NET framework 2.0?!!!
Please reply it here
|
|
|
|
|
|
no i dont know
no i dont know,
|
|
|
|
|
The fact that it doesn't install a turing test that runs via global keyboard hooks and disables the net connection of anyone who fails.
|
|
|
|
|
I need to implement a xaml writer that can save event handler info into xaml file. However, after I went through the Markup Object, I cannot find the info.
For example, I have following codes:
Window w1 = new Window();<br />
DockPanel p1 = new DockPanel();<br />
<br />
w1.Title = "Mock Window";<br />
w1.Content = p1;<br />
Button b1 = new Button();<br />
b1.Content = "Test Button";<br />
b1.Height = 50;<br />
b1.Click += new RoutedEventHandler(OnMockButtonClick);<br />
p1.Children.Add(b1);
When I called XamlWriter.Save(w1), I want the following xaml string output:
<Window Title="Mock Window"><DockPanel><Button Height="50" Click="OnMockButtonClick">Test Button</Button></DockPanel></Window>
|
|
|
|
|
hi dear
can u please tell me that.. what will happen if i am going to launch / deploy an application on .net framework2.0 which is developed in .net framework 1.0 or 1.1 ???
please guide me in this matter..
regards
vishal
Thanks & Regards
Vishal Sharma
vishalsharma556@yahoo.co.in
|
|
|
|
|
As long as the 1.1 framework is installed on the server, you're fine. Your other option is to port it over to 2005 using VS.
|
|
|
|
|
It's called Side-by-Side Execution. You can read more about the process and how the runtime version is determined here[^]. You can even setup an app.config file to target running under a specific version of the .NET Framework.
But, running your 1.x app under 2.0 does have some pitfall - Microsoft .NET Framework 1.1 and 2.0 Compatibility[^]
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Hi,
I'm currently writting my first .NET control by deriving a ListView control under VC++.NET.
I have an issue with a property of type Image^.
As you can see in my code below, nothing is special :
#pragma region public Property : ImageSortAscendant
// Allow user to select the image which will be displayed for column sorted ascendantly
[Description("Set image (8x8) to represent ascending sorting which will appear onto sorted column header")]
[CategoryAttribute("Appearance")]
[LocalizableAttribute (true)]
virtual property Image^ ImageSortAscendant
{
Image^ get()
{
return m_ImageSortA;
}
void set(System::Drawing::Image^ value)
{
m_ImageSortA = value;
}
}
#pragma endregion
However, after assigning an image to this property, i'm not able to clear the property value, in case of user press DELETE or BACKSPACE key while this property has the focus (in property editor).
basically i would like to have the same behavior than for BackgroundImage for Form control.
thanks a lot for your help.
Al.
|
|
|
|
|
Hi all,
at least, after 1 week of research i found where was the problem....
i should declared my defaultvalue as follow :
System::ComponentModel::DefaultValueAttribute(static_cast <system::string^> (nullptr))]
and not as i tried as Image^.
Like that it allow DELETE and BACKSPACE keys to be used to clear the property field.
HTH other in case of same issue..
Alain
|
|
|
|
|
I have a deployment project and when the installer finishes installing I'd like to execute an executable passing a parameter. How would I do this? Thanks for everyones assistance.
|
|
|
|