protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); if (Win32.DwmIsCompositionEnabled()) { this.BackColor = Color.Black; this.dwmDisTitleLabel.Visible = false; Win32.MARGINS m = new Win32.MARGINS { m_Top = 41, m_Left = 0, m_Right = 0, m_Bottom = 0 }; Win32.DwmExtendFrameIntoClientArea(this.Handle, ref m); Win32.WTA_OPTIONS wtaopt = new Win32.WTA_OPTIONS(); wtaopt.dwFlags = 3; wtaopt.dwMask = 3; extendedPanel1.TextSize = extendedPanel1.Size; Win32.SetWindowThemeAttribute(this.Handle, Win32.WINDOWTHEMEATTRIBUTETYPE.WTA_NONCLIENT, ref wtaopt, (uint)Marshal.SizeOf(typeof(Win32.WTA_OPTIONS))); //Win32.SetWindowThemeNonClientAttributes(this.Handle, 3, 3); } else { this.dwmDisTitleLabel.Font = new Font(SystemFonts.CaptionFont.FontFamily, this.dwmDisTitleLabel.Font.Size, FontStyle.Regular); } }
protected override void WndProc(ref Message m) { switch (m.Msg) { case Win32.WM_PAINT: // ガラス効果が使えるか確認 OperatingSystem os = Environment.OSVersion; if ((os.Platform == PlatformID.Win32NT) && (os.Version.Major >= 6) && (DwmApi.DwmIsCompositionEnabled())) { this.BackColor = Color.Black; extendedPanel1.Visible = true; messageLabel.Visible = false; Win32.MARGINS mar = new Win32.MARGINS(); mar.m_Left = -1; mar.m_Right = 0; mar.m_Bottom = 0; mar.m_Top = 0; Win32.DwmExtendFrameIntoClientArea(this.Handle, ref mar); // 文字描画 SizeF textsize = extendedPanel1.CreateGraphics().MeasureString(labelText, new Font(Properties.Resources.AboutFont, 12)); extendedPanel1.DrawText = labelText; extendedPanel1.TextLocation = new Point(0, 0); extendedPanel1.TextSize = textsize.ToSize(); extendedPanel1.GlowSize = 7; this.Size = new Size((int)textsize.Width + extendedPanel1.GlowSize + 10, (int)textsize.Height + extendedPanel1.GlowSize + 15); this.Location = new Point(Screen.PrimaryScreen.WorkingArea.Width - this.Width, Screen.PrimaryScreen.WorkingArea.Height - this.Height - 2); } else { this.BackColor = SystemColors.Control; this.Opacity = 0.9; this.Padding = new Padding(10); messageLabel.Text = labelText; messageLabel.Visible = true; this.ClientSize = new Size(messageLabel.Size.Width + 50, messageLabel.Height + 10); this.Location = new Point(Screen.PrimaryScreen.WorkingArea.Width - this.Width, Screen.PrimaryScreen.WorkingArea.Height - this.Height); } break; default: int wm_syscommand = 0x0112; int sc_move = 0xF010; if ((m.Msg == wm_syscommand) && ((m.WParam.ToInt32() & 0xFFF0) == sc_move)) { m.Result = IntPtr.Zero; return; } break; } base.WndProc(ref m); }
/// <summary> /// Use the form padding values to define a Glass margin /// </summary> private void SetGlassRegion() { // Set up the glass effect using padding as the defining glass region if (Win32.DwmIsCompositionEnabled()) { margins = new Win32.MARGINS(); margins.Top = padding_TOP; margins.Left = padding_LFT; margins.Bottom = padding_BTM; margins.Right = padding_RHT; Win32.DwmExtendFrameIntoClientArea(this.Handle, ref margins); } }
/// <summary> /// Use the form padding values to define a Glass margin /// </summary> private void setGlassRegion() { // Set up the glass effect using padding as the defining glass region // -1 margins indicate glass everywhere if (!Win32.DwmIsCompositionEnabled()) { return; } margins = new Win32.MARGINS(); margins.Top = -1; margins.Left = -1; margins.Bottom = -1; margins.Right = -1; Win32.DwmExtendFrameIntoClientArea(this.Handle, ref margins); }
void set_shadow(IntPtr handle, bool enabled) { if (composition_enabled()) { Win32.MARGINS[] shadow_state = new Win32.MARGINS[2] { new Win32.MARGINS(), new Win32.MARGINS() }; for (int i = 0; i < 2; ++i) { shadow_state[i].bottomHeight = i; shadow_state[i].topHeight = i; shadow_state[i].leftWidth = i; shadow_state[i].rightWidth = i; } Win32.DwmExtendFrameIntoClientArea(handle, ref shadow_state[enabled ? 1 : 0]); } }
protected override void OnHandleCreated(EventArgs e) { // Applies DWM drop shadow effect to the window (Windows Vista +). if (Environment.OSVersion.Version.Major >= 6) { try { var n = 2; var result = Win32.DwmSetWindowAttribute(Handle, 2, ref n, 4); if (result == 0) { var m = new Win32.MARGINS(1, 1, 1, 1); // 1px form border (do NOT use #000000 color). Win32.DwmExtendFrameIntoClientArea(Handle, ref m); } } catch (DllNotFoundException) { } } base.OnHandleCreated(e); }