以上のを参考にし、RichTextBoxから継承してRichTextExを作成しVerticalTextプロパティを実装しました。
C#
1 2 public Form1() 3 { 4 InitializeComponent(); 5 6 //縦書きrichTextboxの作成 7 RichTextEx myText= new RichTextEx(); 8 myText.VerticalText = true; 9 myText.Location = new Point(25,25); 10 myText.Size = new Size(355,722); 11 this.Controls.Add(myText); 12 } 13 14 //richTextboxを縦書きにする操作 15 public class RichTextEx : RichTextBox 16 { 17 [DllImport("kernel32.dll")] 18 private static extern IntPtr LoadLibrary(string path); 19 20 [DllImport("User32.dll")] 21 private static extern int SendMessage(IntPtr hWnd, uint Msg, int wParam, int IParam); 22 23 private const uint EM_SETOPTIONS = 0x44d; 24 private const uint EM_GETOPTIONS = 0x44e; 25 private const int ECOOP_SET = 0x1; 26 private const int ECOOP_OR = 0x2; 27 private const int ECOOP_AND = 0x3; 28 private const int ECOOP_XOR = 0x4; 29 private const int ES_VERTICAL = 0x400000; 30 31 protected override CreateParams CreateParams 32 { 33 get 34 { 35 LoadLibrary("msftedit.dll"); 36 CreateParams createParams = base.CreateParams; 37 createParams.ClassName = "RichEdit50W"; 38 return createParams; 39 } 40 } 41 42 public virtual bool VerticalText 43 { 44 get 45 { 46 int ret = SendMessage(this.Handle, EM_GETOPTIONS, 0, 0); 47 if ((ret & ES_VERTICAL) != 0) return true; else return false; 48 } 49 set 50 { 51 if (value == true) 52 { 53 SendMessage(this.Handle, EM_SETOPTIONS, ECOOP_OR, ES_VERTICAL); 54 } 55 else 56 { 57 SendMessage(this.Handle, EM_SETOPTIONS, ECOOP_AND, ~ES_VERTICAL); 58 } 59 } 60 } 61 } 62 63
このようにopenfiledialogでパソコン内にある文章を縦書き表示させたRichTextExのmyTextにパソコン内にある文章を表示させたいのですが、読み取られません。
どうすればよろしいのでしょうか。
また、あらかじめrichTextBox1を追加していたのですがこちらを縦書きにすることは可能でしょうか。
お願いいたします。
読み取られないとはどうなるのでしょうか。エラーが出るならエラーメッセージを提示してください
CS0103 現在のコンテキストに 'myText' という名前は存在しません というエラーが出ます。このプログラムを実行したときのみ縦書きのmyTextが現れ、それ以外では出てこないので何もできないです。
今のフォームにどうやってmyTextを配置したんでしょうか。そこんところのソースコードも提示してください
少しコードの追加と現在の画面にについて追加させていただきました。拙い文章ですが、ご教授お願いいたします。
myTextはプログラム上には存在するのですが、デザイン配置には現れず、実行時のみの出現となります。