Example #1
0
        public NotepadClone()
        {
            Assembly asmbly = Assembly.GetExecutingAssembly();                                                                                                                            //获取当前执行代码的程序集
            AssemblyTitleAttribute title = (AssemblyTitleAttribute)asmbly.GetCustomAttributes(typeof(AssemblyTitleAttribute), false)[0];                                                  //获取此程序集的程序集说明

            strAppTitle = title.Title;                                                                                                                                                    //程序集标题
            AssemblyProductAttribute product = (AssemblyProductAttribute)asmbly.GetCustomAttributes(typeof(AssemblyProductAttribute), false)[0];                                          //获取此程序集的程序集清单

            strAppData = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "HiWPF\\" + product.Product + "\\" + product.Product + ".Settings.xml"); //配置文件保存路径  C:\Users\Yang\AppData\Local\HiWPF\NotedpadClone\NotedpadClone.Settings.xml

            DockPanel dock = new DockPanel();

            this.Content = dock;

            menu = new Menu();
            dock.Children.Add(menu);
            DockPanel.SetDock(menu, Dock.Top);

            status = new StatusBar();
            dock.Children.Add(status);
            DockPanel.SetDock(status, Dock.Bottom);

            statLineCol = new StatusBarItem();
            statLineCol.HorizontalAlignment = HorizontalAlignment.Right;
            status.Items.Add(statLineCol);
            DockPanel.SetDock(statLineCol, Dock.Right);

            txtbox = new TextBox();
            txtbox.AcceptsReturn = true;
            txtbox.AcceptsTab    = true;
            txtbox.VerticalScrollBarVisibility   = ScrollBarVisibility.Auto;
            txtbox.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
            txtbox.TextChanged      += TextBoxOnTextChanged;
            txtbox.SelectionChanged += TextBoxOnSelectionChanged;
            dock.Children.Add(txtbox);

            AddFileMenu(menu);   //NotepadClone.File.cs
            AddEditMenu(menu);   //NotepadClone.Edit.cs
            AddFormatMenu(menu); //NotepadClone.Format.cs
            AddViewMenu(menu);   //NotepadClone.View.cs
            AddHelpMenu(menu);   //NotedpadClone.Help.cs

            settings = (NotepadCloneSetting)LoadSettings();

            this.WindowState = settings.WindowState;

            if (settings.RestoreBounds != Rect.Empty)
            {
                this.Left   = settings.RestoreBounds.Left;
                this.Top    = settings.RestoreBounds.Top;
                this.Width  = settings.RestoreBounds.Width;
                this.Height = settings.RestoreBounds.Height;
            }

            txtbox.TextWrapping = settings.TextWrapping;
            txtbox.FontFamily   = new FontFamily(settings.FontFamily);
            txtbox.FontStyle    = (FontStyle) new FontStyleConverter().ConvertFromString(settings.FontStyle);
            txtbox.FontWeight   = (FontWeight) new FontWeightConverter().ConvertFromString(settings.FontWeight);
            txtbox.FontStretch  = (FontStretch) new FontStretchConverter().ConvertFromString(settings.FontStretch);
            txtbox.FontSize     = settings.FontSize;

            this.Loaded += WindowOnLoaded;

            txtbox.Focus();
        }
Example #2
0
 protected virtual object LoadSettings()
 {
     return(NotepadCloneSetting.Load(typeof(NotepadCloneSetting), strAppData));
 }