在Win7 Aero主题中增加DateTimePicker日历的字体大小

时间:2013-04-16 07:42:13

标签: c# .net windows

我想在Win7中更改日历控件的字体大小,使其与触摸屏兼容。我机器中的主题是Aero。 CalendarFont属性对Aero主题没有任何影响。

所以我已经重写OnDropDown方法来禁用calander控件的主题。现在字体已更改,但日历窗口大小未更改。下图显示了我看到的窗口enter image description here

代码如下。我该怎么做才能增加日历窗口的大小?

 protected override void OnDropDown(EventArgs e)
    {

        IntPtr pointerToCalenderWindow = SendMessage(Handle, DtmGetmonthcal,0,0);
        // Disble Theme
        SetWindowTheme(pointerToCalenderWindow, "", "");      

        var rect = new Rectangle();
        SendMessage(pointerToCalenderWindow, McmGetminreqrect, 0, ref rect);     

        MoveWindow(pointerToCalenderWindow,0,0,rect.Right + 2, rect.Bottom + 2, true);

        base.OnDropDown(e);
    }


private const int McmFirst = 0x1000;
    private const int McmGetminreqrect = (McmFirst + 9);
    private const int McsWeeknumbers = 0x4;
    private const int DtmFirst = 0x1000;
    private const int DtmGetmonthcal = (DtmFirst + 8);

    private const int WMPAINT = 0x000F;


    [DllImport("uxtheme.dll")]
    private static extern int SetWindowTheme(IntPtr hWnd, string appname, string idlist);


    [DllImport("User32.dll")]
    private static extern IntPtr SendMessage(IntPtr h,
                                             int msg,
                                             int param,
                                             int data);

    [DllImport("User32.dll")]
    private static extern int MoveWindow(IntPtr h,
                                         int x,
                                         int y,
                                         int width,
                                         int height,
                                         bool repaint);

1 个答案:

答案 0 :(得分:3)

似乎this question和你的问题差不多:

答案说明实际上有两个窗口用于日历部分(“内部”和“外部”),您需要正确设置外部窗口的大小。