示例#1
0
        /// <summary>
        /// Draws the background image defined by the visual style for the specified control part
        /// </summary>
        /// <param name="g">The Graphics to draw on</param>
        /// <param name="windowClass">The class of the part to draw</param>
        /// <param name="part">The part to draw</param>
        /// <param name="partState">The state of the part to draw</param>
        /// <param name="drawRect">The Rectangle in which the part is drawn</param>
        /// <param name="clipRect">The Rectangle that represents the clipping area for the part</param>
        public static void DrawThemeBackground(Graphics g, string windowClass, int part, int partState, Rectangle drawRect, Rectangle clipRect)
        {
            if (g == null || drawRect.Width <= 0 || drawRect.Height <= 0 || clipRect.Width <= 0 || clipRect.Height <= 0)
            {
                return;
            }

            // open theme data
            IntPtr hTheme = IntPtr.Zero;

            hTheme = I3NativeMethods.OpenThemeData(hTheme, windowClass);

            // make sure we have a valid handle
            if (hTheme != IntPtr.Zero)
            {
                // get a graphics object the UxTheme can draw into
                IntPtr hdc = g.GetHdc();

                // get the draw and clipping rectangles
                I3RECT dRect = I3RECT.FromRectangle(drawRect);
                I3RECT cRect = I3RECT.FromRectangle(clipRect);

                // draw the themed background
                I3NativeMethods.DrawThemeBackground(hTheme, hdc, part, partState, ref dRect, ref cRect);

                // clean up resources
                g.ReleaseHdc(hdc);
            }

            // close the theme handle
            I3NativeMethods.CloseThemeData(hTheme);
        }
示例#2
0
        /// <summary>
        /// 处理所有Paint事件
        /// Processes any Paint messages in the message queue
        /// </summary>
        private void FlushPaintMessages()
        {
            I3MSG msg = new I3MSG();

            while (I3NativeMethods.PeekMessage(ref msg, IntPtr.Zero, (int)I3WindowMessage.WM_PAINT, (int)I3WindowMessage.WM_PAINT, 1 /*PM_REMOVE*/))
            {
                I3NativeMethods.TranslateMessage(ref msg);
                I3NativeMethods.DispatchMessage(ref msg);
            }
        }
示例#3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void widthTextBox_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!char.IsDigit(e.KeyChar) && e.KeyChar != I3AsciiChars.Backspace && e.KeyChar != I3AsciiChars.Delete)
            {
                if ((Control.ModifierKeys & (Keys.Alt | Keys.Control)) == Keys.None)
                {
                    e.Handled = true;

                    I3NativeMethods.MessageBeep(0 /*MB_OK*/);
                }
            }
        }
