Пример #1
0
        /// <include file='doc\ComboBox.uex' path='docs/doc[@for="ComboBox.OnHandleCreated"]/*' />
        /// <devdoc>
        ///     Overridden to make sure all the items and styles get set up correctly.
        ///     Inheriting classes should not forget to call
        ///     base.OnHandleCreated()
        /// </devdoc>
        /// <internalonly/>
        protected override void OnHandleCreated(EventArgs e) {

            base.OnHandleCreated(e);

            if (MaxLength > 0) {
                SendMessage(NativeMethods.CB_LIMITTEXT, MaxLength, 0);
            }

            // Get the handles and wndprocs of the ComboBox's child windows
            //
            Debug.Assert(childEdit == null, "Child edit window already attached");
            Debug.Assert(childListBox == null, "Child listbox window already attached");

            bool ok = childEdit == null && childListBox == null;

            if (ok && DropDownStyle != ComboBoxStyle.DropDownList) {
                IntPtr hwnd = UnsafeNativeMethods.GetWindow(new HandleRef(this, Handle), NativeMethods.GW_CHILD);
                if (hwnd != IntPtr.Zero) {

                    // if it's a simple dropdown list, the first HWND is the list box.
                    //                    
                    if (DropDownStyle == ComboBoxStyle.Simple) {
                        childListBox = new ComboBoxChildNativeWindow(this);
                        childListBox.AssignHandle(hwnd);

                        // get the edits hwnd...
                        //
                        hwnd = UnsafeNativeMethods.GetWindow(new HandleRef(this, hwnd), NativeMethods.GW_HWNDNEXT);
                    }

                    childEdit = new ComboBoxChildNativeWindow(this);
                    childEdit.AssignHandle(hwnd);

                    // set the initial margin for combobox to be zero (this is also done whenever the font is changed).
                    //
                    UnsafeNativeMethods.SendMessage(new HandleRef(this, childEdit.Handle), NativeMethods.EM_SETMARGINS,
                                              NativeMethods.EC_LEFTMARGIN | NativeMethods.EC_RIGHTMARGIN, 0);
                }
            }

            bool found;
            int dropDownWidth = Properties.GetInteger(PropDropDownWidth, out found);
            if (found) {
                SendMessage(NativeMethods.CB_SETDROPPEDWIDTH, dropDownWidth, 0);
            }

            found = false;
            int itemHeight = Properties.GetInteger(PropItemHeight, out found);
            if (found) {
                // someone has set the item height - update it
                UpdateItemHeight();
            }
            // Resize a simple style combobox on handle creation
            // to respect the requested height.
            //
            if (DropDownStyle == ComboBoxStyle.Simple) {
                Height = requestedHeight;
            }

            //If HandleCreated set the AutoComplete...
            //this function checks if the correct properties are set to enable AutoComplete feature on combobox.
            try
            {
                fromHandleCreate = true;
                SetAutoComplete(false, false);
            }
            finally
            {
                fromHandleCreate = false;
            }


            if (itemsCollection != null) {
                foreach (object item in itemsCollection) {
                    NativeAdd(item);
                }

                // Now udpate the current selection.
                //
                if (selectedIndex >= 0) {
                    SendMessage(NativeMethods.CB_SETCURSEL, selectedIndex, 0);
                    UpdateText();
                    selectedIndex = -1;
                }
            }
            // NOTE: Setting SelectedIndex must be the last thing we do. See ASURT 73949.

        }
Пример #2
0
        /// <devdoc>
        ///     Release the ChildWindow object by un-subclassing the child edit and
        ///     list controls and freeing the root of the ChildWindow object.
        /// </devdoc>
        private void ReleaseChildWindow() {

            if (childEdit != null) {

                childEdit.ReleaseHandle();
                childEdit = null;
            }

            if (childListBox != null) {

                childListBox.ReleaseHandle();
                childListBox = null;
            }
        }
 protected override void OnHandleCreated(EventArgs e)
 {
     bool flag2;
     base.OnHandleCreated(e);
     if (this.MaxLength > 0)
     {
         base.SendMessage(0x141, this.MaxLength, 0);
     }
     if (((this.childEdit == null) && (this.childListBox == null)) && (this.DropDownStyle != ComboBoxStyle.DropDownList))
     {
         IntPtr window = System.Windows.Forms.UnsafeNativeMethods.GetWindow(new HandleRef(this, base.Handle), 5);
         if (window != IntPtr.Zero)
         {
             if (this.DropDownStyle == ComboBoxStyle.Simple)
             {
                 this.childListBox = new ComboBoxChildNativeWindow(this);
                 this.childListBox.AssignHandle(window);
                 window = System.Windows.Forms.UnsafeNativeMethods.GetWindow(new HandleRef(this, window), 2);
             }
             this.childEdit = new ComboBoxChildNativeWindow(this);
             this.childEdit.AssignHandle(window);
             System.Windows.Forms.UnsafeNativeMethods.SendMessage(new HandleRef(this, this.childEdit.Handle), 0xd3, 3, 0);
         }
     }
     int integer = base.Properties.GetInteger(PropDropDownWidth, out flag2);
     if (flag2)
     {
         base.SendMessage(0x160, integer, 0);
     }
     flag2 = false;
     base.Properties.GetInteger(PropItemHeight, out flag2);
     if (flag2)
     {
         this.UpdateItemHeight();
     }
     if (this.DropDownStyle == ComboBoxStyle.Simple)
     {
         base.Height = this.requestedHeight;
     }
     try
     {
         this.fromHandleCreate = true;
         this.SetAutoComplete(false, false);
     }
     finally
     {
         this.fromHandleCreate = false;
     }
     if (this.itemsCollection != null)
     {
         foreach (object obj2 in this.itemsCollection)
         {
             this.NativeAdd(obj2);
         }
         if (this.selectedIndex >= 0)
         {
             base.SendMessage(0x14e, this.selectedIndex, 0);
             this.UpdateText();
             this.selectedIndex = -1;
         }
     }
 }