|
You're right in your assertion, but you're wrong in your assumption. The Timespan of day 1 is from 10 AM to Midnight - or 14 hours.
|
|
|
|
|
If I ask you what time it is, and you say "It's 10 am", you're saying "10 hours have past since midnight".
Assuming you're right, and the TimeSpan class represents it as "10 AM to Midnight", then the TimeSpan class is implemented stupidly. Why then is the "Day 4 = 20 Hours", correct? According to what you said, that should be 4 hours.
Time is not "Until midnight". It's "Time elapsed".
That makes no sense at all.
If it's not broken, fix it until it is
|
|
|
|
|
See this diagram:
Day 1 (11-Aug) | Day 2 (12-Aug) | Day 3 (13-Aug) | Day 4 (14-Aug) |
10am - midnight | whole day | whole day | midnight to 8pm |
14 hrs | 24 hrs | 24 hrs | 20 hrs |
Time interval = 14 + 24 + 24 + 20 = 82 hours
/ravi
|
|
|
|
|
Okay, stop thinking that your computer and the rest of us are out to mess with your mind. Let's take this from a none computer perspective and that should make things simpler - imagine you're 7 years old and it's 10 O'Clock on Christmas Eve. How many hours are there until Christmas Day starts? Now, suppose you're told that you can't open your presents until 4PM on Christmas Day. How many hours do you have to wait from the 10 O'Clock time until you can open your presents?
That's all that's going on.
|
|
|
|
|
I understand what you're saying, I just think the implementation is wrong
If it's not broken, fix it until it is
|
|
|
|
|
I don't think the implementation is wrong at all. On the contrary, it seems that your comprehension of the mathematics is what is wrong. If you are interested in computing an elapsed period of time, then that is exactly what is happening.
Take this for example. If you started the clock at 10AM yesterday and stopped it at 10AM today then a total of 24 hours has passed. Yes? The 24 hours is easily broken down in to 10 hours TODAY and 14 hours YESTERDAY. So a time which has elapsed takes the last fraction of the day your started and the first fraction of the day you finished.
|
|
|
|
|
I see you got it now. This was the reply I was writing to your deleted post.
----
How many hours are there between Mon 11:00pm and Tue 2:00am? 3, right?
Even though I said 11:00pm (which is the 23rd hour of the day), there's only one hour left in that day. THAT's the start of the time interval. So you end up with 1 hr left on Mon and 2 hours elapsed on Tue, giving us a total of 3 hours.
----
/ravi
|
|
|
|
|
It's not that I don't get it... I just don't agree with the implementation. TimeSpan is starting from 10 and counting forward, whereas in real life we consider time as time past.
If it's not broken, fix it until it is
|
|
|
|
|
Kevin Marois wrote: TimeSpan is starting from 10 and counting forward Yes. But wouldn't you do the same when computing a time interval? For the first day, you'd count the hours left (not elapsed) and for all successive days you'd count the hours elapsed, right? Hence, Mon 10pm to Tue 1am would be a time interval of 3 hours, right?
/ravi
|
|
|
|
|
The TimeSpan isn't counting forward or backward from any specific time.
It is representing (in this case) the elapsed time from one DateTime to another.
It has no concept of forward from "10 am".
If you used an hourglass to count time from 10 am Aug 11 until 8pm Aug 14, you would just be turning the glass over for the 82nd time at the 8pm Aug 14. The TimeSpan is just representing the amount of sand that flowed through neck of the hourglass (with much more precision than counting each grain of sand!!)
It is a signed difference.
If you did the subtraction in the other order it would return -82 hours.
It is just a counter.
[Edit]
var TimelineStart = new DateTime(2015, 08, 11, 10, 00, 00);
var TimelineEnd = new DateTime(2015, 08, 14, 20, 00, 00);
TimeSpan delta = TimelineEnd - TimelineStart;
Debug.WriteLine(TimelineEnd.Ticks);
Debug.WriteLine(TimelineStart.Ticks);
Debug.WriteLine(delta.Ticks);
gives the output:
635751792000000000
635748840000000000
2952000000000
The DateTime items are counters forward from a reference date and time.
The TimeSpan is just representing the difference.
"Fairy tales do not tell children the dragons exist. Children already know that dragons exist. Fairy tales tell children the dragons can be killed."
- G.K. Chesterton
modified 17-Aug-15 13:20pm.
|
|
|
|
|
Consider a simpler example:
TimelineStart = new DateTime(2015, 08, 11, 10, 00, 00);
TimelineEnd = new DateTime(2015, 08, 11, 11, 00, 00);
TotalHours = (TimelineEnd - TimelineStart).TotalHours;
Subtracting two DateTime instances gives you a TimeSpan representing the difference between the two points on the timeline - ie: how many hours are there between 10:00 and 11:00 on 11th August 2015.
With your approach to the problem, TotalHours would contain 21 . Unless you live next to a black hole, there aren't 21 hours between 10:00 and 11:00 on the same day.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I'm using VS Community 2013 and I'd like to start a VSTO (Excel) project. However, I don't find any templates listed, local or online.
|
|
|
|
|
|
I have a form and want to display formatted text. I use a RichTextBox control. But I want windows message such as mouse clicks on the text to be handled by the parent form. So I disable the control. But that changes the background colour to grey, which is unacceptable as I want to set the background colour. Okay, so I override the WndProc method of the RichTextBox and use SendMessage to send messages such as mouse double click to the parent. That works, the form WndProc DOES receive the double click. But, the form's handler for a mouse double click is not invoked. Why is this? Does the system invoke Form event handlers instead of WndProc?
Note that the mouse bouble click message includs the client position in the lParam arg. I changed that from the location in the RichTextBox to the location in the parent form.
SOLVED
The problem is how to make a RichTextBox transparent to mouse events, so that it does no more than draw text on screen. Disabling the richtextbox sets a fixed background colour, which is not what I want.
The solution is to handle mouse events from the richeditbox in the form. Then in each event handler call Form.OnXXXXXX method e.g. Form.OnDoubleClick().
So in the end this is actually quite simple!
Thanks all for comments.
modified 14-Aug-15 11:03am.
|
|
|
|
|
You actually don't need to override WndProc callback in your RichEdit control class. Really, You have to declare and send a notify message as follows:
#define EN_MYMSG1 (WM_USER + 200)
NMHDR nmhdr;
::ZeroMemory((LPVOID)&nmhdr, sizeof(NMHDR));
nmhdr.hwndFrom = hRichEditWnd;
nmhdr.idFrom = IDC_MYRICHEDIT;
nmhdr.code = EN_MYMSG;
::SendMessage(hWndView, WM_NOTIFY, (WPARAM)nmhdr.idFrom, (LPARAM)&nmhdr);
And then, process this message by handling WM_NOTIFY in your parent window class using whatever predefined MFC message map macros or overriding WndProc callback method:
ON_NOTIFY(EN_MYMSG, IDC_MYRICHEDIT, OnMyMessage) or
ON_NOTIFY_REFLECT(EN_MYMSG, OnMyMessage)
afx_msg void OnMyMessage(NMHDR* pnmhdr , LRESULT* pResult);
void CMyWnd::OnMyMessage(NMHDR* pnmhdr, LRESULT* pResult)
{
if (pnmhdr->code == EN_MYMSG)
{
}
*pResult = 0;
}
LRESULT CALLBACK CMyWnd::WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_NOTIFY:
NMHDR* pnmhdr = &(NMHDR)message.GetLParam(typeof(NMHDR));
if (pnmhdr->code == EN_MYMSG)
{
}
break;
default: break;
}
return WndProcDefault(hWnd, uMsg, wParam, lParam);
}
That's all 
modified 14-Aug-15 8:19am.
|
|
|
|
|
That doesn't look like C# to me!
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Maybe it is .Net 5. 
|
|
|
|
|
Besides, this code has been written using C++ MFC, but you can easily convert it into C#.NET 
|
|
|
|
|
This code is just a prototype and describes the basic concept of notify message handling, it's no matter you implement it in C++ or C#. The notify message handling works similar in either C#.NET or C++ MFC. The main post of this post is the concept. 
|
|
|
|
|
Sadly I don't think it does do what I need. Basically I want the RichTextBox to display text, with the correct font, bold, background colour, etc, but to be transparent to mouse events such as double click.
I am able to intercept mouse double clicks in a class derived from RichTextBox, and SendMessage them to the parent form. They are passed in to the parent form WndProc. But for some reason they do not invoke the MouseDoubleClick event handler. I tried overriding the Form.WndProc, but could not invoke MouseDoubleClick, for reasons I understand.
|
|
|
|
|
Surely, because in Win32API, to be able to handle control's messages in parent window you have to send and process notification messages. For example, if you need to process MouseDblClick message outside the RichEditCtrl, first you have to handle this message in RichEditCtrl window class by posting WM_NOTIFY message and then process the WM_NOTIFY in the parent window as just I have shown in my reply.
|
|
|
|
|
|
Baby, help me solve my problem: FormDesigner Runtime
|
|
|
|
|
I made a function of having a Form Designer software.
In this software, I use this namespace:System.Drawing.Design.
I use the following code in my program is designed .to Program run A pop-up It is designed to form.
Now I have a problem: How can The program Run time Right click It is designed to form A pop-up with a menu.
DesignSurface surface = new DesignSurface();
surface.BeginLoad(typeof(Form));
Control view = (Control)surface.View;
view.Dock = DockStyle.Fill;
this.Controls.Add(view);
toolBoxService = new DemoToolboxService();
toolBoxService.ToolBox = new ListBox();
toolBoxService.ToolBox.Items.Add(new ToolboxItem(typeof(Button)));
toolBoxService.ToolBox.Items.Add(new ToolboxItem(typeof(TextBox)));
toolBoxService.ToolBox.Items.Add(new ToolboxItem(typeof(Label)));
toolBoxService.ToolBox.Items.Add(new ToolboxItem(typeof(TabControl)));
toolBoxService.ToolBox.Items.Add(new ToolboxItem(typeof(StatusBar)));
toolBoxService.ToolBox.Dock = DockStyle.Fill;
this.panel1.Controls.Add(toolBoxService.ToolBox);
IServiceContainer container = surface.GetService(typeof(IServiceContainer)) as IServiceContainer;
if (container != null)
{
container.AddService(typeof(IToolboxService), toolBoxService);
}
|
|
|
|
|
How to do Automatically select the Next items of list box using Timer?
|
|
|
|