コード例 #1
0
        public override void MoveControl(Rectangle valueRect, PropertyEnumerator propEnum)
        {
	        if (mInPlaceCtrl == null)
		        return;

            mInPlaceCtrl.BackColor = propEnum.Property.Value.BackColor;

            // Find where the string is actually displayed (a look instance could place it anywhere)
            Graphics graphics = mParentWnd.CreateGraphics();
	        Rectangle strRect = propEnum.Property.Value.GetStringValueRect(graphics, valueRect, Point.Empty /* not used */);
            strRect.X -= (propEnum.Property.Value.EditboxLeftMargin == -1 ?
                propEnum.Property.ParentGrid.GlobalTextMargin :
                propEnum.Property.Value.EditboxLeftMargin);
            strRect.Width = valueRect.Right - strRect.Left;

            // Calculate the height of the editbox, based on the font height

            Rectangle editRect = strRect;
            editRect.Inflate(0,-1);

            Win32Calls.TEXTMETRIC tm = new Win32Calls.TEXTMETRIC();
            Win32Calls.GetTextMetrics(graphics, mInPlaceCtrl.Font, ref tm);

            graphics.Dispose();

            int extraHeight = editRect.Height - tm.tmHeight;
            editRect.Y += extraHeight / 2;
            editRect.Height -= extraHeight;

            if (mInPlaceCtrl.Bounds != editRect)
                mInPlaceCtrl.Bounds = editRect;
        }
コード例 #2
0
ファイル: PropInPlaceList.cs プロジェクト: 15831944/Test3-1
        public virtual void RepositionChildren()
        {
            if (_edit != null)
            {
                Rectangle clientRect = ClientRectangle;
                if (clientRect.Width > 0)
                {
                    // Get the margins of the editbox
                    int rawMargins = Win32Calls.LoWord(Win32Calls.SendMessage(_edit.Handle, Win32Calls.EM_GETMARGINS, 0, 0));
                    int margins    = Win32Calls.LoWord(rawMargins) + Win32Calls.HiWord(rawMargins);

                    int buttonWidth = GetButtonWidth(null);

                    Rectangle valueRect = ClientRectangle;
                    valueRect.Width -= buttonWidth + 1;
                    valueRect.Height++; // for GetStringValueRect()
                    Graphics graphics = CreateGraphics();
                    valueRect = _ownerPropertyEnum.Property.Value.GetStringValueRect(graphics, valueRect, Point.Empty);
                    valueRect.Height--;

                    int margin  = _ownerPropertyEnum.Property.ParentGrid.GlobalTextMargin;
                    int leftPos = valueRect.Left - margin + (_ownerPropertyEnum.Property.Value.EditboxLeftMargin == -1 ? 0 :
                                                             margin - _ownerPropertyEnum.Property.Value.EditboxLeftMargin);

                    Rectangle editRect = new Rectangle(leftPos, 0, clientRect.Width - buttonWidth - leftPos, clientRect.Height);
                    editRect.Y++;
                    editRect.Height--;

                    // The width of the editbox can't be smaller than the margins or the margins would be void and the text misplaced
                    if (editRect.Width <= margins)
                    {
                        if (_edit.Focused)
                        {
                            Parent.Focus();
                        }

                        _edit.Visible = false;
                    }
                    else
                    {
                        _edit.Visible = true;

                        Win32Calls.TEXTMETRIC tm = new Win32Calls.TEXTMETRIC();
                        Win32Calls.GetTextMetrics(graphics, Font, ref tm);
                        int extraHeight = editRect.Height - tm.tmHeight;
                        editRect.Y      += extraHeight / 2;
                        editRect.Height -= extraHeight / 2;

                        _edit.Invalidate();
                        _edit.Bounds = editRect;
                    }

                    graphics.Dispose();
                }
            }

            Invalidate(false);
        }
