Example #1
0
        /// <summary>
        /// 绘制标题区按钮
        /// </summary>
        /// <param name="g"></param>
        /// <param name="sizeInfo"></param>
        private void DrawControlBox(Graphics g, NonClientSizeInfo sizeInfo)
        {
            g.DrawImage(CloseButtonImage, sizeInfo.CloseBtnRect);
            g.DrawImage(MinimumButtonImage, sizeInfo.MinimumBtnRect);

            // 当前用户名不为空时,才显示用户名与用户图标
            if (!string.IsNullOrEmpty(UserName))
            {
                SizeF     nameSize = g.MeasureString(UserName, BtnFont);
                Rectangle nameRect = new Rectangle((int)(sizeInfo.UserNameImageRect.X - nameSize.Width),
                                                   sizeInfo.UserNameImageRect.Y, (int)Math.Ceiling(sizeInfo.UserNameImageRect.Width + nameSize.Width) + 2,
                                                   sizeInfo.UserNameImageRect.Height);
                StringFormat format = new StringFormat();
                format.Alignment     = StringAlignment.Near;
                format.LineAlignment = StringAlignment.Center;
                g.FillRectangle(BtnBackBrush, nameRect);
                g.DrawString(UserName, BtnFont, BtnForeBrush, nameRect, format);
                g.DrawImage(UserNameImage, sizeInfo.UserNameImageRect);
            }
        }
Example #2
0
        /// <summary>
        /// 获取非客户区窗体信息
        /// </summary>
        /// <param name="hwnd"></param>
        /// <returns></returns>
        private NonClientSizeInfo GetNonClientInfo(IntPtr hwnd)
        {
            NonClientSizeInfo info = new NonClientSizeInfo();

            info.BorderSize    = BorderSize;
            info.CaptionHeight = CaptionHeight;

            _RECT areatRect = new _RECT();

            GetWindowRect(hwnd, ref areatRect);

            int width  = areatRect.right - areatRect.left;
            int height = areatRect.bottom - areatRect.top;

            info.Width  = width;
            info.Height = height;

            Point xy = new Point(areatRect.left, areatRect.top);

            xy.Offset(-areatRect.left, -areatRect.top);

            info.CaptionRect = new Rectangle(xy.X, xy.Y
                                             , width, info.CaptionHeight);
            info.Rect       = new Rectangle(xy.X, xy.Y, width, height);
            info.ClientRect = new Rectangle(xy.X + info.BorderSize.Width,
                                            xy.Y + info.CaptionHeight + info.BorderSize.Height,
                                            width - info.BorderSize.Width * 2,
                                            height - info.CaptionHeight - info.BorderSize.Height * 2);

            info.CloseBtnRect = new Rectangle(new Point(xy.X + width - 2 * BtnHeight, info.BorderSize.Height),
                                              new Size(BtnHeight, BtnHeight));
            info.MinimumBtnRect    = new Rectangle(info.CloseBtnRect.X - BtnHeight, info.CloseBtnRect.Y, BtnHeight, BtnHeight);
            info.UserNameImageRect = new Rectangle(info.MinimumBtnRect.X - 2 * BtnHeight, info.CloseBtnRect.Y, BtnHeight, BtnHeight);

            return(info);
        }
Example #3
0
 /// <summary>
 /// 绘制标题文字
 /// </summary>
 /// <param name="g"></param>
 /// <param name="sizeInfo"></param>
 private void DrawCaptionTitle(Graphics g, NonClientSizeInfo sizeInfo)
 {
     g.DrawString(this.Text, TitleFont, TitleBrush, new PointF(TitleMargin, sizeInfo.CaptionRect.Y));
 }