前田稔(Maeda Minoru)の超初心者のプログラム入門
string m_Kword; // 検索キー private void KeySearch(object sender, EventArgs e) { MyDialog Mydlg = new MyDialog(); Mydlg.txtBox.Text = m_Kword; DialogResult dr = Mydlg.ShowDialog(); if (dr == DialogResult.OK) { int cnt = 0; m_Kword = Mydlg.str; for (int pos = 0; ; ) { pos = richTextBox1.Find(m_Kword, pos, RichTextBoxFinds.None); if (pos < 0) break; richTextBox1.SelectionColor = Color.DarkMagenta; cnt++; pos++; } MessageBox.Show("検索件数: " + cnt); richTextBox1.Select(0, 0); } } |
private void Replace(object sender, EventArgs e) { RepDialog Repdlg = new RepDialog(); Repdlg.k_Box.Text = m_Kword; DialogResult dr = Repdlg.ShowDialog(); if (dr == DialogResult.OK) { richTextBox1.Text = richTextBox1.Text.Replace(Repdlg.k_str, Repdlg.r_str); m_Kword = Repdlg.r_str; m_flag = true; } } |
//★ Dialog Class class MyDialog : Form { public TextBox txtBox; public string str; //取得KeyWord public MyDialog() { Text = "Dialog Text Input"; MaximizeBox = false; MinimizeBox = false; ControlBox = false; ShowInTaskbar = false; FormBorderStyle = FormBorderStyle.FixedDialog; Width = 250; Height = 130; Button btnOK = new Button(); btnOK.Text = "OK"; btnOK.Location = new Point(30, ClientSize.Height - btnOK.Height - 5); btnOK.Parent = this; btnOK.TabIndex = 1; btnOK.Click += new EventHandler(btnOK_Click); btnOK.DialogResult = DialogResult.OK; Button btnCancel = new Button(); btnCancel.Text = "Cancel"; btnCancel.Location = new Point(ClientSize.Width - btnCancel.Width - 30, ClientSize.Height - btnCancel.Height - 5); btnCancel.Parent = this; btnCancel.TabIndex = 2; btnCancel.DialogResult = DialogResult.Cancel; txtBox = new TextBox(); txtBox.Parent = this; txtBox.Location = new Point(10, 10); txtBox.Width = ClientSize.Width - 20; txtBox.TabIndex = 0; } void btnOK_Click(object sender, EventArgs e) { str = txtBox.Text; } } |
class RepDialog : Form { public TextBox k_Box; public TextBox r_Box; public string k_str; //KeyWord public string r_str; //Replace public RepDialog() { Text = "Dialog Text Input"; MaximizeBox = false; MinimizeBox = false; ControlBox = false; ShowInTaskbar = false; FormBorderStyle = FormBorderStyle.FixedDialog; Width = 250; Height = 130; Button btnOK = new Button(); btnOK.Text = "OK"; btnOK.Location = new Point(30, ClientSize.Height - btnOK.Height - 5); btnOK.Parent = this; btnOK.TabIndex = 2; btnOK.Click += new EventHandler(btnOK_Click); btnOK.DialogResult = DialogResult.OK; Button btnCancel = new Button(); btnCancel.Text = "Cancel"; btnCancel.Location = new Point(ClientSize.Width - btnCancel.Width - 30, ClientSize.Height - btnCancel.Height - 5); btnCancel.Parent = this; btnCancel.TabIndex = 3; btnCancel.DialogResult = DialogResult.Cancel; k_Box = new TextBox(); k_Box.Parent = this; k_Box.Location = new Point(10, 10); k_Box.Width = ClientSize.Width - 20; k_Box.TabIndex = 0; r_Box = new TextBox(); r_Box.Parent = this; r_Box.Location = new Point(10, 36); r_Box.Width = ClientSize.Width - 20; r_Box.TabIndex = 1; } void btnOK_Click(object sender, EventArgs e) { k_str = k_Box.Text; r_str = r_Box.Text; } } |
// タブの幅を設定する SendMessage() を定義 [System.Runtime.InteropServices.DllImport("User32.dll")] static extern IntPtr SendMessage( IntPtr hWnd, int msg, int wParam, int [] lParam); |
private void Form_Load(object sender, EventArgs e) { // 4 TAB に設定 const int EM_SETTABSTOPS = 0x00CB; SendMessage(richTextBox1.Handle, EM_SETTABSTOPS, 1, new int[] {16}); } |
txtedit.exe<br> txtedit.exe file_name<br> txtedit.exe file_name text_code<br> |
[STAThread] static void Main(string[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); switch (args.Length) { case 0: Application.Run(new Form1()); break; case 1: // ファイル名を指定 Application.Run(new Form1(args[0])); break; case 2: // ファイル名とコード Application.Run(new Form1(args[0], args[1])); break; } } |
// Constructor public Form1() { FormInit(string.Empty, string.Empty); } public Form1(string tpath) { FormInit(tpath, string.Empty); } public Form1(string tpath, string tcode) { FormInit(tpath, tcode); } private void FormInit(string tpath, string tcode) { InitializeComponent(); if (tpath == string.Empty) return; LoadFile(tpath, tcode); } |
[Next Chapter ↓] Single File Editor
[Previous Chapter ↑] XML に保存