コード例 #3
0
        public override void MoveControl(Rectangle valueRect, PropertyEnumerator propEnum)
        {
            if (mInPlaceCtrl == null)
            {
                return;
            }

            if (mInPlaceCtrl is PropInPlaceDateTime)
            {
                valueRect.Height--;

                Win32Calls.RECT rect = new Win32Calls.RECT();
                Win32Calls.GetWindowRect(mInPlaceCtrl.Handle, ref rect);
                Rectangle bounds = Rectangle.FromLTRB(rect.Left, rect.Top, rect.Right, rect.Bottom);
                bounds = mInPlaceCtrl.Parent.RectangleToClient(bounds);

                if (bounds != valueRect)
                {
                    mInPlaceCtrl.Invalidate();

                    // Bounds doesn't work because of DateTimePicker.PreferredHeight
                    Win32Calls.SetWindowPos(mInPlaceCtrl.Handle, IntPtr.Zero, valueRect.Left, valueRect.Top,
                                            valueRect.Width, valueRect.Height, Win32Calls.SWP_NOZORDER | Win32Calls.SWP_NOACTIVATE |
                                            Win32Calls.SWP_NOREDRAW);

                    // Causes WM_NCPAINT
                    Win32Calls.RedrawWindow(mInPlaceCtrl.Handle, IntPtr.Zero, IntPtr.Zero, 0x0561);
                }
            }
            else
            {
                // Find where the string is actually displayed (a look instance could place it anywhere)
                Graphics  graphics = mParentWnd.CreateGraphics();
                Rectangle strRect  = propEnum.Property.Value.GetStringValueRect(graphics, valueRect, Point.Empty /* not used */);
                strRect.X -= (propEnum.Property.Value.EditboxLeftMargin == -1 ? propEnum.Property.ParentGrid.GlobalTextMargin :
                              propEnum.Property.Value.EditboxLeftMargin);
                strRect.Width = valueRect.Right - strRect.Left;

                // Calculate the height of the editbox, based on the font height

                Rectangle editRect = strRect;
                editRect.Inflate(0, -1);

                Win32Calls.TEXTMETRIC tm = new Win32Calls.TEXTMETRIC();
                Win32Calls.GetTextMetrics(graphics, mInPlaceCtrl.Font, ref tm);

                graphics.Dispose();

                int extraHeight = editRect.Height - tm.tmHeight;
                editRect.Y      += extraHeight / 2;
                editRect.Height -= extraHeight;

                if (mInPlaceCtrl.Bounds != editRect)
                {
                    mInPlaceCtrl.Bounds = editRect;
                }
            }
        }
コード例 #4
0
ファイル: PropInPlaceButton.cs プロジェクト: 15831944/Test3-1
        public virtual void RepositionChildren()
        {
            if (mEdit != null)
            {
                Rectangle clientRect = ClientRectangle;
                if (clientRect.Width > 0)
                {
                    // Get the margins of the editbox
                    int rawMargins = Win32Calls.LoWord(Win32Calls.SendMessage(mEdit.Handle, Win32Calls.EM_GETMARGINS, 0, 0));
                    int margins    = Win32Calls.LoWord(rawMargins) + Win32Calls.HiWord(rawMargins);

                    int margin  = mOwnerPropertyEnum.Property.ParentGrid.GlobalTextMargin;
                    int leftPos = (mOwnerPropertyEnum.Property.Value.EditboxLeftMargin == -1 ? 0 :
                                   margin - mOwnerPropertyEnum.Property.Value.EditboxLeftMargin);

                    int       buttonWidth = GetButtonWidth(null);
                    Rectangle editRect    = new Rectangle(leftPos, 0, clientRect.Width - buttonWidth - leftPos, clientRect.Height);
                    editRect.Y++;
                    editRect.Height--;

                    // The width of the editbox can't be smaller than the margins or the margins would be void and the text misplaced
                    if (editRect.Width <= margins)
                    {
                        if (mEdit.Focused)
                        {
                            Parent.Focus();
                        }

                        mEdit.Visible = false;
                    }
                    else
                    {
                        mEdit.Visible = true;

                        Win32Calls.TEXTMETRIC tm = new Win32Calls.TEXTMETRIC();
                        Graphics graphics        = CreateGraphics();
                        Win32Calls.GetTextMetrics(graphics, Font, ref tm);
                        graphics.Dispose();
                        int extraHeight = editRect.Height - tm.tmHeight;
                        editRect.Y      += extraHeight / 2;
                        editRect.Height -= extraHeight / 2;

                        mEdit.Invalidate();
                        mEdit.Bounds = editRect;
                    }
                }
            }

            Invalidate(false);

//            mEdit.Location = new Point(0, 0);
//          mEdit.Size = new Size(ClientRectangle.Width - SystemInformation.VerticalScrollBarWidth, ClientRectangle.Height);
        }