示例#4
0
        /// <summary>
        /// Returns a Version object that contains information about the verion
        /// of the CommonControls that the application is using
        /// </summary>
        /// <returns>A Version object that contains information about the verion
        /// of the CommonControls that the application is using</returns>
        private static Version GetComctlVersion()
        {
            I3DLLVERSIONINFO comctlVersion = new I3DLLVERSIONINFO();

            comctlVersion.cbSize = Marshal.SizeOf(typeof(I3DLLVERSIONINFO));

            if (I3NativeMethods.DllGetVersion(ref comctlVersion) == 0)
            {
                return(new Version(comctlVersion.dwMajorVersion, comctlVersion.dwMinorVersion, comctlVersion.dwBuildNumber));
            }

            return(new Version());
        }
        /// <summary>
        /// 显示下拉容器
        /// Displays the drop down portion to the user
        /// </summary>
        protected virtual void ShowDropDown()
        {
            //TextBox.Location在准备编辑方法中被赋值
            Point p = this.EditingTable.PointToScreen(this.TextBox.Location);

            //p.Y += this.TextBox.Height + 1;
            p.Y = GetDropDownContainerTop(p);

            Rectangle screenBounds = Screen.GetBounds(p);

            if (p.Y + this.dropDownContainer.Height > screenBounds.Bottom)
            {
                p.Y -= this.TextBox.Height + this.dropDownContainer.Height + 1;
            }

            if (p.X + this.dropDownContainer.Width > screenBounds.Right)
            {
                II3CellRenderer renderer    = this.EditingTable.ColumnModel.GetCellRenderer(this.EditingCellPos.Column);
                int             buttonWidth = ((I3DropDownCellRenderer)renderer).ButtonWidth;

                p.X = p.X + this.TextBox.Width + buttonWidth - this.dropDownContainer.Width;
            }

            this.dropDownContainer.Location = p;

            this.parentForm.AddOwnedForm(this.dropDownContainer);
            this.activationListener.AssignHandle(this.parentForm.Handle);

            this.dropDownContainer.ShowDropDown();
            this.dropDownContainer.Activate();

            // A little bit of fun.  We've shown the popup,
            // but because we've kept the main window's
            // title bar in focus the tab sequence isn't quite
            // right.  This can be fixed by sending a tab,
            // but that on its own would shift focus to the
            // second control in the form.  So send a tab,
            // followed by a reverse-tab.

            // Send a Tab command:
            I3NativeMethods.keybd_event((byte)Keys.Tab, 0, 0, 0);
            I3NativeMethods.keybd_event((byte)Keys.Tab, 0, I3KeyEventFFlags.KEYEVENTF_KEYUP, 0);

            // Send a reverse Tab command:
            I3NativeMethods.keybd_event((byte)Keys.ShiftKey, 0, 0, 0);
            I3NativeMethods.keybd_event((byte)Keys.Tab, 0, 0, 0);
            I3NativeMethods.keybd_event((byte)Keys.Tab, 0, I3KeyEventFFlags.KEYEVENTF_KEYUP, 0);
            I3NativeMethods.keybd_event((byte)Keys.ShiftKey, 0, I3KeyEventFFlags.KEYEVENTF_KEYUP, 0);
        }
        /// <summary>
        /// Handler for the editors TextBox.KeyPress event
        /// </summary>
        /// <param name="sender">The object that raised the event</param>
        /// <param name="e">A KeyPressEventArgs that contains the event data</param>
        protected virtual void OnTextBoxKeyPress(object sender, KeyPressEventArgs e)
        {
            char enter  = I3AsciiChars.CarriageReturn;
            char escape = I3AsciiChars.Escape;
            char tab    = I3AsciiChars.HorizontalTab;

            NumberFormatInfo info = CultureInfo.CurrentCulture.NumberFormat;

            string decimalSeparator = info.NumberDecimalSeparator;
            string groupSeparator   = info.NumberGroupSeparator;
            string negativeSign     = info.NegativeSign;
            string character        = e.KeyChar.ToString();

            if ((!char.IsDigit(e.KeyChar) && !character.Equals(decimalSeparator) && !character.Equals(groupSeparator)) &&
                !character.Equals(negativeSign) && (e.KeyChar != tab))
            {
                if ((Control.ModifierKeys & (Keys.Alt | Keys.Control)) == Keys.None)
                {
                    e.Handled = true;

                    if (e.KeyChar == enter)
                    {
                        if (this.EditingTable != null)
                        {
                            this.EditingTable.StopEditing();
                        }
                    }
                    else if (e.KeyChar == escape)
                    {
                        if (this.EditingTable != null)
                        {
                            this.EditingTable.CancelEditing();
                        }
                    }
                    else
                    {
                        I3NativeMethods.MessageBeep(0 /*MB_OK*/);
                    }
                }
            }
            else
            {
                this.userEdit = true;
            }
        }
        /// <summary>
        /// 响应垂直滚动条滚动事件
        /// Occurs when the Table's vertical scrollbar is scrolled
        /// </summary>
        /// <param name="sender">The object that Raised the event</param>
        /// <param name="e">A ScrollEventArgs that contains the event data</param>
        protected void OnVerticalScroll(object sender, ScrollEventArgs e)
        {
            int scrollVal = e.OldValue - e.NewValue;

            if (scrollVal != 0)
            {
                Rectangle invalidateRect = new Rectangle(0, 0, this.Width - VScrollWidth, this.Height - HScrollHeight);
                I3RECT    scrollRect     = I3RECT.FromRectangle(invalidateRect);

                scrollRect.top += 1;
                I3NativeMethods.ScrollWindow(this.Handle, 0, scrollVal, ref scrollRect, ref scrollRect);

                if (scrollVal < 0)
                {
                    invalidateRect.Y = invalidateRect.Bottom + scrollVal;
                }
                invalidateRect.Height = Math.Abs(scrollVal) + 1;

                this.Invalidate(invalidateRect, false);
            }
        }
        protected void OnHorizontalScroll(object sender, ScrollEventArgs e)
        {
            int scrollVal = e.OldValue - e.NewValue;

            if (scrollVal != 0)
            {
                Rectangle invalidateRect = new Rectangle(0, 0, this.Width - VScrollWidth, this.Height - HScrollHeight);
                I3RECT    scrollRect     = I3RECT.FromRectangle(invalidateRect);

                //移动窗体的绘画区
                I3NativeMethods.ScrollWindow(this.Handle, scrollVal, 0, ref scrollRect, ref scrollRect);

                //计算重绘区域
                if (scrollVal < 0)
                {
                    invalidateRect.X = invalidateRect.Right + scrollVal;
                }
                invalidateRect.Width = Math.Abs(scrollVal) + 1;

                this.Invalidate(invalidateRect, false);
            }
        }
            /// <summary>
            /// 消息钩子,处理了WM_NCACTIVATE消息和WM_ACTIVATEAPP消息
            /// 这两个消息的意思?有待查找资料
            /// Processes Windows messages
            /// </summary>
            /// <param name="m">The Windows Message to process</param>
            protected override void WndProc(ref Message m)
            {
                base.WndProc(ref m);

                if (this.owner != null && this.owner.DroppedDown)
                {
                    if (m.Msg == (int)I3WindowMessage.WM_NCACTIVATE)
                    {
                        if (((int)m.WParam) == 0)
                        {
                            I3NativeMethods.SendMessage(this.Handle, (int)I3WindowMessage.WM_NCACTIVATE, 1, 0);
                        }
                    }
                    else if (m.Msg == (int)I3WindowMessage.WM_ACTIVATEAPP)
                    {
                        if ((int)m.WParam == 0)
                        {
                            this.owner.DroppedDown = false;

                            I3NativeMethods.PostMessage(this.Handle, (int)I3WindowMessage.WM_NCACTIVATE, 0, 0);
                        }
                    }
                }
            }
        private bool OnNcHitTest(ref Message m)
        {
            Point location = PointToClient(new Point(
                                               I3NativeMethods.LOWORD(m.LParam), I3NativeMethods.HIWORD(m.LParam)));
            Rectangle gripRect = Rectangle.Empty;

            if (_canResize && !_changeRegion)
            {
                if (_resizableLeft)
                {
                    if (_resizableTop)
                    {
                        gripRect = new Rectangle(0, 0, 6, 6);
                    }
                    else
                    {
                        gripRect = new Rectangle(
                            0,
                            Height - 6,
                            6,
                            6);
                    }
                }
                else
                {
                    if (_resizableTop)
                    {
                        gripRect = new Rectangle(Width - 6, 0, 6, 6);
                    }
                    else
                    {
                        gripRect = new Rectangle(
                            Width - 6,
                            Height - 6,
                            6,
                            6);
                    }
                }
            }

            if (gripRect.Contains(location))
            {
                if (_resizableLeft)
                {
                    if (_resizableTop)
                    {
                        m.Result = (IntPtr)I3NativeMethods.HTTOPLEFT;
                        return(true);
                    }
                    else
                    {
                        m.Result = (IntPtr)I3NativeMethods.HTBOTTOMLEFT;
                        return(true);
                    }
                }
                else
                {
                    if (_resizableTop)
                    {
                        m.Result = (IntPtr)I3NativeMethods.HTTOPRIGHT;
                        return(true);
                    }
                    else
                    {
                        m.Result = (IntPtr)I3NativeMethods.HTBOTTOMRIGHT;
                        return(true);
                    }
                }
            }
            else
            {
                Rectangle rectClient = ClientRectangle;
                if (location.X > rectClient.Right - 3 &&
                    location.X <= rectClient.Right &&
                    !_resizableLeft)
                {
                    m.Result = (IntPtr)I3NativeMethods.HTRIGHT;
                    return(true);
                }
                else if (location.Y > rectClient.Bottom - 3 &&
                         location.Y <= rectClient.Bottom &&
                         !_resizableTop)
                {
                    m.Result = (IntPtr)I3NativeMethods.HTBOTTOM;
                    return(true);
                }
                else if (location.X > -1 &&
                         location.X < 3 &&
                         _resizableLeft)
                {
                    m.Result = (IntPtr)I3NativeMethods.HTLEFT;
                    return(true);
                }
                else if (location.Y > -1 &&
                         location.Y < 3 &&
                         _resizableTop)
                {
                    m.Result = (IntPtr)I3NativeMethods.HTTOP;
                    return(true);
                }
            }
            return(false);
        }