本文整理汇总了C#中System.Windows.Window.RestoreBounds属性的典型用法代码示例。如果您正苦于以下问题:C# Window.RestoreBounds属性的具体用法?C# Window.RestoreBounds怎么用?C# Window.RestoreBounds使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类System.Windows.Window
的用法示例。
在下文中一共展示了Window.RestoreBounds属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1:
//引入命名空间
using System;
using System.ComponentModel;
using System.IO;
using System.IO.IsolatedStorage;
using System.Windows;
示例2: MainWindow
public partial class MainWindow : Window {
string filename = "settings.txt";
public MainWindow() {
InitializeComponent();
// Refresh restore bounds from previous window opening
IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForAssembly();
try {
using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream(this.filename, FileMode.Open, storage))
using (StreamReader reader = new StreamReader(stream)) {
// Read restore bounds value from file
Rect restoreBounds = Rect.Parse(reader.ReadLine());
this.Left = restoreBounds.Left;
this.Top = restoreBounds.Top;
this.Width = restoreBounds.Width;
this.Height = restoreBounds.Height;
}
}
catch (FileNotFoundException ex) {
// Handle when file is not found in isolated storage, which is when:
// * This is first application session
// * The file has been deleted
}
}
void MainWindow_Closing(object sender, CancelEventArgs e) {
// Save restore bounds for the next time this window is opened
IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForAssembly();
using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream(this.filename, FileMode.Create, storage))
using (StreamWriter writer = new StreamWriter(stream)) {
// Write restore bounds value to file
writer.WriteLine(this.RestoreBounds.ToString());
}
}
}