<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: DatePicker in Pallette Keeps closing in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/datepicker-in-pallette-keeps-closing/m-p/7826828#M27054</link>
    <description>&lt;P&gt;Should the below bit of code be returning somthing&amp;nbsp;?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;IntPtr GetDropDownWindow()
      {
         EnumChildren enumChildren = new EnumChildren();
         EnumChildren.EnumChildrenCallback func = new EnumChildren.EnumChildrenCallback(enumChildren.enumChildren);
         EnumChildWindows(new HandleRef(this, base.Handle), func, new HandleRef(null, IntPtr.Zero));
         return enumChildren.hwndFound;
      }&lt;/PRE&gt;&lt;P&gt;the below is what I'm&amp;nbsp;getting when I run it in debug it returns&amp;nbsp;0x0000000000000000&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 705px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/470799i17784E9668DF4429/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 05 Mar 2018 09:02:36 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2018-03-05T09:02:36Z</dc:date>
    <item>
      <title>DatePicker in Pallette Keeps closing</title>
      <link>https://forums.autodesk.com/t5/net-forum/datepicker-in-pallette-keeps-closing/m-p/7818938#M27050</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have got a pallet that I am showing in AutoCAD&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have created it as a custom control and then loaded it up when a command is run&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the Problem i have got is that there is a datetimepicker&amp;nbsp;in it and then i go to select a date from the dropdown it opens and then as soon as i go to move my mouse over it it then closes again&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;does anyone know a way to fix this ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 01 Mar 2018 10:55:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/datepicker-in-pallette-keeps-closing/m-p/7818938#M27050</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-03-01T10:55:52Z</dc:date>
    </item>
    <item>
      <title>Re: DatePicker in Pallette Keeps closing</title>
      <link>https://forums.autodesk.com/t5/net-forum/datepicker-in-pallette-keeps-closing/m-p/7820200#M27051</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Difficult to diagnose without seeing any code...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;this works for me:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the XAML:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&amp;lt;TextBlock Grid.Row="0" Margin="10" Text="{Binding Date, StringFormat=dd/MM/yyyy}" /&amp;gt;
&amp;lt;DatePicker Grid.Row="1" Margin="10" SelectedDate="{Binding Date}" /&amp;gt;&lt;/PRE&gt;
&lt;P&gt;In the class set as DataContext (which implements INotifyPropertyChanged)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;DateTime date;

