SyntaxHighlighter part1

using  System;
using  System.Drawing;
using  System.Collections;
using  System.Collections.Specialized;
using  System.ComponentModel;
using  System.Windows.Forms;

namespace  UrielGuy.SyntaxHighlightingTextBox
{
    
/// <summary>
    
/// Summary description for AutoCompleteForm.
    
/// </summary>

    public class AutoCompleteForm : System.Windows.Forms.Form
    
{
        
private StringCollection mItems = new StringCollection();
        
private System.Windows.Forms.ListView lstCompleteItems;
        
private System.Windows.Forms.ColumnHeader columnHeader1;

        
public StringCollection Items 
        
{
            
get 
            
{
                
return mItems;
            }

        }


        
internal int ItemHeight 
        
{
            
get  
            
{
                
return 18;
            }

        }


        
/// <summary>
        
/// Required designer variable.
        
/// </summary>

        private System.ComponentModel.Container components = null;

        
public AutoCompleteForm()
        
{
            
//
            
// Required for Windows Form Designer support
            
//
            InitializeComponent();
        }


        
public string SelectedItem 
        
{
            
get
            
{
                
if (lstCompleteItems.SelectedItems.Count == 0return null;
                
return (string)lstCompleteItems.SelectedItems[0].Text;
            }

        }


        
/// <summary>
        
/// Clean up any resources being used.
        
/// </summary>

        protected override void Dispose( bool disposing )
        
{
            
if( disposing )
            
{
                
if(components != null)
                
{
                    components.Dispose();
                }

            }

            
base.Dispose( disposing );
        }


        

        
Windows Form Designer generated code

        
private void lstCompleteItems_SelectedIndexChanged(object sender, System.EventArgs e)
        
{
        }


        
internal int SelectedIndex 
        
{
            
get 
            
{
                
if (lstCompleteItems.SelectedIndices.Count == 0)
                
{
                    
return -1;
                }

                
return lstCompleteItems.SelectedIndices[0];
            }

            
set
            
{
                lstCompleteItems.Items[value].Selected 
= true;
            }

        }

        
private void AutoCompleteForm_Resize(object sender, System.EventArgs e)
        
{
            
//System.Diagnostics.Debug.WriteLine(string.Format("Size x:{0} y:{1}  {2}", Size.Width , Size.Height, Environment.StackTrace));
        }


        
internal void UpdateView()
        
{
            lstCompleteItems.Items.Clear();
            
foreach (string item in mItems)
            
{
                lstCompleteItems.Items.Add(item);
            }

        }


        
private void AutoCompleteForm_VisibleChanged(object sender, System.EventArgs e)
        
{
            ArrayList items 
= new ArrayList(mItems);
            items.Sort(
new CaseInsensitiveComparer());
            mItems 
= new StringCollection();
            mItems.AddRange((
string[])items.ToArray(typeof(string)));
            columnHeader1.Width 
= lstCompleteItems.Width - 20;

        }


        
private void lstCompleteItems_Resize(object sender, System.EventArgs e)
        
{
            
if (this.Size != lstCompleteItems.Size)
            
{
                
            }

        }

    }

}

 

 

using  System;
using  System.Drawing;

namespace  UrielGuy.SyntaxHighlightingTextBox
{
    
public class HighlightDescriptor
    
{
        
public HighlightDescriptor(string token, Color color, Font font, DescriptorType descriptorType, DescriptorRecognition dr, bool useForAutoComplete)
        
{
            
if (descriptorType == UrielGuy.SyntaxHighlightingTextBox.DescriptorType.ToCloseToken)
            
{
                
throw new ArgumentException("You may not choose ToCloseToken DescriptorType without specifing an end token.");
            }

            Color 
= color;
            Font 
= font;
            Token 
= token;
            DescriptorType 
= descriptorType;
            DescriptorRecognition 
= dr;
            CloseToken 
= null;
            UseForAutoComplete 
= useForAutoComplete;
        }

        
public HighlightDescriptor(string token, string closeToken, Color color, Font font, DescriptorType descriptorType, DescriptorRecognition dr, bool useForAutoComplete)
        
{
            Color 
= color;
            Font 
= font;
            Token 
= token;
            DescriptorType 
= descriptorType;
            CloseToken 
= closeToken;
            DescriptorRecognition 
= dr;
            UseForAutoComplete 
= useForAutoComplete;
        }

        
public readonly Color Color;
        
public readonly Font Font;
        
public readonly string Token;
        
public readonly string CloseToken;
        
public readonly DescriptorType DescriptorType;
        
public readonly DescriptorRecognition DescriptorRecognition; 
        
public readonly bool UseForAutoComplete;
    }


    
    
public enum DescriptorType
    
{
        
/// <summary>
        
/// Causes the highlighting of a single word
        
/// </summary>

        Word,
        
/// <summary>
        
/// Causes the entire line from this point on the be highlighted, regardless of other tokens
        
/// </summary>

        ToEOL,
        
/// <summary>
        
/// Highlights all text until the end token;
        
/// </summary>

        ToCloseToken
    }


    
public enum DescriptorRecognition
    
{
        
/// <summary>
        
/// Only if the whole token is equal to the word
        
/// </summary>

        WholeWord,
        
/// <summary>
        
/// If the word starts with the token
        
/// </summary>

        StartsWith,
        
/// <summary>
        
/// If the word contains the Token
        
/// </summary>

        Contains
    }


}

 

 

using  System;
using  System.Collections;

namespace  UrielGuy.SyntaxHighlightingTextBox
{
    
/// <summary>
    
/// Summary description for SeperaratorCollection.
    
/// </summary>

    public class HighLightDescriptorCollection
    
{
        
private ArrayList mInnerList = new ArrayList();
        
internal HighLightDescriptorCollection()
        
{
        }


        
public void AddRange(ICollection c)
        
{
            mInnerList.AddRange(c);
        }



        
IList Members

        
ICollection Members

        
IEnumerable Members
    }

}

 

 

using  System;
using  System.Collections;

namespace  UrielGuy.SyntaxHighlightingTextBox
{
    
/// <summary>
    
/// Summary description for SeperaratorCollection.
    
/// </summary>

    public class SeperaratorCollection
    
{
        
private ArrayList mInnerList = new ArrayList();
        
internal SeperaratorCollection()
        
{
        }


        
public void AddRange(ICollection c)
        
{
            mInnerList.AddRange(c);
        }


        
internal char[] GetAsCharArray()
        
{
            
return (char[])mInnerList.ToArray(typeof(char));
        }

        
IList Members

        
ICollection Members

        
IEnumerable Members
    }

}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值