コード例 #5
0
        public void InitializeContent(PropertyEnumerator propEnum, string currentValue, object valueKey)
        {
            _ownerPropertyEnumerator = propEnum;

            int width = 0;

            _propValue = (valueKey == null ? propEnum.Property.Value : propEnum.Property.GetValue(valueKey));

            Graphics graphics = CreateGraphics();

            object[] displayedValues = _propValue.GetDisplayedValues();
            foreach (object str in displayedValues)
            {
                Items.Add(str.ToString());

                Size size = Win32Calls.GetTextExtent(graphics, str.ToString(), propEnum.Property.ParentGrid.Font);
                if (width < size.Width)
                {
                    width = size.Width;
                }
            }

            Win32Calls.TEXTMETRIC tm = new Win32Calls.TEXTMETRIC();
            Win32Calls.GetTextMetrics(graphics, propEnum.Property.ParentGrid.Font, ref tm);

            graphics.Dispose();

            ItemHeight = tm.tmHeight + propEnum.Property.ParentGrid.PropertyVerticalMargin - 2;

            Height = Math.Max(ItemHeight, Math.Min(200, ItemHeight * displayedValues.Length));

            int margin = propEnum.Property.ParentGrid.GlobalTextMargin;

            Width = width + 2 * margin;
            if (_propValue.ImageList != null)
            {
                Width += ItemHeight + margin;
            }

            DrawMode = DrawMode.OwnerDrawFixed;

            SelectedItem = currentValue;
//            SelectedItem = _propValue.DisplayString;
        }
コード例 #6
0
        public override void MoveControl(Rectangle valueRect, PropertyEnumerator propEnum)
        {
            if (mInPlaceCtrl == null)
            {
                return;
            }

            mInPlaceCtrl.BackColor = propEnum.Property.Value.BackColor;

            // Find where the string is actually displayed (a look instance could place it anywhere)
            Graphics  graphics = mParentWnd.CreateGraphics();
            Rectangle strRect  = propEnum.Property.Value.GetStringValueRect(graphics, valueRect, Point.Empty /* not used */);

            strRect.X -= (propEnum.Property.Value.EditboxLeftMargin == -1 ?
                          propEnum.Property.ParentGrid.GlobalTextMargin :
                          propEnum.Property.Value.EditboxLeftMargin);
            strRect.Width = valueRect.Right - strRect.Left;

            // Calculate the height of the editbox, based on the font height

            Rectangle editRect = strRect;

            editRect.Inflate(0, -1);

            Win32Calls.TEXTMETRIC tm = new Win32Calls.TEXTMETRIC();
            Win32Calls.GetTextMetrics(graphics, mInPlaceCtrl.Font, ref tm);

            graphics.Dispose();

            int extraHeight = editRect.Height - tm.tmHeight;

            editRect.Y      += extraHeight / 2;
            editRect.Height -= extraHeight;

            if (mInPlaceCtrl.Bounds != editRect)
            {
                mInPlaceCtrl.Bounds = editRect;
            }
        }
コード例 #7
0
        public void RepositionChildren()
        {
            if (_edit != null)
            {
                Rectangle clientRect = ClientRectangle;
                if (clientRect.Width > 0)
                {
                    // Get the margins of the editbox
                    int rawMargins = Win32Calls.LoWord(Win32Calls.SendMessage(_edit.Handle, Win32Calls.EM_GETMARGINS, 0, 0));
                    int margins    = Win32Calls.LoWord(rawMargins) + Win32Calls.HiWord(rawMargins);

                    int       buttonWidth = GetButtonWidth(null);
                    Rectangle editRect    = new Rectangle(0, 0, clientRect.Width - buttonWidth, clientRect.Height);
                    editRect.Inflate(0, -1);

                    // The width of the editbox can't be smaller than the margins or the margins would be void and the text misplaced
                    if (editRect.Width <= margins)
                    {
                        _edit.Visible = false;
                    }
                    else
                    {
                        _edit.Visible = true;

                        Win32Calls.TEXTMETRIC tm = new Win32Calls.TEXTMETRIC();
                        Graphics graphics        = CreateGraphics();
                        Win32Calls.GetTextMetrics(graphics, Font, ref tm);
                        graphics.Dispose();
                        editRect.Y      += (clientRect.Height - tm.tmHeight) / 2;
                        editRect.Height -= (clientRect.Height - tm.tmHeight) / 2;

                        _edit.Invalidate();
                        _edit.Bounds = editRect;
                    }
                }
            }

            Invalidate(false);
        }
コード例 #8
0
ファイル: PropInPlaceList.cs プロジェクト: ChrisMoreton/Test3
        public virtual void RepositionChildren()
        {
            if (_edit != null)
            {
                Rectangle clientRect = ClientRectangle;
                if (clientRect.Width > 0)
                {
                    // Get the margins of the editbox
                    int rawMargins = Win32Calls.LoWord(Win32Calls.SendMessage(_edit.Handle, Win32Calls.EM_GETMARGINS, 0, 0));
                    int margins = Win32Calls.LoWord(rawMargins) + Win32Calls.HiWord(rawMargins);

                    int buttonWidth = GetButtonWidth(null);

                    Rectangle valueRect = ClientRectangle;
                    valueRect.Width -= buttonWidth + 1;
                    valueRect.Height++; // for GetStringValueRect()
                    Graphics graphics = CreateGraphics();
                    valueRect = _ownerPropertyEnum.Property.Value.GetStringValueRect(graphics, valueRect, Point.Empty);
                    valueRect.Height--;

                    int margin = _ownerPropertyEnum.Property.ParentGrid.GlobalTextMargin;
                    int leftPos = valueRect.Left - margin + (_ownerPropertyEnum.Property.Value.EditboxLeftMargin == -1 ? 0 :
                        margin - _ownerPropertyEnum.Property.Value.EditboxLeftMargin);

                    Rectangle editRect = new Rectangle(leftPos, 0, clientRect.Width - buttonWidth - leftPos, clientRect.Height);
                    editRect.Y++;
                    editRect.Height--;

                    // The width of the editbox can't be smaller than the margins or the margins would be void and the text misplaced
                    if (editRect.Width <= margins)
                    {
                        if (_edit.Focused)
                            Parent.Focus();

                        _edit.Visible = false;
                    }
                    else
                    {
                        _edit.Visible = true;

                        Win32Calls.TEXTMETRIC tm = new Win32Calls.TEXTMETRIC();
                        Win32Calls.GetTextMetrics(graphics, Font, ref tm);
                        int extraHeight = editRect.Height - tm.tmHeight;
                        editRect.Y += extraHeight / 2;
                        editRect.Height -= extraHeight / 2;

                        _edit.Invalidate();
                        _edit.Bounds = editRect;
                    }

                    graphics.Dispose();
                }
            }

            Invalidate(false);
        }
