Advertisement
Guest User

scintilla example

a guest
Sep 30th, 2016
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.71 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using ScintillaNET;
  11. using AutocompleteMenuNS;
  12. using System.Runtime.InteropServices;
  13. namespace WindowsFormsApplication1
  14. {
  15.  
  16.     public partial class Form1 : Form
  17.     {
  18.         [DllImport("kernel32.dll", SetLastError = true)]
  19.         static extern bool AllocConsole();
  20.  
  21.         [DllImport("kernel32.dll", SetLastError = true)]
  22.         static extern bool FreeConsole();
  23.         string[] snippets = { "public", "class", "namespace", "maurice" };
  24.         public Form1()
  25.         {
  26.             AllocConsole();
  27.             InitializeComponent();
  28.             autocompleteMenu1.TargetControlWrapper = new ScintillaWrapper(scintilla);
  29.             autocompleteMenu1.ToolTipDuration = 1;
  30.             // = New ScintillaWrapper(scintilla1);
  31.             scintilla.Text = "";
  32.             // Configuring the default style with properties
  33.             // we have common to every lexer style saves time.
  34.             scintilla.StyleResetDefault();
  35.             scintilla.Styles[Style.Default].Font = "Consolas";
  36.             scintilla.Styles[Style.Default].Size = 10;
  37.             scintilla.Styles[Style.Default].BackColor = Color.Black;
  38.             scintilla.Styles[Style.Default].ForeColor = Color.White;
  39.             scintilla.CaretForeColor = Color.Yellow;
  40.             scintilla.StyleClearAll();
  41.  
  42.             // Configure the CPP (C#) lexer styles
  43.             scintilla.Styles[Style.Cpp.Default].ForeColor = Color.Silver;
  44.             scintilla.Styles[Style.Cpp.Comment].ForeColor = Color.FromArgb(0, 128, 0); // Green
  45.             scintilla.Styles[Style.Cpp.CommentLine].ForeColor = Color.FromArgb(0, 128, 0); // Green
  46.             scintilla.Styles[Style.Cpp.CommentLineDoc].ForeColor = Color.FromArgb(128, 128, 128); // Gray
  47.             scintilla.Styles[Style.Cpp.Number].ForeColor = Color.Olive;
  48.             scintilla.Styles[Style.Cpp.Word].ForeColor = Color.Red;
  49.             scintilla.Styles[Style.Cpp.Word2].ForeColor = Color.Blue;
  50.             scintilla.Styles[Style.Cpp.String].ForeColor = Color.FromArgb(163, 21, 21); // Red
  51.             scintilla.Styles[Style.Cpp.Character].ForeColor = Color.FromArgb(163, 21, 21); // Red
  52.             scintilla.Styles[Style.Cpp.Verbatim].ForeColor = Color.FromArgb(163, 21, 21); // Red
  53.             scintilla.Styles[Style.Cpp.StringEol].BackColor = Color.Pink;
  54.             scintilla.Styles[Style.Cpp.Operator].ForeColor = Color.Purple;
  55.             scintilla.Styles[Style.Cpp.Preprocessor].ForeColor = Color.Maroon;
  56.             scintilla.Lexer = Lexer.Cpp;
  57.  
  58.             // Set the keywords
  59.             scintilla.SetKeywords(0, "abstract as base break case catch checked continue default delegate do else event explicit extern false finally fixed for foreach goto if implicit in interface internal is lock namespace new null object operator out override params private protected public readonly ref return sealed sizeof stackalloc switch this throw true try typeof unchecked unsafe using virtual while");
  60.             scintilla.SetKeywords(1, "bool byte char class const decimal double enum float int long sbyte short static string struct uint ulong ushort void");
  61.             scintilla.KeyDown += scintilla_KeyDown;
  62.             BuildAutocompleteMenu();
  63.         }
  64.         public void scintilla_TextChanged(object sender, EventArgs e)
  65.         {
  66.            
  67.         }
  68.         private void scintilla_KeyDown(object sender, KeyEventArgs e)
  69.         {
  70.             //forcibly shows menu
  71.             if (e.KeyCode != Keys.Return && e.KeyCode != Keys.Back)
  72.                 autocompleteMenu1.Show(scintilla, false);
  73.             else
  74.             {
  75.                 Console.WriteLine("OH?");
  76.             }
  77.         }
  78.         private void scintilla_Click(object sender, EventArgs e)
  79.         {
  80.  
  81.         }
  82.         private void BuildAutocompleteMenu()
  83.         {
  84.             var items = new List<AutocompleteItem>();
  85.  
  86.             foreach (var item in snippets)
  87.                 items.Add(new SnippetAutocompleteItem(item) { ImageIndex = 1 });
  88.  
  89.             //set as autocomplete source
  90.             autocompleteMenu1.SetAutocompleteItems(items);
  91.         }
  92.     }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement