如何保存和使用应用程序的窗口大小? [英] How to save and use app's window size?
本文介绍了如何保存和使用应用程序的窗口大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用.NET 4,什么是一个应用程序的窗口大小和位置保存在关闭和使用这些值到下运行它时启动应用程序的窗口的最佳方法是什么?
Using .NET 4, what is the best way to save an app's window size and position at closing and use these values to start the app's window next time it is run?
我不喜欢有接触任何一种注册表,但不知道是否有某种的app.config的(类似的Web.config ASP.NET应用程序),我可以使用有关Windows Presentation Foundation应用程序。
I prefer not to have to touch any kind of registry but don't know if there is some kind of app.config (similar to web.config for ASP.NET apps) that I can use for Windows Presentation Foundation apps.
感谢。
推荐答案
- 创建属性的应用程序设置的 LocationX 的 LocationY 的 WINDOWWIDTH 的 WINDOWHEIGHT 的(类型的 INT 的)
- 保存位置和大小
Form_FormClosed
- 装载和使用位置和大小
的Form_Load
Description
Windows Forms
- Create Properties in Application Settings LocationX, LocationY, WindowWidth, WindowHeight (of type int)
- Save Location and Size in
Form_FormClosed
- Load and apply Location and Size in
Form_Load
private void Form1_Load(object sender, EventArgs e)
{
this.Location = new Point(Properties.Settings.Default.LocationX, Properties.Settings.Default.LocationY);
this.Width = Properties.Settings.Default.WindowWidth;
this.Height = Properties.Settings.Default.WindowHeight;
}
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
Properties.Settings.Default.LocationX = this.Location.X;
Properties.Settings.Default.LocationY = this.Location.Y;
Properties.Settings.Default.WindowWidth = this.Width;
Properties.Settings.Default.WindowHeight = this.Height;
Properties.Settings.Default.Save();
}
更多信息
- 应用程序设置
- MSDN - Form.Load事件
- MSDN - Form.Closed事件
- Application Settings for Windows Forms
- MSDN - Form.Load Event
- MSDN - Form.Closed Event
- 创建在应用程序设置属性的 LocationX 的 LocationY 的 WINDOWWIDTH 的 WINDOWHEIGHT 的(类型的双的)
- 保存位置,并在
MainWindow_Closed
- 负荷大小和应用的位置和大小
MainWindow_Loaded
- Create Properties in Application Settings LocationX, LocationY, WindowWidth, WindowHeight (of type double)
- Save Location and Size in
MainWindow_Closed
- Load and apply Location and Size in
MainWindow_Loaded
More Information
void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
this.Left = Properties.Settings.Default.LocationX;
this.Top = Properties.Settings.Default.LocationY;
this.Width = Properties.Settings.Default.WindowWidth;
this.Height = Properties.Settings.Default.WindowHeight;
}
void MainWindow_Closed(object sender, EventArgs e)
{
Properties.Settings.Default.LocationX = this.Left;
Properties.Settings.Default.LocationY = this.Top;
Properties.Settings.Default.WindowWidth = this.Width;
Properties.Settings.Default.WindowHeight = this.Height;
Properties.Settings.Default.Save();
}
更多信息
- 应用程序设置
- MSDN - FrameworkElement.Loaded事件
- MSDN - Window.Closed事件
- Application Settings
- MSDN - FrameworkElement.Loaded Event
- MSDN - Window.Closed Event
More Information
这篇关于如何保存和使用应用程序的窗口大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文