コード例 #9
0
        public virtual void RepositionChildren()
        {
            Rectangle clientRect = ClientRectangle;

            if (clientRect.Width > 0)
            {
                if (_edit != null)
                {
                    // Get the margins of the editbox
                    int rawMargins = Win32Calls.LoWord(Win32Calls.SendMessage(_edit.Handle, Win32Calls.EM_GETMARGINS, 0, 0));
                    int margins    = Win32Calls.LoWord(rawMargins) + Win32Calls.HiWord(rawMargins);

                    int margin  = _ownerPropertyEnum.Property.ParentGrid.GlobalTextMargin;
                    int leftPos = (_ownerPropertyEnum.Property.Value.EditboxLeftMargin == -1 ? 0 :
                                   margin - _ownerPropertyEnum.Property.Value.EditboxLeftMargin);

                    Rectangle editRect = new Rectangle(leftPos, 0, GetEditWidth() - leftPos, clientRect.Height);
                    editRect.Y++;
                    editRect.Height--;

                    // The width of the editbox can't be smaller than the margins or the margins would be void and the text misplaced
                    if (editRect.Width <= margins)
                    {
                        if (_edit.Focused)
                        {
                            Parent.Focus();
                        }

                        _edit.Visible = false;
                    }
                    else
                    {
                        _edit.Visible = true;

                        Win32Calls.TEXTMETRIC tm = new Win32Calls.TEXTMETRIC();
                        Graphics graphics        = CreateGraphics();
                        Win32Calls.GetTextMetrics(graphics, Font, ref tm);
                        graphics.Dispose();
                        int extraHeight = editRect.Height - tm.tmHeight;
                        editRect.Y      += extraHeight / 2;
                        editRect.Height -= extraHeight / 2;

                        _edit.Invalidate();
                        _edit.Bounds = editRect;
                    }

                    if (_trackbar != null)
                    {
                        Rectangle trackbarRect = new Rectangle(editRect.Right, 0 + 2, clientRect.Right - editRect.Right, clientRect.Height - 2);
                        if (trackbarRect.Width < 15)
                        {
                            _trackbar.Visible = false;
                        }
                        else
                        {
                            _trackbar.Visible = true;
                            _trackbar.Bounds  = trackbarRect;
                        }
                    }
                }
                else
                {
                    if (_trackbar != null)
                    {
                        int       editWidth    = GetEditWidth();
                        Rectangle trackbarRect = new Rectangle(editWidth, 0, clientRect.Width - editWidth, clientRect.Height);
                        _trackbar.Bounds = trackbarRect;
                    }
                }
            }
        }
コード例 #10
0
        public virtual void RepositionChildren()
        {
            if (mEdit != null)
            {
                Rectangle clientRect = ClientRectangle;
                if (clientRect.Width > 0)
                {
                    // Get the margins of the editbox
                    int rawMargins = Win32Calls.LoWord(Win32Calls.SendMessage(mEdit.Handle, Win32Calls.EM_GETMARGINS, 0, 0));
                    int margins = Win32Calls.LoWord(rawMargins) + Win32Calls.HiWord(rawMargins);

                    int margin = mOwnerPropertyEnum.Property.ParentGrid.GlobalTextMargin;
                    int leftPos = (mOwnerPropertyEnum.Property.Value.EditboxLeftMargin == -1 ? 0 :
                        margin - mOwnerPropertyEnum.Property.Value.EditboxLeftMargin);

                    int buttonWidth = GetButtonWidth(null);
                    Rectangle editRect = new Rectangle(leftPos, 0, clientRect.Width - buttonWidth - leftPos, clientRect.Height);
                    editRect.Y++;
                    editRect.Height--;

                    // The width of the editbox can't be smaller than the margins or the margins would be void and the text misplaced
                    if (editRect.Width <= margins)
                    {
                        if (mEdit.Focused)
                            Parent.Focus();

                        mEdit.Visible = false;
                    }
                    else
                    {
                        mEdit.Visible = true;

                        Win32Calls.TEXTMETRIC tm = new Win32Calls.TEXTMETRIC();
                        Graphics graphics = CreateGraphics();
                        Win32Calls.GetTextMetrics(graphics, Font, ref tm);
                        graphics.Dispose();
                        int extraHeight = editRect.Height - tm.tmHeight;
                        editRect.Y += extraHeight / 2;
                        editRect.Height -= extraHeight / 2;

                        mEdit.Invalidate();
                        mEdit.Bounds = editRect;
                    }
                }
            }

            Invalidate(false);

//            mEdit.Location = new Point(0, 0);
//          mEdit.Size = new Size(ClientRectangle.Width - SystemInformation.VerticalScrollBarWidth, ClientRectangle.Height);
        }
