This project is read-only.

For your help . . .C# Basic features

Topics: Developer Forum, User Forum
Jul 16, 2011 at 5:13 PM

Hi!

Today I used ScintillaNET for the first time - since there is only a rudimentary documentation I posted you a simple solution for

1. Create and manage your own keyword list dynamically.

2. Using the autocomplete function.

 

I hope, that will help you!

Best regard,

Michael.

 

private const string keywords = "_Title _Class _Love _Car _Parent _Child _Subclass _Data _Text";
        List<string> keywordList;

        public Form1()
        {
            InitializeComponent();
            scintilla1.Margins[0].Width = 20;
            scintilla1.ConfigurationManager.Language = "cs";
            scintilla1.Lexing.Keywords[0] = keywords;
  scintilla1.AutoComplete.DropRestOfWord = true; scintilla1.AutoComplete.AutoHide = false; keywordList = new List<string>(keywords.Split(' ')); // manage your list dynamically (e.g. from a database), don't use the AutoComplete.List keywordList.Sort(); } private void scintilla1_CharAdded(object sender, CharAddedEventArgs e) { if (e.Ch == ' ') return; int pos = scintilla1.NativeInterface.GetCurrentPos(); string word = scintilla1.GetWordFromPosition(pos); if (word == string.Empty) return; List<string> list = keywordList.FindAll(item => item.StartsWith(word)); if (list.Count > 0) scintilla1.AutoComplete.Show(list); }

 

 

Jul 29, 2011 at 4:59 PM

Hello!

you know how can I put different color(bold) for custom words?

 

thanks!

Jul 29, 2011 at 7:31 PM

You are somewhat dependent on the lexer. Most lexers have a style that correspond to a keyword list. The cpp lexer (used for cs language) sets the style of keywords to 5. To bold that style simply

scintilla.Styles[5].Bold = true;

Aug 19, 2011 at 7:06 AM

Hi!

Some modifications:

1. Autocomplete List

2. Two keyword lists (different colored)

3. Code Snippets

Best,

My Morgentau

 

 

 List<string> keywordList1 = new List<string>();
 List<string> keywordList2 = new List<string>();
 List<string> keywordListAll = new List<string>();

        public List<string> Keywords1 { set { this.keywordList1 = value; UpdateKeywords(); } get { return this.keywordList1; } }
        public List<string> Keywords2 { set { this.keywordList2 = value; UpdateKeywords(); } get { return this.keywordList2; } }
        private void UpdateKeywords() {
            this.keywordListAll = new List<string>(this.keywordList1);
            this.keywordListAll.AddRange(this.keywordList2); 
            keywordListAll.Sort();
            scintilla1.Lexing.Keywords[0] = String.Join(" ", keywordList1.ToArray());
            scintilla1.Lexing.Keywords[1] = String.Join(" ", keywordList2.ToArray());
        }


public void Init()
{
scintilla1.Margins[0].Width = 20;
scintilla1.ConfigurationManager.Language = "cs";
//In order to find out the indivudal type name, e.g. Word2; debug program and look into scintilla1.Lexing.StyleNameMap
scintilla1.Styles[scintilla1.Lexing.StyleNameMap["Word2"]].ForeColor = Color.Red;
scintilla1.Styles[scintilla1.Lexing.StyleNameMap["Number"]].ForeColor = Color.Black;
scintilla1.AutoComplete.SingleLineAccept = false;
scintilla1.AutoComplete.IsCaseSensitive = true;
scintilla1.AutoComplete.DropRestOfWord = true;
scintilla1.AutoComplete.AutoHide = false;
scintilla1.AutoComplete.AutomaticLengthEntered = true;
scintilla1.Caret.HighlightCurrentLine = true;
}

public void GotoLine(int line)
{
scintilla1.NativeInterface.GotoLine(Math.Max(0, line - 1)); //zero-based
}

private void scintilla1_CharAdded(object sender, ScintillaNet.CharAddedEventArgs e)
{
            if (e.Ch == ' ')
                return;
            int pos = scintilla1.NativeInterface.GetCurrentPos();
            string word = scintilla1.GetWordFromPosition(pos);
            if (word == string.Empty)
                return;
            List<string> list = keywordListAll.FindAll(item => item.StartsWith(word));
            if (list.Count > 0)
                scintilla1.AutoComplete.Show(list);
            else
                scintilla1.AutoComplete.Cancel();
        
} private void scintilla1_KeyDown(object sender, KeyEventArgs e) { if (e.Control) { if (e.KeyCode == Keys.D1) scintilla1.Snippets.ShowSnippetList(); } }