public DateTime Date
{
    get { return date; }
    set { date = value; RaisePropertyChanged("date"); }
}&lt;/PRE&gt;</description>
      <pubDate>Thu, 01 Mar 2018 17:21:54 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/datepicker-in-pallette-keeps-closing/m-p/7820200#M27051</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2018-03-01T17:21:54Z</dc:date>
    </item>
    <item>
      <title>Re: DatePicker in Pallette Keeps closing</title>
      <link>https://forums.autodesk.com/t5/net-forum/datepicker-in-pallette-keeps-closing/m-p/7821045#M27052</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;@Anonymous wrote:&lt;BR /&gt;&lt;P&gt;Hi&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have got a pallet that I am showing in AutoCAD&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have created it as a custom control and then loaded it up when a command is run&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the Problem i have got is that there is a datetimepicker&amp;nbsp;in it and then i go to select a date from the dropdown it opens and then as soon as i go to move my mouse over it it then closes again&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;does anyone know a way to fix this ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;With WinForms controls, this is not a simple problem to solve.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, I've had to deal with this quite a bit in the past, so below is one of my custom WinForms controls that solves the problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace AcadControlLibrary
{

   /// &amp;lt;summary&amp;gt;
   /// A specialization of System.Windows.Forms.DateTimePicker
   /// that can be used on a modeless floating window (such as
   /// a PaletteSet or a Form that is shown modelessly), which
   /// corrects the problem of AutoCAD stealing the input focus 
   /// from popup windows.
   /// 
   /// Use this class in lieu of System.Windows.Forms.DateTimePicker.
   /// &amp;lt;/summary&amp;gt;
   
   public class AcDateTimePicker : DateTimePicker
   {
      KeepFocusHook hook = null;
      protected override void OnDropDown(EventArgs eventargs)
      {
         if(!DesignMode)
         {
            IntPtr hwnd = GetDropDownWindow();
            if(hwnd != IntPtr.Zero)
               hook = new KeepFocusHook(hwnd);
         }
         base.OnDropDown(eventargs);
      }

      protected override void OnCloseUp(EventArgs eventargs)
      {
         if(hook != null &amp;amp;&amp;amp; !DesignMode)
         {
            hook.ReleaseHandle();
            hook = null;
         }
         base.OnCloseUp(eventargs);
      }

      class EnumChildren
      {
         public IntPtr hwndFound = IntPtr.Zero;

         public bool enumChildren(IntPtr hwnd, IntPtr lparam)
         {
            this.hwndFound = hwnd;
            return true;
         }

         public delegate bool EnumChildrenCallback(IntPtr hwnd, IntPtr lParam);
      }

      class KeepFocusHook : NativeWindow
      {
         public KeepFocusHook(IntPtr handle)
         {
            base.AssignHandle(handle);
         }

         const int WM_ACADKEEPFOCUS = 0x7101;
         protected override void WndProc(ref Message m)
         {
            if(m.Msg == WM_ACADKEEPFOCUS)
            {
               m.Result = new IntPtr(1);
            }
            else
            {
               base.WndProc(ref m);
            }
         }
      }


      IntPtr GetDropDownWindow()
      {
         EnumChildren enumChildren = new EnumChildren();
         EnumChildren.EnumChildrenCallback func = new EnumChildren.EnumChildrenCallback(enumChildren.enumChildren);
         EnumChildWindows(new HandleRef(this, base.Handle), func, new HandleRef(null, IntPtr.Zero));
         return enumChildren.hwndFound;
      }

      [DllImport("user32.dll", ExactSpelling = true)]
      static extern bool EnumChildWindows(HandleRef hwndParent, EnumChildren.EnumChildrenCallback lpEnumFunc, HandleRef lParam);


   }
}&lt;/PRE&gt;</description>
      <pubDate>Thu, 01 Mar 2018 21:48:22 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/datepicker-in-pallette-keeps-closing/m-p/7821045#M27052</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2018-03-01T21:48:22Z</dc:date>
    </item>
    <item>
      <title>Re: DatePicker in Pallette Keeps closing</title>
      <link>https://forums.autodesk.com/t5/net-forum/datepicker-in-pallette-keeps-closing/m-p/7826818#M27053</link>
      <description>&lt;P&gt;Sorry for the late reply thanks for the code but its not working for me i am still having the same problem&lt;/P&gt;&lt;P&gt;I have changed the datetimepickers on the form the be the AcDateTimePicker but it still closes when you go to move your mouse over it&lt;/P&gt;</description>
      <pubDate>Mon, 05 Mar 2018 08:55:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/datepicker-in-pallette-keeps-closing/m-p/7826818#M27053</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-03-05T08:55:08Z</dc:date>
    </item>
    <item>
      <title>Re: DatePicker in Pallette Keeps closing</title>
      <link>https://forums.autodesk.com/t5/net-forum/datepicker-in-pallette-keeps-closing/m-p/7826828#M27054</link>
      <description>&lt;P&gt;Should the below bit of code be returning somthing&amp;nbsp;?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;IntPtr GetDropDownWindow()
      {
         EnumChildren enumChildren = new EnumChildren();
         EnumChildren.EnumChildrenCallback func = new EnumChildren.EnumChildrenCallback(enumChildren.enumChildren);
         EnumChildWindows(new HandleRef(this, base.Handle), func, new HandleRef(null, IntPtr.Zero));
         return enumChildren.hwndFound;
      }&lt;/PRE&gt;&lt;P&gt;the below is what I'm&amp;nbsp;getting when I run it in debug it returns&amp;nbsp;0x0000000000000000&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 705px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/470799i17784E9668DF4429/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Mar 2018 09:02:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/datepicker-in-pallette-keeps-closing/m-p/7826828#M27054</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-03-05T09:02:36Z</dc:date>
    </item>
    <item>
      <title>Re: DatePicker in Pallette Keeps closing</title>
      <link>https://forums.autodesk.com/t5/net-forum/datepicker-in-pallette-keeps-closing/m-p/7829138#M27055</link>
      <description>&lt;P&gt;The code I posted works for me without any problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I created a new UserControl, added an AcDateTimePicker to it, and then added the UserControl to a PaletteSet, and when I show the PaletteSet and click on the dropdown button on the DateTimePicker, the dropdown window appears and I can use the mouse to pick a date.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, there must be something else happening on your end because&amp;nbsp;I'm confident that it works, and I have many other custom controls with dropdown windows that I also use that same code with, and they also work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I can tell you is that it will not work in the debugger with a breakpoint set to stop when the dropdown button is clicked, because that will bring the debugger into the foreground, which will cancel the display of the popup window (and in that case, the result of GetDropDownWindow() will be IntPtr.Zero).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Did you try running the code outside of the debugger?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;@Anonymous wrote:&lt;BR /&gt;&lt;P&gt;Sorry for the late reply thanks for the code but its not working for me i am still having the same problem&lt;/P&gt;&lt;P&gt;I have changed the datetimepickers on the form the be the AcDateTimePicker but it still closes when you go to move your mouse over it&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Mar 2018 21:13:43 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/datepicker-in-pallette-keeps-closing/m-p/7829138#M27055</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2018-03-05T21:13:43Z</dc:date>
    </item>
    <item>
      <title>Re: DatePicker in Pallette Keeps closing</title>
      <link>https://forums.autodesk.com/t5/net-forum/datepicker-in-pallette-keeps-closing/m-p/7829153#M27056</link>
      <description>Hi&lt;BR /&gt;&lt;BR /&gt;Yes tried outside of debug and get the same issue&lt;BR /&gt;Tried also writing the editor and was getting the same result 0 being returned&lt;BR /&gt;&lt;BR /&gt;Not sure if that would take the focus away ?</description>
      <pubDate>Mon, 05 Mar 2018 21:15:46 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/datepicker-in-pallette-keeps-closing/m-p/7829153#M27056</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-03-05T21:15:46Z</dc:date>
    </item>
    <item>
      <title>Re: DatePicker in Pallette Keeps closing</title>
      <link>https://forums.autodesk.com/t5/net-forum/datepicker-in-pallette-keeps-closing/m-p/7829378#M27057</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;@Anonymous wrote:&lt;BR /&gt;Hi&lt;BR /&gt;&lt;BR /&gt;Yes tried outside of debug and get the same issue&lt;BR /&gt;Tried also writing the editor and was getting the same result 0 being returned&lt;BR /&gt;&lt;BR /&gt;Not sure if that would take the focus away ?&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Something else is not right on your end.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please first confirm that you haven't made any changes to the above code, and what language are you using (VB or C#) ?&amp;nbsp; What AutoCAD release are you using, and what version of Windows are you using?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The only other way to get to the bottom of it, is to create a new ClassLibrary project, add the code I posted above, add a new UserControl to the project and drop an AcDateTimePicker control on it, then create a new PaletteSet and add the new UserControl to the PaletteSet, and compile and run the code, and see if it works.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Mar 2018 22:35:22 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/datepicker-in-pallette-keeps-closing/m-p/7829378#M27057</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2018-03-05T22:35:22Z</dc:date>
    </item>
  </channel>
</rss>