コード例 #11
0
        public void InitializeContent(PropertyEnumerator propEnum, string currentValue, object valueKey)
        {
            _ownerPropertyEnumerator = propEnum;

            int width = 0;

            _propValue = (valueKey == null ? propEnum.Property.Value : propEnum.Property.GetValue(valueKey));

            Graphics graphics = CreateGraphics();

            object[] displayedValues = _propValue.GetDisplayedValues();
            foreach(object str in displayedValues)
            {
                Items.Add(str.ToString());

                Size size = Win32Calls.GetTextExtent(graphics, str.ToString(), propEnum.Property.ParentGrid.Font);
                if (width < size.Width)
                    width = size.Width;
            }

            Win32Calls.TEXTMETRIC tm = new Win32Calls.TEXTMETRIC();
            Win32Calls.GetTextMetrics(graphics, propEnum.Property.ParentGrid.Font, ref tm);

            graphics.Dispose();

            ItemHeight = tm.tmHeight + propEnum.Property.ParentGrid.PropertyVerticalMargin - 2;

            Height = Math.Max(ItemHeight, Math.Min(200, ItemHeight * displayedValues.Length));

            int margin = propEnum.Property.ParentGrid.GlobalTextMargin;
            Width = width + 2 * margin;
            if (_propValue.ImageList != null)
                Width += ItemHeight + margin;

            DrawMode = DrawMode.OwnerDrawFixed;

            SelectedItem = currentValue;
//            SelectedItem = _propValue.DisplayString;
        }
コード例 #12
0
        public virtual void RepositionChildren()
        {
            Rectangle clientRect = ClientRectangle;
            if (clientRect.Width > 0)
            {
                if (_edit != null)
                {
                    // Get the margins of the editbox
                    int rawMargins = Win32Calls.LoWord(Win32Calls.SendMessage(_edit.Handle, Win32Calls.EM_GETMARGINS, 0, 0));
                    int margins = Win32Calls.LoWord(rawMargins) + Win32Calls.HiWord(rawMargins);

                    int margin = _ownerPropertyEnum.Property.ParentGrid.GlobalTextMargin;
                    int leftPos = (_ownerPropertyEnum.Property.Value.EditboxLeftMargin == -1 ? 0 :
                        margin - _ownerPropertyEnum.Property.Value.EditboxLeftMargin);

                    Rectangle editRect = new Rectangle(leftPos, 0, GetEditWidth() - leftPos, clientRect.Height);
                    editRect.Y++;
                    editRect.Height--;

                    // The width of the editbox can't be smaller than the margins or the margins would be void and the text misplaced
                    if (editRect.Width <= margins)
                    {
                        if (_edit.Focused)
                            Parent.Focus();

                        _edit.Visible = false;
                    }
                    else
                    {
                        _edit.Visible = true;

                        Win32Calls.TEXTMETRIC tm = new Win32Calls.TEXTMETRIC();
                        Graphics graphics = CreateGraphics();
                        Win32Calls.GetTextMetrics(graphics, Font, ref tm);
                        graphics.Dispose();
                        int extraHeight = editRect.Height - tm.tmHeight;
                        editRect.Y += extraHeight / 2;
                        editRect.Height -= extraHeight / 2;

                        _edit.Invalidate();
                        _edit.Bounds = editRect;
                    }

                    if (_trackbar != null)
                    {
                        Rectangle trackbarRect = new Rectangle(editRect.Right, 0+2, clientRect.Right - editRect.Right, clientRect.Height-2);
                        if (trackbarRect.Width < 15)
                            _trackbar.Visible = false;
                        else
                        {
                            _trackbar.Visible = true;
                            _trackbar.Bounds = trackbarRect;
                        }
                    }
                }
                else
                {
                    if (_trackbar != null)
                    {
                        int editWidth = GetEditWidth();
                        Rectangle trackbarRect = new Rectangle(editWidth, 0, clientRect.Width - editWidth, clientRect.Height);
                        _trackbar.Bounds = trackbarRect;
                    }
                }
            }
        }
