teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

3

追記

2021/08/12 11:07

投稿

YAmaGNZ
YAmaGNZ

スコア10663

answer CHANGED
@@ -108,4 +108,8 @@
108
108
  }
109
109
 
110
110
  ```
111
- といったコードと上記のコマンドにてコンパイル、動作の確認ができました。
111
+ といったコードと上記のコマンドにてコンパイル、動作の確認ができました。
112
+ ./binには
113
+ Microsoft.WindowsAPICodePack.dll
114
+ Microsoft.WindowsAPICodePack.Shell.dll
115
+ のDLLを置いてあります。

2

追記

2021/08/12 11:07

投稿

YAmaGNZ
YAmaGNZ

スコア10663

answer CHANGED
@@ -31,4 +31,81 @@
31
31
  ```
32
32
  C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc /nologo -reference:./bin/Microsoft.WindowsAPICodePack.dll -reference:./bin/Microsoft.WindowsAPICodePack.Shell.dll /target:winexe /out:.\bin\Main.exe .\src\main.cs .\src\sub\MainForm.cs
33
33
  ```
34
- といった感じでコンパイルすれば使用できるはずです。
34
+ といった感じでコンパイルすれば使用できるはずです。
35
+
36
+ ./src/main.cs
37
+ ```C#
38
+ using System;
39
+ using System.Windows.Forms;
40
+
41
+ using Sample.Forms;
42
+
43
+ namespace Sample{
44
+ class EntryPoint{
45
+ [STAThread]
46
+ static void Main( string[] args ){
47
+ // メインウィンドウの生成と起動
48
+ Application.Run( new MainForm( ) );
49
+ }
50
+ }
51
+ }
52
+ ```
53
+
54
+ ./src/sub/MainForm.cs
55
+ ```C#
56
+ using System;
57
+ using System.Drawing;
58
+ using System.Windows.Forms;
59
+ using Microsoft.WindowsAPICodePack;
60
+ using Microsoft.WindowsAPICodePack.Dialogs;
61
+ using Microsoft.WindowsAPICodePack.Dialogs.Controls;
62
+
63
+ namespace Sample.Forms
64
+ {
65
+ public partial class MainForm : Form
66
+ {
67
+
68
+ Label label1,label2;
69
+
70
+ public MainForm()
71
+ {
72
+ Button b = new Button();
73
+ b.Location = new Point(10,10);
74
+ b.Size = new Size(100,50);
75
+ b.Text = "button";
76
+ b.Click += button_Click;
77
+ this.Controls.Add(b);
78
+
79
+ label1 = new Label();
80
+ label1.Location = new Point(10,150);
81
+ label1.AutoSize = true;
82
+ label2 = new Label();
83
+ label2.Location = new Point(10,170);
84
+ label2.AutoSize = true;
85
+ this.Controls.Add(label1);
86
+ this.Controls.Add(label2);
87
+
88
+ }
89
+
90
+ private void button_Click(object sender, EventArgs e)
91
+ {
92
+ CommonSaveFileDialog dialog = new CommonSaveFileDialog();
93
+ CommonFileDialogComboBox comboBox = new CommonFileDialogComboBox();
94
+ comboBox.Items.Add(new CommonFileDialogComboBoxItem("SHIFT-JIS"));
95
+ comboBox.Items.Add(new CommonFileDialogComboBoxItem("UTF-8"));
96
+ comboBox.Items.Add(new CommonFileDialogComboBoxItem("UNICODE"));
97
+ comboBox.Items.Add(new CommonFileDialogComboBoxItem("EUC"));
98
+ comboBox.SelectedIndex = 0;
99
+ dialog.Controls.Add(comboBox);
100
+
101
+ if (dialog.ShowDialog() == CommonFileDialogResult.Ok)
102
+ {
103
+ label1.Text = dialog.FileName;
104
+ label2.Text = comboBox.Items[comboBox.SelectedIndex].Text;
105
+ }
106
+ }
107
+ }
108
+ }
109
+
110
+ ```
111
+ といったコードと上記のコマンドにてコンパイル、動作の確認ができました。

1

追記

2021/08/12 11:06

投稿

YAmaGNZ
YAmaGNZ

スコア10663

answer CHANGED
@@ -18,4 +18,17 @@
18
18
  }
19
19
  }
20
20
  ```
21
- こんな感じで
21
+ こんな感じで
22
+
23
+ ---
24
+ 追記
25
+ CommonSaveFileDialogを利用するにはWindowsAPICodePack-Shellをインストールしなくてはなりません。
26
+ これをインストールするとWindowsAPICodePack-Coreもインストールされます。
27
+ 使用するDLLは
28
+ Microsoft.WindowsAPICodePack.dll
29
+ Microsoft.WindowsAPICodePack.Shell.dll
30
+ の2つのDLLとなります。
31
+ ```
32
+ C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc /nologo -reference:./bin/Microsoft.WindowsAPICodePack.dll -reference:./bin/Microsoft.WindowsAPICodePack.Shell.dll /target:winexe /out:.\bin\Main.exe .\src\main.cs .\src\sub\MainForm.cs
33
+ ```
34
+ といった感じでコンパイルすれば使用できるはずです。