Example #1
0
        protected override void OnPaint(PaintEventArgs e)
        {
            e.Graphics.SmoothingMode     = SmoothingMode.AntiAlias;
            e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
            g = e.Graphics;

            //draw BackgroundImage
            if (BackgroundImage != null)
            {
                switch (BackgroundImageLayout)
                {
                case ImageLayout.Stretch:
                case ImageLayout.Zoom:
                    e.Graphics.DrawImage(
                        _formBkg,
                        ClientRectangle,
                        new Rectangle(0, 0, _formBkg.Width, _formBkg.Height),
                        GraphicsUnit.Pixel);
                    break;

                case ImageLayout.Center:
                case ImageLayout.None:
                case ImageLayout.Tile:
                    e.Graphics.DrawImage(
                        _formBkg,
                        ClientRectangle,
                        ClientRectangle,
                        GraphicsUnit.Pixel);
                    break;
                }
            }
            else
            {
                bmpFormExBack = (Bitmap)ServiceStationClient.ComponentUI.Properties.Resources.window;
                imageAttr     = new ImageAttributes();
                imageAttr.SetColorKey(bmpFormExBack.GetPixel(1, 1), bmpFormExBack.GetPixel(1, 1));
                g.DrawImage(bmpFormExBack, new Rectangle(0, 0, 5, 31), 0, 0, 5, 31, GraphicsUnit.Pixel);
                g.DrawImage(bmpFormExBack, new Rectangle(5, 0, this.Width - 10, 31), 5, 0, bmpFormExBack.Width - 10, 31, GraphicsUnit.Pixel);
                g.DrawImage(bmpFormExBack, new Rectangle(this.Width - 5, 0, 5, 31), bmpFormExBack.Width - 5, 0, 5, 31, GraphicsUnit.Pixel);
                g.DrawImage(bmpFormExBack, new Rectangle(0, 31, 5, this.Height - 36), 0, 31, 5, bmpFormExBack.Height - 36, GraphicsUnit.Pixel);
                g.DrawImage(bmpFormExBack, new Rectangle(5, 31, this.Width - 8, this.Height - 36), 5, 31, 5, bmpFormExBack.Height - 36, GraphicsUnit.Pixel);
                g.DrawImage(bmpFormExBack, new Rectangle(this.Width - 5, 31, 5, this.Height - 36), bmpFormExBack.Width - 5, 31, 5, bmpFormExBack.Height - 36, GraphicsUnit.Pixel);
                g.DrawImage(bmpFormExBack, new Rectangle(0, this.Height - 5, 5, 5), 0, bmpFormExBack.Height - 5, 5, 5, GraphicsUnit.Pixel);
                g.DrawImage(bmpFormExBack, new Rectangle(5, this.Height - 5, this.Width - 10, 5), 5, bmpFormExBack.Height - 5, bmpFormExBack.Width - 10, 5, GraphicsUnit.Pixel);
                g.DrawImage(bmpFormExBack, new Rectangle(this.Width - 5, this.Height - 5, 5, 5), bmpFormExBack.Width - 5, bmpFormExBack.Height - 5, 5, 5, GraphicsUnit.Pixel);
            }

            //draw system buttons
            SystemButtonManager.DrawSystemButtons(e.Graphics);

            //draw fringe
            CommonMethod.DrawFormFringe(this, e.Graphics, _formFringe, Radius);

            //draw icon
            if (Icon != null && ShowIconInTitle)
            {
                e.Graphics.DrawIcon(Icon, IconRect);
            }

            //draw text
            if (Text.Length != 0 && ShowTitle)
            {
                if (TextWithShadow)
                {
                    //using (Image textImg = CommonMethod.GetStringImgWithShadowEffect(Text, TextFont, TextForeColor, TextShadowColor, TextShadowWidth))
                    //{
                    //    e.Graphics.DrawImage(textImg, TextRect.Location);
                    //}
                }
                else
                {
                    TextRenderer.DrawText(
                        e.Graphics,
                        Text, TextFont,
                        TextRect,
                        TextForeColor,
                        TextFormatFlags.SingleLine | TextFormatFlags.EndEllipsis);
                }
            }
        }
Example #2
0
        private void WmNcHitTest(ref Message m)  //调整窗体大小
        {
            int   wparam        = m.LParam.ToInt32();
            Point mouseLocation = new Point(CommonMethod.LOWORD(wparam), CommonMethod.HIWORD(wparam));

            mouseLocation = PointToClient(mouseLocation);

            if (WindowState != FormWindowState.Maximized)
            {
                if (CanResize == true)
                {
                    if (mouseLocation.X < 5 && mouseLocation.Y < 5)
                    {
                        m.Result = new IntPtr(Win32API.HTTOPLEFT);
                        return;
                    }

                    if (mouseLocation.X > Width - 5 && mouseLocation.Y < 5)
                    {
                        m.Result = new IntPtr(Win32API.HTTOPRIGHT);
                        return;
                    }

                    if (mouseLocation.X < 5 && mouseLocation.Y > Height - 5)
                    {
                        m.Result = new IntPtr(Win32API.HTBOTTOMLEFT);
                        return;
                    }

                    if (mouseLocation.X > Width - 5 && mouseLocation.Y > Height - 5)
                    {
                        m.Result = new IntPtr(Win32API.HTBOTTOMRIGHT);
                        return;
                    }

                    if (mouseLocation.Y < 3)
                    {
                        m.Result = new IntPtr(Win32API.HTTOP);
                        return;
                    }

                    if (mouseLocation.Y > Height - 3)
                    {
                        m.Result = new IntPtr(Win32API.HTBOTTOM);
                        return;
                    }

                    if (mouseLocation.X < 3)
                    {
                        m.Result = new IntPtr(Win32API.HTLEFT);
                        return;
                    }

                    if (mouseLocation.X > Width - 3)
                    {
                        m.Result = new IntPtr(Win32API.HTRIGHT);
                        return;
                    }
                }
            }
            m.Result = new IntPtr(Win32API.HTCLIENT);
        }
Example #3
0
 protected override void OnCreateControl()
 {
     base.OnCreateControl();
     CommonMethod.SetFormRoundRectRgn(this, Radius);
 }