前田稔(Maeda Minoru)の超初心者のプログラム入門
![]()
![]()
public class FileClass
{ public string path; //ファイルパス
public string file; //ファイル名
public string code; //TEXTコード
public string str; //編集 TEXT
public bool flag; //更新フラグ
public string lstr; //現在行の文字列
public int cursor; //現在のカーソル位置
public int line; //現在の行番号
public int st, nx; //現在行と次の行の先頭Index
public int lt; //次の行の有効文字
static StreamReader reader;
static StreamWriter writer;
static string sepa = "\n\\\t ,.;:<>(){}[]'\"+-*/=。、";
public static RichTextBox textbox;
|
// Constructor
public FileClass(string tpath, string tcode, int cur)
{
path = tpath;
code = tcode;
cursor = cur;
str = string.Empty;
flag = false;
SetFile();
}
|
// Word を選択状態に設定 pos:Word選択位置
static public int WordSelect(int pos, Color cor)
{
・・・
}
// RichTextBox の表示開始行を設定
static public void SetLine(int cur)
{ int pos, wk;
pos = cur;
if (pos<0) pos = 0;
wk = textbox.GetLineFromCharIndex(pos);
wk = textbox.GetFirstCharIndexFromLine(wk);
textbox.Select(wk,0);
textbox.Focus();
textbox.ScrollToCaret();
}
|
public void Next_srh(string word)
{
int wp;
if (word == string.Empty) return;
wp = textbox.SelectionStart + word.Length;
wp = textbox.Find(word, wp, -1, RichTextBoxFinds.None);
if (wp < 0)
{
MessageBox.Show("終端に達しました");
return;
}
SetCurPos(wp);
textbox.Select(wp, word.Length);
textbox.SelectionColor = Color.DarkMagenta;
textbox.Select(wp, 0); //選択状態の解除
}
public void Back_srh(string word)
{
int wp;
if (word == string.Empty) return;
wp = textbox.SelectionStart;
wp = textbox.Find(word, 0, wp, RichTextBoxFinds.Reverse);
if (wp < 0)
{
MessageBox.Show("終端に達しました");
return;
}
SetCurPos(wp);
textbox.Select(wp, word.Length);
textbox.SelectionColor = Color.DarkMagenta;
textbox.Select(wp, 0); //選択状態の解除
}
// cur の3行前から表示
public void SetCurPos(int cur)
{ int pos, wk;
if (cur>=0) cursor = cur;
pos = cursor;
wk = textbox.GetLineFromCharIndex(pos) - 3;
if (wk < 0) wk = 0;
wk = textbox.GetFirstCharIndexFromLine(wk);
textbox.Select(wk,0);
textbox.Focus();
textbox.ScrollToCaret();
}
// 現在行を取得
public void LineEdit()
{
cursor = textbox.SelectionStart;
st = textbox.GetFirstCharIndexOfCurrentLine();
line = textbox.GetLineFromCharIndex(st);
if (line < (textbox.Lines.Length-1))
{
nx = textbox.GetFirstCharIndexFromLine(line + 1);
lstr = textbox.Text.Substring(st, nx - st);
}
else
{
nx = st;
lstr = "*LineEdit EndLine";
}
for (lt=0; lt<lstr.Length; lt++)
{
if (lstr[lt] == ' ') continue;
if (lstr[lt] == '\t') continue;
break;
}
}
|
public static RichTextBox textbox;
|
FileClass.textbox = richTextBox1;
|
// Text File に保存
public void WriteFile()
{
TextWrite(path, code);
}
public void WriteFile(string tpath, string tcode)
{
TextWrite(tpath, tcode);
path = tpath;
code = tcode;
SetFile();
}
// RichTextBox のデータをファイル(tpath)に出力
private void TextWrite(string tpath, string tcode)
{
if (tcode==string.Empty)
writer = new StreamWriter(tpath, false);
else
writer = new StreamWriter(tpath, false, Encoding.GetEncoding(tcode));
writer.Write(textbox.Text);
writer.Close();
}
・・・
|
// Constructor
public FileClass(string tpath, string tcode, int cur)
{
・・・
}
|
private void LoadFile(string tpath, string tcode, int cur)
{
・・・
m_fclass = new FileClass(tpath, tcode, cur);
|
![]()
private void ClipPaste()
{
IDataObject data = Clipboard.GetDataObject();
if (data != null && data.GetDataPresent(DataFormats.Text) == true)
{
int pos = richTextBox1.SelectionStart;
richTextBox1.Select(pos, 0);
richTextBox1.SelectedText = Clipboard.GetText();
}
m_fclass.flag = true;
}
|
![]()
[Next Chapter ↓] Multi File Editor
[Previous Chapter ↑] TabPage Chenge