BUG:广东话选择日期一个datepicker若超出浮动VSTO加载项 [英] BUG: Cant choose dates on a DatePicker that fall outside a floating VSTO Add-In

查看:541
本文介绍了BUG:广东话选择日期一个datepicker若超出浮动VSTO加载项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

登录微软的问题在这里 - 在摄制可供下载:<一href="https://connect.microsoft.com/VisualStudio/feedback/details/741454/value-change-event-doesnt-fire-for-datetimepicker-controls-used-in-vsto-add-ins" rel="nofollow">https://connect.microsoft.com/VisualStudio/feedback/details/741454/value-change-event-doesnt-fire-for-datetimepicker-controls-used-in-vsto-add-ins

Logged the issue with Microsoft here - the Repro is available for download: https://connect.microsoft.com/VisualStudio/feedback/details/741454/value-change-event-doesnt-fire-for-datetimepicker-controls-used-in-vsto-add-ins

如果你把一个DateTimePicker在Excel中VSTO浮动加载和定位,以便当日历滴下来,它是附加在边缘之外,在这里看到:

If you put a DateTimePicker in a Excel VSTO floating Add-In and position it so when the calendar drops down, it is outside the edge of the add-in, see here:

任何选择的日期盘旋在预期的绿色工程,但点击红圈的任何日期的时候,它只是关闭日历下拉,并且不设定日期!

Choosing any of the dates circled in the green works as expected, but when clicking any dates circled in red, it just closes the calendar drop down and doesn't set the date!

有谁知道我怎么能解决这个问题?

Does anyone know how I can fix this?

修改

本SO用户遇到使用WPF的问题: <一href="http://stackoverflow.com/questions/8449745/vsto-wpf-contextmenu-menuitem-click-outside-a-taskpane-not-raised">VSTO WPF ContextMenu.MenuItem点击TaskPane外没有提出

This SO user has experienced the problem using WPF: VSTO WPF ContextMenu.MenuItem Click outside a TaskPane not raised

该问题的答案显示问题被报告给了一段时间连回,但仍没有与VSTO 4.0 SP1的解决方案:<一href="https://connect.microsoft.com/VisualStudio/feedback/details/432998/excel-2007-vsto-custom-task-pane-with-wpf-context-menu-has-focus-problems" rel="nofollow">https://connect.microsoft.com/VisualStudio/feedback/details/432998/excel-2007-vsto-custom-task-pane-with-wpf-context-menu-has-focus-problems

The answer to that question shows the issue was reported to connect a while back but still no solution with VSTO 4.0 SP1: https://connect.microsoft.com/VisualStudio/feedback/details/432998/excel-2007-vsto-custom-task-pane-with-wpf-context-menu-has-focus-problems

其中一个解决方法是使用DispatcherFrame泵消息和订阅GotFocusEvent和LostFocusEvent用于菜单。 <一href="http://blogs.msdn.com/b/vsod/archive/2009/12/16/excel-2007-wpf-events-are-not-fired-for-items-that-overlap-excel-ui-for-wpf-context-menus.aspx" rel="nofollow">http://blogs.msdn.com/b/vsod/archive/2009/12/16/excel-2007-wpf-events-are-not-fired-for-items-that-overlap-excel-ui-for-wpf-context-menus.aspx但是这一切WPF $ C $下菜单的不作为WinForm的DateTimePicker的解决方案。

One of the workarounds is to use the DispatcherFrame to pump messages and subscribe to GotFocusEvent and LostFocusEvent for the menu. http://blogs.msdn.com/b/vsod/archive/2009/12/16/excel-2007-wpf-events-are-not-fired-for-items-that-overlap-excel-ui-for-wpf-context-menus.aspx but this is all WPF code for menu's not a solution for Winform DateTimePicker.

摄制微软连接:

新建项目> Excel 2010中加载

New Project > Excel 2010 Add-In

private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
    //setup custom taskpane
    MyTaskView = new TaskPaneView();
    MyTaskView.currentInstance = Globals.ThisAddIn.Application;
    MyTaskPane = this.CustomTaskPanes.Add(MyTaskView, "MyTaskView");
    MyTaskPane.DockPosition = Microsoft.Office.Core.MsoCTPDockPosition.msoCTPDockPositionFloating;
    MyTaskPane.DockPositionRestrict = MsoCTPDockPositionRestrict.msoCTPDockPositionRestrictNoChange;
    MyTaskPane.Visible = true;
}

文件菜单>添加>新建项目>类库>命名TaskPane

File Menu > Add > New Project > Class Library > named TaskPane

然后在TaskPane项目中创建名为TaskPaneView用户控件

Then in the TaskPane project create a User Control called TaskPaneView

public partial class TaskPaneView : UserControl
{
    public TaskPaneView()
    {
        InitializeComponent();
    }

