我正在尝试保存在scintilla中编辑的文件的指示器(书签),以便下次打开文件时重新加载它们。
这是我的代码片段:
List<int> bookmarks = new List<int>();
for (int i = 0; i < scintilla1.Lines.Count; i++)
{
if (!bookmarks.Contains(scintilla1.Markers.FindNextMarker(i).Number))
bookmarks.Add(scintilla1.Markers.FindNextMarker(i).Number);
}
for (int j=0;j<bookmarks.Count;j++)
MessageBox.Show(bookmarks[j].ToString());然而,指数似乎超出了它的界限,有什么帮助吗?
发布于 2013-03-19 02:13:32
你能试试这个吗:
HashMap<int> bookmarks = new HashMap<int>();
for (int i = 0; i < scintilla1.Lines.Count; i++)
{
bookmarks.Add(scintilla1.Markers.FindNextMarker(i).Number);
}
foreach (var bookmark in bookmarks)
{
MessageBox.Show(bookmark.ToString());
}另外,需要注意的是,FindNextMarker将返回带有标记的下一行(参见实现here)。所以我认为你的方法是错误的。它应该更像这样:
HashMap<int> bookmarks = new HashMap<int>();
int nextBookmark = 0;
while (nextBookmark != UInt32.MaxValue)
{
nextBookmark = scintilla1.Markers.FindNextMarker(nextBookmark).Line;
if (nextBookmark != UInt32.MaxValue)
{
bookmarks.Add(nextBookmark);
}
}
foreach (var bookmark in bookmarks)
{
MessageBox.Show(bookmark.ToString());
}更棒的是,您可以使用public List<Marker> GetMarkers(int line)获取所有标记
foreach (var bookmark in scintilla1.Markers.GetMarkers(0))
{
MessageBox.Show(bookmark.Line.ToString());
}要注意的是,每个文件最多有32个标记。请参阅markers documentation on the Scintilla site。
发布于 2013-03-19 03:21:25
我用下面的代码解决了这个问题,但是,我想将书签内容添加到文件的末尾,这样我就可以知道在打开新文件时在哪里加载书签。如何编辑scintilla1.Linesscintilla1.Lines.Count
List<int> bookmarks = new List<int>();
while(true)
{
try
{
Line next = scintilla1.Markers.FindNextMarker();
scintilla1.Caret.Position = next.StartPosition;
scintilla1.Caret.Goto(next.EndPosition);
scintilla1.Scrolling.ScrollToCaret();
scintilla1.Focus();
bookmarks.Add(next.Number);
}
catch(Exception ex)
{
break;
}
}
string Marks="";
for(int i =0;i<bookmarks.Count;i++)
Marks += bookmarks[i]+ ",";https://stackoverflow.com/questions/15483734
复制相似问题