最近在自学wpf,通过网上找资料。做了一个全屏功能。现纪录如下。以供日后使用。这是用的一个能获得焦点的控件做的实验。我用的是一个textbox控件。此控件的keyup事件如下(测试用)。以下代码便可以模拟实现全屏。如果按esc键的话。则可以相应的去掉全屏。
private void ellipse_KeyUp(object sender, KeyEventArgs e)
{
showmsg.Text = " the key "+e.Key.ToString()+" was prestented while focus on "+(e.Source as FrameworkElement).Name;
if (e.Key == Key.Escape)//按esc键去掉全屏
{
this.WindowState = WindowState.Normal;
this.WindowStyle = WindowStyle.SingleBorderWindow;
this.Visibility = Visibility.Visible;
}
else//实现全屏
{
this.Visibility = Visibility.Hidden;
this.WindowState = WindowState.Maximized;
this.WindowStyle = WindowStyle.None;
this.Visibility = Visibility.Visible;
}
}