    public Microsoft.Office.Interop.Excel.Application currentInstance { get; set; }

    public TaskPaneCtrl getTaskPaneCtrl
    {
        get { return this.taskPaneCtrl1; }
    }  

}

接下来创建一个用户控件有一个DateTimePicker,确保日历控件位于朝向用户控制的右下方

Next create a User Control with a DateTimePicker, make sure the Calendar control is located toward the bottom right of the user control

public partial class TaskPaneCtrl : UserControl
{
public TaskPaneCtrl()
{
    InitializeComponent();
}
}

F5键并单击Calendar控件,现在尽量选择是taskpane区域之外的日期。 否值更改事件触发,它像日历之外的点击!

注:我尝试了下降downlist是脱落的控制,但它的事件DO火灾

Note: I tried a drop downlist that falls off the control but its events DO FIRE!

推荐答案

浮的关键问题就在这里。什么是从来没有一个问题是,你依靠Excel中的消息泵派遣的Windows消息,使这些控件的消息响应输入。这又错在WPF尽可能的WinForms,他们有自己的调度循环,才交付给窗口过滤的邮件。那出问题时不使用其各自的调度的关键事情是这样的东西Tab键和快捷键。

"Floating" is the key to the problem here. What's never not a problem is that you rely on the message pump in Excel to dispatch Windows messages, the messages that make these controls respond to input. This goes wrong in WPF as much as Winforms, they have their own dispatch loop that filters messages before they are delivered to the window. Key things that go wrong when their respective dispatcher isn't used are stuff like tabbing and short-cut keystrokes.

然后一些,这样的问题会用Excel做自己的过滤调度消息之前引起。我猜想,在反恶意软件功能,微软是永远的牵挂方案,办公应用程序搞乱。

And then some, this kind of problem would be induced by Excel doing its own filtering before dispatching messages. I'd guess at an anti-malware feature, Microsoft is forever worried about programs messing with Office apps.

本的WinForms解决方案是同一个作为WPF的解决方法,你需要抽你自己的消息循环。这需要一些手术,的DateTimePicker不会合作,因为它不允许其下拉事件被取消,它被升高的的日历已示出。解决方法是愚蠢的,但有效的,这看起来将按钮添加到您的形式,就像在DTP下拉箭头,使其重叠箭头所以它被点击,而不是方向。

The Winforms solution is the same one as the WPF workaround, you need to pump your own message loop. That requires some surgery, DateTimePicker isn't going to cooperate since it doesn't allow its DropDown event to be cancelled and it is raised after the calendar is already shown. The workaround is silly but effective, add a button to your form that looks just like the dropdown arrow on the DTP and make it overlap the arrow so it gets clicked instead of the arrow.

一些例如code获取按钮重叠的下拉箭头:

Some example code for getting the button to overlap the dropdown arrow:

    public Form1() {
        InitializeComponent();
        var btn = new Button();
        btn.BackgroundImage = Properties.Resources.DropdownArrow;
        btn.FlatStyle = FlatStyle.Flat;
        btn.BackColor = Color.FromKnownColor(KnownColor.Window);
        btn.Parent = dateTimePicker1;
        btn.Dock = DockStyle.Right;
        btn.Click += showMonthCalendar;
        dateTimePicker1.Resize += delegate {
            btn.Width = btn.Height = dateTimePicker1.ClientSize.Height;
        };
    }

Click事件处理程序需要显示包含的MonthCalendar一个对话框:

The Click event handler needs to show a dialog that contains a MonthCalendar:

    private void showMonthCalendar(object sender, EventArgs e) {
        dateTimePicker1.Focus();
        using (var dlg = new CalendarForm()) {
            dlg.DateSelected += new DateRangeEventHandler((s, ea) => dateTimePicker1.Value = ea.Start);
            dlg.Location = dateTimePicker1.PointToScreen(new Point(0, dateTimePicker1.Height));
            dlg.ShowDialog(this);
        }
    }

通过CalendarForm形式添加这是无国界的,并只包含的MonthCalendar:

With CalendarForm a form you add that's borderless and contains just a MonthCalendar:

public partial class CalendarForm : Form {
    public event DateRangeEventHandler DateSelected;

    public CalendarForm() {
        InitializeComponent();
        this.StartPosition = FormStartPosition.Manual;
        monthCalendar1.Resize += delegate {
            this.ClientSize = monthCalendar1.Size;
        };
        monthCalendar1.DateSelected += monthCalendar1_DateSelected;
    }

    void monthCalendar1_DateSelected(object sender, DateRangeEventArgs e) {
        if (DateSelected != null) DateSelected(this, e);
        this.DialogResult = DialogResult.OK;
    }
}

这篇关于BUG:广东话选择日期一个datepicker若超出浮动VSTO加载项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