示例#1
0
        public void TransformForm2(byte opacity)
        {
            if (DesignMode)
                return;

            #if _DEMO
              MessageBox.Show("AlphaForm Transformer Demo Mode.\n\nPlease see www.alpha-forms.com for information","Demo Mode");
            #endif

            m_lwin = new LayeredWindowForm();

            // This control becomes transparent
            BackColor = Color.Transparent;

            // ParentForm becomes transparent via color key
            ParentForm.TransparencyKey = Color.FromArgb(0,0,1);
            ParentForm.BackColor = ParentForm.TransparencyKey;
            ParentForm.Visible = false;
            ParentForm.ShowInTaskbar = false;

            // Setting the layered window's TopMost to the main
            // form's value keeps the relative Z order the same for
            // the pair of windows
            m_lwin.TopMost = ParentForm.TopMost;

            if (BackgroundImage.Size != ParentForm.Size)
            {
            m_alphaBitmap = new Bitmap(ParentForm.Width, ParentForm.Height);
            Graphics gr = Graphics.FromImage(m_alphaBitmap);
                gr.SmoothingMode = SmoothingMode.None;
                gr.CompositingQuality = CompositingQuality.HighQuality;
                gr.InterpolationMode = InterpolationMode.HighQualityBilinear;

                gr.DrawImage(BackgroundImage, new Rectangle(0, 0, ParentForm.Width, ParentForm.Height),
                    new Rectangle(0, 0, BackgroundImage.Width, BackgroundImage.Height), GraphicsUnit.Pixel);
                gr.Dispose();
            }
            else
                m_alphaBitmap = new Bitmap(BackgroundImage);

            BackgroundImage = null;

            // Set the layered window bitmap
              m_lwin.SetBits(m_alphaBitmap,opacity);

            // For each transparent control, copy the layered window background
            // into the control's background

            foreach (Control cntrl in Controls)
              {
                if (cntrl.Tag != null && cntrl.Tag.ToString() == "back")
                    {
                    Bitmap bm = new Bitmap(cntrl.Width,cntrl.Height);
                    Graphics cg = Graphics.FromImage(bm);
                    cg.DrawImage(m_alphaBitmap, new Rectangle(0,0,cntrl.Width,cntrl.Height),
                        new Rectangle(cntrl.Location.X, cntrl.Location.Y, cntrl.Width, cntrl.Height),
                        GraphicsUnit.Pixel);
                    cntrl.BackgroundImage = bm;
                    cg.Dispose();
                    }
              }

              m_lwin.MouseDown += new MouseEventHandler(LayeredFormMouseDown);
            m_lwin.MouseMove += new MouseEventHandler(LayeredFormMouseMove);
            m_lwin.MouseUp += new MouseEventHandler(LayeredFormMouseUp);
            ParentForm.Move += new EventHandler(ParentFormMove);

            ParentForm.Opacity = opacity/255.0;
            m_lwin.Location = ParentForm.Location;
            m_lwin.Text = ParentForm.Text;

            // ParentForm becomes owned by layered window
            ParentForm.Visible = true;
            ParentForm.Owner = m_lwin;
            m_lwin.Visible = true;
        }
示例#2
0
        /// <summary>
        /// This methods does the following:
        /// <list type="number">
        /// <item>
        /// <description>Constructs a desktop composited frame window and shows it. This window's
        /// bitmap is built from this control's <c>BackgroundImage</c>.</description>
        /// </item>
        /// <item>
        /// <description>Calls <c>UpdateSkin</c> to updated the frame window's image data
        /// and build the main form's Region.</description>
        /// </item>
        /// <item>
        /// <description>The BackgroundImage is set to the main form's Background image.</description>
        /// </item>
        /// </list>
        /// <para>
        /// This method should only be called *once* from the main form's
        /// Load event. If the user wants to change the image at runtime,
        /// <see cref="AlphaFormTransformer.UpdateSkin" /> should be used.
        /// </para>
        /// </summary>
        /// <param name="opacity">
        /// Opacity of form [0..255]
        /// </param>
        public void TransformForm(byte opacity)
        {
            if (DesignMode)
                return;

            #if _DEMO
              MessageBox.Show("AlphaForm Transformer Demo Mode.\n\nPlease see www.alpha-forms.com for information","Demo Mode");
            #endif

            m_lwin = new LayeredWindowForm();

            // Setting the layered window's TopMost to the main
            // form's value keeps the relative Z order the same for
            // the pair of windows
            m_lwin.TopMost = ParentForm.TopMost;

            // We don't want the layered window form to show in the
            // taskbar now do we :-)
            m_lwin.ShowInTaskbar = false;

            // These will handle dragging for both the layered window
            // and the main form.
            m_lwin.MouseDown += new MouseEventHandler(LayeredFormMouseDown);
            m_lwin.MouseMove += new MouseEventHandler(LayeredFormMouseMove);
            m_lwin.MouseUp += new MouseEventHandler(LayeredFormMouseUp);
            if (m_transFormerDrags)
              {
            MouseDown += new MouseEventHandler(FormMouseDown);
            MouseMove += new MouseEventHandler(FormMouseMove);
            MouseUp += new MouseEventHandler(FormMouseUp);
              }
            ParentForm.Move += new EventHandler(ParentFormMove);

            // Form must be shown by specifying an owner so that activation of
            // the layered form activates the main app. It's also needed to keep
            // the Z order of the two windows in sync. Note that it's not
            // necessary to set the size of the layered window. The call to
            // SetBits() does this.
              m_lwin.Visible = false;
            m_lwin.Show(ParentForm);
            m_lwin.Location = ParentForm.Location;

            ParentForm.Opacity = opacity/255.0;

            if (BackgroundImage != null)
            {
            // Update the layered window bits and form region
            UpdateSkin(
              new Bitmap(BackgroundImage),
              ParentForm.BackgroundImage != null ? new Bitmap(ParentForm.BackgroundImage) : null,
              opacity);

            m_lwin.Visible = true;

              if (BackColor == Color.Transparent)
              {
                // user may have it this way in the designer too see the
                // main form's background image, but it can't be set to
                // this at runtime as the background image will be copied from
                // the main form to this control. Even in the absence of a background
                // image, it can't be transparent as it won't composite correctly
                // with the main form at runtime (quirk with Panel? - irrelevant in any case)
                BackColor = SystemColors.Control;
            }
              }
        }