0

Drop a TMonthCalendar control onto a form. Set it to show one month. Use US English locale (Sunday as first day of week). View January 2013. Your calendar actually is showing December 30th, 2012 to February 9th, 2013 because it shows 42 days total. Set your MaxSelCount to 42 and set MultiSelect to true so you can select and number of these days.

Issue 1 - Click on December 31st, and hold the mouse down. Drag to January 1st and let go. You have two days selected. Works as expected. Clear this selection by selecting another date in January. Now select the same two days again, but this time select January 1st FIRST, and drag left in order to get December 31st highlighted. Notice how the calendar scrolls left into December? How can I stop the calendar from scrolling???

Issue 2 - In both scenarios above you had the same two dates selected, but the displayed month of the calendar was completely different. How can I tell what month is actually being displayed by the calendar?

Issue 3 - Select from January 24th to February 1st. The calendar now scrolls to February, and then cuts off the 24th, 25th, and 26th from view. Seems completely broken.

I've also tried the Jedi controls which are wrappers.

Paul
  • 5,700
  • 5
  • 43
  • 67
  • 1
    I kind of doubt that this control is 'broken', since it is a native Windows control... – Andreas Rejbrand Jan 24 '13 at 21:36
  • #1 makes perfect sense to me. You've told the control to allow a max of 42 days, selected 1/1 as the first one, and started to move to a prior month. It doesn't know you want to stop at 12/31 until you stop dragging; if you intended to drag until 12/15, how would you do so if it didn't scroll to allow it? #3 is the same thing; it started to allow you to select into Feb., but you can't select more than 42 days, so why would it show you more than that on the Feb. calendar until you've gotten close to the end of Feb. with your selection? – Ken White Jan 24 '13 at 21:42
  • ...although some testing confirms that this control is not good at making a selection that requires more than a single view. For instance, it seems impossible to select 2012-01-15—2012-02-15. [However, this *does* work well if you show two or more columns at the same time.] – Andreas Rejbrand Jan 24 '13 at 21:46
  • Now that I think about it, this control is surprisingly restrictive. Why isn't the selection saved when you change the view of the control? Also, why cannot you 'Ctrl-click' to select non-contiguous subsets of days? [On the other hand, you *can* change the 'today' date displayed!] – Andreas Rejbrand Jan 24 '13 at 21:55
  • 1
    Issue 3 is not a question. If you meant it to be a question, consider posting it separately so that you can get the best possible answers for *all* your issues, instead of making people try to address all of them equally in a single response. – Rob Kennedy Jan 24 '13 at 22:26
  • @KenWhite - It does not move until after I stop dragging, so it still doesn't seem right to me. – Paul Jan 24 '13 at 22:36
  • But you still have the mouse button down, right? So it scrolls thinking you can't get to the date you want to stop on. Still makes sense to me. :-) – Ken White Jan 24 '13 at 22:37
  • @AndreasRejbrand, yes I suppose 'broken' is harsh. In my defense, I'm saying "seems broken" because I realize there might be valid reasons for why it behaves this way. I'll mention that in Delphi 6, I could in fact highlight 2013-01-15 to 2013-02-15. Also, the control did not scroll in any of the cases above! The upgrade we did from Delphi 6 to Delphi XE2 has changed this behavior. (Yes, I know it's referencing Windows controls, but D6 still doesn't do this.) – Paul Jan 24 '13 at 22:38
  • @KenWhite, No. I click, drag, and release the button. Only THEN does it scroll. I would completely understand if I still had the button down. – Paul Jan 24 '13 at 22:39
  • @RobKennedy, You are right, I'm sorry for the bad post. I was trying to illustrate why I think the automatic scrolling is wrong, and explain why I want to stop the auto scroll from #1. I should have posted these separately, and I see I've already got a terrific answer for #2 that I'll have to test and accept. At that point I'll open a new question for #1 and add #3 as a comment to it. – Paul Jan 24 '13 at 22:41

1 Answers1

2

The easy one is the second one. You can simply use the MCM_GETMONTHRANGE message – or, more simply, the MonthCal_GetMonthRange 'macro' – to obtain this information.

For example (uses CommCtrl),

procedure TForm1.FormClick(Sender: TObject);
var
  st: array[0..1] of TSystemTime;
begin
  MonthCal_GetMonthRange(MonthCalendar1.Handle, GMR_VISIBLE, @st);
  Caption := IntToStr(st[0].wMonth);
end;
Andreas Rejbrand
  • 105,602
  • 8
  • 282
  • 384