OSDN Git Service

Initial contents of nt2chview
[nt2chview/stable.git] / NT2chView45 / NTFontSelectDialog.xaml.cs
1 using System;\r
2 using System.Collections.Generic;\r
3 using System.Text;\r
4 using System.Windows;\r
5 using System.Windows.Controls;\r
6 using System.Windows.Data;\r
7 using System.Windows.Documents;\r
8 using System.Windows.Input;\r
9 using System.Windows.Media;\r
10 using System.Windows.Media.Imaging;\r
11 using System.Windows.Shapes;\r
12 \r
13 namespace NT2chView\r
14 {\r
15     /// <summary>\r
16     /// NTFontSelectDialog.xaml の相互作用ロジック\r
17     /// </summary>\r
18     public partial class NTFontSelectDialog : Window\r
19     {\r
20         public String FontName\r
21         {\r
22             get;\r
23             set;\r
24         }\r
25 \r
26         public NTFontSelectDialog()\r
27         {\r
28             InitializeComponent();\r
29         }\r
30 \r
31          private void NTFontSelectDialog_Loaded(object sender, RoutedEventArgs e)\r
32         {\r
33             edtFontName.Text = FontName;\r
34 \r
35 \r
36             int idx = 0;\r
37             int selIdx = -1;\r
38             foreach (FontFamily fontFamily in Fonts.SystemFontFamilies)\r
39             {\r
40                 string source = fontFamily.Source;\r
41                 lstFonts.Items.Add(source);\r
42                 if (source.Equals(FontName))\r
43                     selIdx = idx;\r
44                 idx++;\r
45             }\r
46 \r
47             if (selIdx >= 0)\r
48             {\r
49                 \r
50                 lstFonts.SelectedIndex = selIdx;\r
51                 lstFonts.ScrollIntoView(lstFonts.SelectedItem);\r
52             }\r
53 \r
54         }\r
55        \r
56         private void lstFonts_selectionChanged(object sender, SelectionChangedEventArgs e)\r
57         {\r
58             ListBox lb = sender as ListBox;\r
59             if (lb != null)\r
60             {\r
61                 ListBoxItem lbi =lb.SelectedItem as ListBoxItem;\r
62                 if (lbi != null)\r
63                 {\r
64                     edtFontName.Text = lbi.Content.ToString();\r
65                 }\r
66                 else\r
67                 {\r
68                     string fontName = lb.SelectedItem as string;\r
69                     if (fontName != null)\r
70                     {\r
71                         edtFontName.Text = fontName;\r
72                     }\r
73 \r
74                 }\r
75 \r
76             }\r
77 \r
78         }\r
79 \r
80         private void btnOK_Click(object sender, RoutedEventArgs e)\r
81         {\r
82             this.DialogResult = true;\r
83             FontName = edtFontName.Text;\r
84             this.Close();\r
85         }\r
86 \r
87         private void btnCancel_Click(object sender, RoutedEventArgs e)\r
88         {\r
89             this.DialogResult = false;\r
90             FontName = string.Empty;\r
91             this.Close();\r
92 \r
93         }\r
94 \r
95     }\r
96 }\r