下載
軟體開發
帳戶
下載
軟體開發
登入
我忘記帳戶名和密碼了
新增帳戶
語言
手冊
語言
手冊
×
登入
登入名稱
密碼
×
我忘記帳戶名和密碼了
繁體中文翻譯狀態
類別:
軟體
人
PersonalForge
Magazine
Wiki
搜尋
OSDN
>
軟體搜索
>
Text Editors
>
Azuki
>
討論區
>
公開討議
>
Caretを、指定した行/列インデックスへ移動する方法を教えて下さい。
Azuki
描述
專案概要
開發人員儀表板
專案的網頁
Developers
Image Gallery
List of RSS Feeds
活動
使用統計
歷史
檔案下載
發布列表
Stats
原始碼
儲存庫列表
Subversion
查看儲存庫
待辦事項
待辦事項列表
里程碑列表
類型列表
元件列表
List of frequently used tickets/RSS
新增待辦事項
文檔
FrontPage
Title index
Recent changes
溝通
討論區列表
公開討議 (499)
討論區:
公開討議
(Thread #44492)
Return to Thread list
RSS
Caretを、指定した行/列インデックスへ移動する方法を教えて下さい。 (2021-08-07 16:31 by
kazmax
#87863)
回覆
①Enterで改行後、改行前の行の先頭に全角空白があれば数を数えて、同じ数の全角空白を新らしい行の先頭に自動挿入する。
②挿入後、Caretを、挿入された全角空白の最後の位置に移動する。
という機能を作っています。
①は出来るのですが、②が出来ません。
どのようにすればよいでしょうか。
実装は下記のとおりです。
private void AzukiEditor_TextChanged(object sender, EventArgs e)
{
if (LastInputedKey == Keys.Enter)
{
int newLineIndex = AzukiEditor.GetLineIndexFromCharIndex(AzukiEditor.CaretIndex);
if (newLineIndex != 0)
{
string prevLine = AzukiEditor.Document.GetLineContent(newLineIndex - 1);
if (prevLine.StartsWith(" "))
{
string headSpaces = "";
for (int i = 0; i < prevLine.Length; i++)
{
if (prevLine[i] == ' ')
{
headSpaces += " ";
}
else
{
break;
}
}
AzukiEditor.TextChanged -= AzukiEditor_TextChanged;
AzukiEditor.Document.Text = AzukiEditor.Document.Text.Insert(AzukiEditor.CaretIndex, headSpaces);
AzukiEditor.TextChanged += AzukiEditor_TextChanged;
headSpaces = "";
}
}
}
}
回覆 #87863
×
主題
內容
Reply To Message #87863 > ①Enterで改行後、改行前の行の先頭に全角空白があれば数を数えて、同じ数の全角空白を新らしい行の先頭に自動挿入する。 > ②挿入後、Caretを、挿入された全角空白の最後の位置に移動する。 > という機能を作っています。 > > ①は出来るのですが、②が出来ません。 > どのようにすればよいでしょうか。 > > 実装は下記のとおりです。 > > private void AzukiEditor_TextChanged(object sender, EventArgs e) > { > if (LastInputedKey == Keys.Enter) > { > int newLineIndex = AzukiEditor.GetLineIndexFromCharIndex(AzukiEditor.CaretIndex); > if (newLineIndex != 0) > { > string prevLine = AzukiEditor.Document.GetLineContent(newLineIndex - 1); > if (prevLine.StartsWith(" ")) > { > string headSpaces = ""; > for (int i = 0; i < prevLine.Length; i++) > { > if (prevLine[i] == ' ') > { > headSpaces += " "; > } > else > { > break; > } > } > AzukiEditor.TextChanged -= AzukiEditor_TextChanged; > AzukiEditor.Document.Text = AzukiEditor.Document.Text.Insert(AzukiEditor.CaretIndex, headSpaces); > AzukiEditor.TextChanged += AzukiEditor_TextChanged; > headSpaces = ""; > } > } > } > }
You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.)
登入
Nickname
預覽
Post
取消
Re: Caretを、指定した行/列インデックスへ移動する方法を教えて下さい。 (2021-08-07 22:45 by
kazmax
#87864)
回覆
自己解決しました。
private void AzukiEditor_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.Enter)
{
int prevLineIndex = AzukiEditor.GetLineIndexFromCharIndex(AzukiEditor.Document.CaretIndex);
string prevLineText = AzukiEditor.Document.GetLineContent(prevLineIndex);
string headSpaces = "";
if (prevLineText.StartsWith(" "))
{
for (int i = 0; i < prevLineText.Length; i++)
{
if (prevLineText[i] == ' ')
{
headSpaces += " ";
}
else
{
break;
}
}
e.Handled = true;
AzukiEditor.Document.Replace(Environment.NewLine + headSpaces, AzukiEditor.Document.CaretIndex, AzukiEditor.CaretIndex);
}
}
}
回覆:
#87863
回覆 #87864
×
主題
內容
Reply To Message #87864 > 自己解決しました。 > > private void AzukiEditor_KeyPress(object sender, KeyPressEventArgs e) > { > if (e.KeyChar == (char)Keys.Enter) > { > int prevLineIndex = AzukiEditor.GetLineIndexFromCharIndex(AzukiEditor.Document.CaretIndex); > string prevLineText = AzukiEditor.Document.GetLineContent(prevLineIndex); > > string headSpaces = ""; > if (prevLineText.StartsWith(" ")) > { > for (int i = 0; i < prevLineText.Length; i++) > { > if (prevLineText[i] == ' ') > { > headSpaces += " "; > } > else > { > break; > } > } > e.Handled = true; > AzukiEditor.Document.Replace(Environment.NewLine + headSpaces, AzukiEditor.Document.CaretIndex, AzukiEditor.CaretIndex); > } > } > }
You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.)
登入
Nickname
預覽
Post
取消