Exemple #1
0
        private void GetBitmaps()
        {
            if (myBitmap == null ||
                myAlphaBitmap == null ||
                myBitmap.Width != Width ||
                myBitmap.Height != Height ||
                myAlphaBitmap.Width != Width ||
                myAlphaBitmap.Height != Height)
            {
                myBitmap      = null;
                myAlphaBitmap = null;
            }



            if (myBitmap == null)
            {
                myBitmap   = new Bitmap(this.ClientRectangle.Width, this.ClientRectangle.Height);//(Width,Height);
                myUpToDate = false;
            }


            if (!myUpToDate)
            {
                this.SetStyle(ControlStyles.UserPaint, false);

                WIN32.CaptureWindow(this, ref myBitmap);

                this.SetStyle(ControlStyles.UserPaint, true);
                this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
                this.BackColor = Color.FromArgb(myBackAlpha, myBackColor);
            }

            Rectangle       r2            = new Rectangle(0, 0, this.ClientRectangle.Width, this.ClientRectangle.Height);
            ImageAttributes tempImageAttr = new ImageAttributes();

            ColorMap[] tempColorMap = new ColorMap[1];
            tempColorMap[0]          = new ColorMap();
            tempColorMap[0].OldColor = Color.FromArgb(255, myBackColor);
            tempColorMap[0].NewColor = Color.FromArgb(myBackAlpha, myBackColor);

            tempImageAttr.SetRemapTable(tempColorMap);

            if (myAlphaBitmap != null)
            {
                myAlphaBitmap.Dispose();
            }


            myAlphaBitmap = new Bitmap(this.ClientRectangle.Width, this.ClientRectangle.Height);

            Graphics tempGraphics1 = Graphics.FromImage(myAlphaBitmap);

            //tempGraphics1.DrawImage(myBitmap, r2, 0, 0, this.ClientRectangle.Width, this.ClientRectangle.Height, GraphicsUnit.Pixel, tempImageAttr);
            tempGraphics1.DrawImage(myBitmap, r2, 0, 0, this.ClientRectangle.Width, this.ClientRectangle.Height, GraphicsUnit.Pixel, tempImageAttr);

            tempGraphics1.Dispose();

            //if (this.Focused && (this.SelectionLength == 0))
            //{
            //    Graphics tempGraphics2 = Graphics.FromImage(myAlphaBitmap);
            //    if (myCaretState)
            //    {
            //        Point caret = this.findCaret();
            //        Pen p = new Pen(this.ForeColor, 3);
            //        tempGraphics2.DrawLine(p, caret.X, caret.Y + 0, caret.X, caret.Y + myFontHeight);
            //        tempGraphics2.Dispose();
            //    }

            //}
        }
Exemple #2
0
        /// <summary>
        /// 显示和消失动画
        /// </summary>
        private void animate()
        {
            if (!timer1.Enabled)
            {
                if (backImg != null)
                {
                    backImg.Dispose();
                }
                backImg = null;
                backImg = new Bitmap(base.ClientRectangle.Width, base.ClientRectangle.Height);

                base.DrawToBitmap(backImg, base.ClientRectangle);

                if (alphaback != null)
                {
                    alphaback.Dispose();
                }
                alphaback = null;
                alphaback = new Bitmap(base.ClientRectangle.Width, base.ClientRectangle.Height);

                if (base.BackgroundImage != null)
                {
                    backgroundTemp       = (Bitmap)base.BackgroundImage;
                    base.BackgroundImage = null;
                }
                if (base.BackColor != Color.Transparent)
                {
                    backcolorTemp  = base.BackColor;
                    base.BackColor = Color.Transparent;
                }

                WIN32.CaptureWindow(this, ref alphaback);

                if (picbox != null)
                {
                    picbox.Dispose();
                }
                picbox = null;
                picbox = new uPictureBox();
                this.Controls.Add(picbox);
                picbox.Dock = DockStyle.Fill;

                if (!shown)
                {
                    picbox.Image = alphaback;
                }
                else
                {
                    picbox.Image = backImg;
                }
                picbox.BringToFront();
                base.Visible = true;

                if (!shown)
                {
                    if (gbackImg != null)
                    {
                        gbackImg.Dispose();
                    }
                    gbackImg = null;
                    gbackImg = Graphics.FromImage(alphaback);
                    gbackImg.SmoothingMode = SmoothingMode.HighQuality;
                }
                else
                {
                    if (gbackImg != null)
                    {
                        gbackImg.Dispose();
                    }
                    gbackImg = null;
                    gbackImg = Graphics.FromImage(backImg);
                    gbackImg.SmoothingMode = SmoothingMode.HighQuality;
                }
                isfirst = true;
                this.timer1.Start();
            }
        }