Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
921 views
in Technique[技术] by (71.8m points)

vb.net - How can i show month selection calendar in my app

I am interested in showing list of 12 months like in similar way to datepicker's month selection control. But i don't like to show the date picker to show the dates of that month too... only month view is ok so that i can select month from the list.

my desired output: enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This is going to require a bit of pinvoke to send the messages to get the calendar to switch the view. Implement the DateTimePicker's DropDown event handler like this:

    private void dateTimePicker1_DropDown(object sender, EventArgs e) {
        IntPtr cal = SendMessage(dateTimePicker1.Handle, DTM_GETMONTHCAL, IntPtr.Zero, IntPtr.Zero);
        SendMessage(cal, MCM_SETCURRENTVIEW, IntPtr.Zero, (IntPtr)1);
    }

    // pinvoke:
    private const int DTM_GETMONTHCAL = 0x1000 + 8;
    private const int MCM_SETCURRENTVIEW = 0x1000 + 32;

    [System.Runtime.InteropServices.DllImport("user32.dll")]
    private static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wp, IntPtr lp);

The view switching is animated, it is going to be visible to the user. This won't work for Windows versions prior to Vista. Use an online translator if necessary to translate this C# code to VB.NET


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...