コード例 #13
0
        public override void MoveControl(Rectangle valueRect, PropertyEnumerator propEnum)
        {
            if (mInPlaceCtrl == null)
                return;

            if (mInPlaceCtrl is PropInPlaceDateTime)
            {
                valueRect.Height--;

                Win32Calls.RECT rect = new Win32Calls.RECT();
                Win32Calls.GetWindowRect(mInPlaceCtrl.Handle, ref rect);
                Rectangle bounds = Rectangle.FromLTRB(rect.Left, rect.Top, rect.Right, rect.Bottom);
                bounds = mInPlaceCtrl.Parent.RectangleToClient(bounds);

                if (bounds != valueRect)
                {
                    mInPlaceCtrl.Invalidate();

                    // Bounds doesn't work because of DateTimePicker.PreferredHeight
                    Win32Calls.SetWindowPos(mInPlaceCtrl.Handle, IntPtr.Zero, valueRect.Left, valueRect.Top,
                        valueRect.Width, valueRect.Height, Win32Calls.SWP_NOZORDER | Win32Calls.SWP_NOACTIVATE |
                        Win32Calls.SWP_NOREDRAW);

                    // Causes WM_NCPAINT
                    Win32Calls.RedrawWindow(mInPlaceCtrl.Handle, IntPtr.Zero, IntPtr.Zero, 0x0561);
                }
            }
            else
            {
                // Find where the string is actually displayed (a look instance could place it anywhere)
                Graphics graphics = mParentWnd.CreateGraphics();
                Rectangle strRect = propEnum.Property.Value.GetStringValueRect(graphics, valueRect, Point.Empty /* not used */);
                strRect.X -= (propEnum.Property.Value.EditboxLeftMargin == -1 ? propEnum.Property.ParentGrid.GlobalTextMargin :
                    propEnum.Property.Value.EditboxLeftMargin);
                strRect.Width = valueRect.Right - strRect.Left;

                // Calculate the height of the editbox, based on the font height

                Rectangle editRect = strRect;
                editRect.Inflate(0, -1);

                Win32Calls.TEXTMETRIC tm = new Win32Calls.TEXTMETRIC();
                Win32Calls.GetTextMetrics(graphics, mInPlaceCtrl.Font, ref tm);

                graphics.Dispose();

                int extraHeight = editRect.Height - tm.tmHeight;
                editRect.Y += extraHeight / 2;
                editRect.Height -= extraHeight;

                if (mInPlaceCtrl.Bounds != editRect)
                    mInPlaceCtrl.Bounds = editRect;
            }
        }
コード例 #14
0
        public void RepositionChildren()
        {
            if (_edit != null)
            {
                Rectangle clientRect = ClientRectangle;
                if (clientRect.Width > 0)
                {
                    // Get the margins of the editbox
                    int rawMargins = Win32Calls.LoWord(Win32Calls.SendMessage(_edit.Handle, Win32Calls.EM_GETMARGINS, 0, 0));
                    int margins = Win32Calls.LoWord(rawMargins) + Win32Calls.HiWord(rawMargins);

                    int buttonWidth = GetButtonWidth(null);
                    Rectangle editRect = new Rectangle(0, 0, clientRect.Width - buttonWidth, clientRect.Height);
                    editRect.Inflate(0, -1);

                    // The width of the editbox can't be smaller than the margins or the margins would be void and the text misplaced
                    if (editRect.Width <= margins)
                        _edit.Visible = false;
                    else
                    {
                        _edit.Visible = true;

                        Win32Calls.TEXTMETRIC tm = new Win32Calls.TEXTMETRIC();
                        Graphics graphics = CreateGraphics();
                        Win32Calls.GetTextMetrics(graphics, Font, ref tm);
                        graphics.Dispose();
                        editRect.Y += (clientRect.Height - tm.tmHeight) / 2;
                        editRect.Height -= (clientRect.Height - tm.tmHeight) / 2;

                        _edit.Invalidate();
                        _edit.Bounds = editRect;
                    }
                }
            }

            Invalidate(false);
        }