[英]Paint or Hide Control Box for Borderless Form while maximize and minimize
我已附上一個有關此問題的小例子。 在最大化和最小化無邊界表單期間如何完全隱藏控制框
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Security;
using System.Threading;
namespace TalkTime
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private const int WM_NCPAINT = 0x0085;
protected override void WndProc(ref Message m)
{
int message = m.Msg;
switch (m.Msg)
{
case WM_NCPAINT:
{
Thread.Sleep(100);
return;
}
}
base.WndProc(ref m);
}
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.Style |= 0x20000;
return cp;
}
}
}
}
我把線程顯示出確切的問題出在哪里。
我想與控制箱和表單名稱有關的黑色矩形會出現在表單之前,而我想在最大化和最小化時完全隱藏它。
我可以確認這個問題。 從最小化狀態還原無邊界Form
,很短的時間在窗口的左上方會顯示標題欄的重影。
重現問題
要重現該問題,只需將FormBorderStyle
屬性設置為None
,然后在計時器中最小化和還原它,即可創建無邊界表單。 還原后,顯示表單啟動程序,並在窗口的左上方查看。
using System;
using System.Windows.Forms;
class Form1 : Form
{
public Form1()
{
var timer = new Timer() { Interval = 1000 };
this.Text = "Some Text";
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
timer.Tick += (x, y) =>
{
if (this.WindowState != FormWindowState.Minimized)
this.WindowState = FormWindowState.Minimized;
else
this.WindowState = FormWindowState.Normal;
};
timer.Start();
}
}
解決方法
這是我用來消除閃爍的解決方法。 將事件處理程序添加到上面的Form1
類中並為Activated
事件注冊它this.Activated += Form1_Activated;
。
private void Form1_Activated(object sender, EventArgs e)
{
if (this.WindowState == FormWindowState.Minimized)
this.Hide();
this.BeginInvoke(new Action(() =>
{
if (this.WindowState != FormWindowState.Minimized && !Visible)
this.Show();
}));
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.