質問編集履歴

1

コードの追加

2018/11/25 04:16

投稿

syo46no
syo46no

スコア13

test CHANGED
File without changes
test CHANGED
@@ -8,35 +8,119 @@
8
8
 
9
9
 
10
10
 
11
-
12
-
13
- private void button1_Click(object sender, EventArgs e)
11
+ public Form1()
14
12
 
15
13
  {
16
14
 
17
- //テキスト読み込み
15
+ InitializeComponent();
18
16
 
17
+
18
+
19
+ //縦書きrichTextboxの作成
20
+
21
+ RichTextEx myText= new RichTextEx();
22
+
19
- if (sender == button1)
23
+ myText.VerticalText = true;
24
+
25
+ myText.Location = new Point(25,25);
26
+
27
+ myText.Size = new Size(355,722);
28
+
29
+ this.Controls.Add(myText);
30
+
31
+ }
32
+
33
+
34
+
35
+ //richTextboxを縦書きにする操作
36
+
37
+ public class RichTextEx : RichTextBox
38
+
39
+ {
40
+
41
+ [DllImport("kernel32.dll")]
42
+
43
+ private static extern IntPtr LoadLibrary(string path);
44
+
45
+
46
+
47
+ [DllImport("User32.dll")]
48
+
49
+ private static extern int SendMessage(IntPtr hWnd, uint Msg, int wParam, int IParam);
50
+
51
+
52
+
53
+ private const uint EM_SETOPTIONS = 0x44d;
54
+
55
+ private const uint EM_GETOPTIONS = 0x44e;
56
+
57
+ private const int ECOOP_SET = 0x1;
58
+
59
+ private const int ECOOP_OR = 0x2;
60
+
61
+ private const int ECOOP_AND = 0x3;
62
+
63
+ private const int ECOOP_XOR = 0x4;
64
+
65
+ private const int ES_VERTICAL = 0x400000;
66
+
67
+
68
+
69
+ protected override CreateParams CreateParams
20
70
 
21
71
  {
22
72
 
23
- OpenFileDialog ofd = new OpenFileDialog();
24
-
25
- ofd.Filter = "テキストファイル|*.txt";
26
-
27
- if (ofd.ShowDialog() == DialogResult.OK)
73
+ get
28
74
 
29
75
  {
30
76
 
77
+ LoadLibrary("msftedit.dll");
78
+
79
+ CreateParams createParams = base.CreateParams;
80
+
31
- StreamReader sr = new StreamReader(ofd.FileName, Encoding.GetEncoding("Shift_JIS"));
81
+ createParams.ClassName = "RichEdit50W";
82
+
83
+ return createParams;
84
+
85
+ }
86
+
87
+ }
32
88
 
33
89
 
34
90
 
35
- //RichTextEx に文書を表示させたい
91
+ public virtual bool VerticalText
36
92
 
37
- myText.Text = sr.ReadToEnd();
93
+ {
38
94
 
39
-
95
+ get
96
+
97
+ {
98
+
99
+ int ret = SendMessage(this.Handle, EM_GETOPTIONS, 0, 0);
100
+
101
+ if ((ret & ES_VERTICAL) != 0) return true; else return false;
102
+
103
+ }
104
+
105
+ set
106
+
107
+ {
108
+
109
+ if (value == true)
110
+
111
+ {
112
+
113
+ SendMessage(this.Handle, EM_SETOPTIONS, ECOOP_OR, ES_VERTICAL);
114
+
115
+ }
116
+
117
+ else
118
+
119
+ {
120
+
121
+ SendMessage(this.Handle, EM_SETOPTIONS, ECOOP_AND, ~ES_VERTICAL);
122
+
123
+ }
40
124
 
41
125
  }
42
126
 
@@ -44,7 +128,19 @@
44
128
 
45
129
  }
46
130
 
131
+
132
+
133
+
134
+
47
135
  ```
136
+
137
+
138
+
139
+ ![左の赤が実行時に出てくる作成したmyText、右があらかじめ作成したrichTextBox1](593a4a4a87fc6e1668dc0e35735fb272.jpeg)
140
+
141
+ この左のmyTextに文書を表示させたいです。
142
+
143
+
48
144
 
49
145
  このようにopenfiledialogでパソコン内にある文章を縦書き表示させたRichTextExのmyTextにパソコン内にある文章を表示させたいのですが、読み取られません。
50
146