我正在尝试使用C#组件在ScintillaNET中实现一个自定义文本编辑器。到目前为止,我已经掌握了其中的大部分内容,但仍停留在某一点上。我想让用户能够阻止评论/取消评论选定的文本。我试了很多次,但在网上找不到任何例子。我似乎从控件的选择对象中得到的唯一东西是开始和结束位置,但这并没有多大帮助。
private void commentBlockToolStripMenuItem_Click(object sender, EventArgs e)
{
if (txtSQL.Selection.Text.Length > 0)
{
String start = txtSQL.Selection.Start.ToString();
String end = txtSQL.Selection.End.ToString();
MessageBox.Show(start + "::" + end);
}
}
你们中有人能够使用ScintillaNET控件成功地实现这一点吗?
编辑:经过一些不准备,我可以做它以某种方式,但在块被评论后,最后一行移出选择!
private void commentBlockToolStripMenuItem_Click(object sender, EventArgs e)
{
if (txtSQL.Selection.Text.Length > 0)
{
Range range = txtSQL.Selection.Range;
int f = range.StartingLine.Number;
int t = range.EndingLine.Number;
int endpos = txtSQL.Selection.End;
for (int i = f; i <= t; i++)
{
//txtSQL.GoTo.Line(i);
string tstr = txtSQL.Lines[i].Text.Replace(Environment.NewLine, "");
txtSQL.Lines[i].Text = "--" + tstr;
}
}
}
发布于 2013-09-04 13:27:32
经过一些实验,我找到了一种方法来完成这个任务。虽然我怀疑这是否是最优雅的解决方案!
private void commentBlockToolStripMenuItem_Click(object sender, EventArgs e)
{
if (txtSQL.Selection.Text.Length > 0)
{
Range range = txtSQL.Selection.Range;
int f = range.StartingLine.Number;
int t = range.EndingLine.Number;
for (int i = f; i <= t; i++)
{
txtSQL.InsertText(txtSQL.Lines[i].StartPosition,"--");
}
txtSQL.Selection.Start = txtSQL.Lines[f].StartPosition;
txtSQL.Selection.End = txtSQL.Lines[t].EndPosition;
}
}
发布于 2014-07-26 19:07:00
事实上,我找到了一个非常简单的解决方案。若要阻止注释do
scintilla1.Lexing.LineComment();
和阻止取消注释做
scintilla1.Lexing.LineUncomment();
https://stackoverflow.com/questions/18614006
复制相似问题