📄 mainform.cs
字号:
this.m_subMatchMenuItem = new System.Windows.Forms.MenuItem();
this.m_reverseLookupMenuItem = new System.Windows.Forms.MenuItem();
this.m_pronounciationMenuItem = new System.Windows.Forms.MenuItem();
this.menuItem5 = new System.Windows.Forms.MenuItem();
this.df_menuShowBothToggle = new System.Windows.Forms.MenuItem();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.m_saveOptionsMenuItem = new System.Windows.Forms.MenuItem();
this.m_enableMenuItem = new System.Windows.Forms.MenuItem();
this.menuItem4 = new System.Windows.Forms.MenuItem();
this.m_aboutMenuItem = new System.Windows.Forms.MenuItem();
this.m_richTextBox = new System.Windows.Forms.RichTextBox();
this.SuspendLayout();
//
// mainMenu1
//
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.m_dictsMenuItem,
this.menuItem2,
this.m_enableMenuItem,
this.menuItem4});
//
// m_dictsMenuItem
//
this.m_dictsMenuItem.Index = 0;
this.m_dictsMenuItem.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem8,
this.m_manageDictionariesMenuItem,
this.m_quitMenuItem});
this.m_dictsMenuItem.Text = "字典";
this.m_dictsMenuItem.Click += new System.EventHandler(this.m_dictsMenuItem_Click);
//
// menuItem8
//
this.menuItem8.Index = 0;
this.menuItem8.Text = "-";
//
// m_manageDictionariesMenuItem
//
this.m_manageDictionariesMenuItem.Index = 1;
this.m_manageDictionariesMenuItem.Text = "字典管理";
this.m_manageDictionariesMenuItem.Click += new System.EventHandler(this.m_manageDictionariesMenuItem_Click);
//
// m_quitMenuItem
//
this.m_quitMenuItem.Index = 2;
this.m_quitMenuItem.Shortcut = System.Windows.Forms.Shortcut.CtrlQ;
this.m_quitMenuItem.Text = "退出";
this.m_quitMenuItem.Click += new System.EventHandler(this.m_quitMenuItem_Click);
//
// menuItem2
//
this.menuItem2.Index = 1;
this.menuItem2.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.m_alwaysOnTopMenuItem,
this.m_popupOnLookupMenuItem,
this.m_fontMenuButton,
this.menuItem6,
this.m_exactMatchMenuItem,
this.m_looseMatchMenuItem,
this.m_subphraseMatchMenuItem,
this.m_subMatchMenuItem,
this.m_reverseLookupMenuItem,
this.m_pronounciationMenuItem,
this.menuItem5,
this.df_menuShowBothToggle,
this.menuItem1,
this.m_saveOptionsMenuItem});
this.menuItem2.Text = "选项";
//
// m_alwaysOnTopMenuItem
//
this.m_alwaysOnTopMenuItem.Index = 0;
this.m_alwaysOnTopMenuItem.Shortcut = System.Windows.Forms.Shortcut.CtrlA;
this.m_alwaysOnTopMenuItem.ShowShortcut = false;
this.m_alwaysOnTopMenuItem.Text = "总在最上";
this.m_alwaysOnTopMenuItem.Click += new System.EventHandler(this.m_alwaysOnTopMenuItem_Click);
//
// m_popupOnLookupMenuItem
//
this.m_popupOnLookupMenuItem.Index = 1;
this.m_popupOnLookupMenuItem.Shortcut = System.Windows.Forms.Shortcut.CtrlU;
this.m_popupOnLookupMenuItem.ShowShortcut = false;
this.m_popupOnLookupMenuItem.Text = "自动弹出";
this.m_popupOnLookupMenuItem.Click += new System.EventHandler(this.m_popupOnLookupMenuItem_Click);
//
// m_fontMenuButton
//
this.m_fontMenuButton.Index = 2;
this.m_fontMenuButton.Shortcut = System.Windows.Forms.Shortcut.CtrlF;
this.m_fontMenuButton.ShowShortcut = false;
this.m_fontMenuButton.Text = "字体";
this.m_fontMenuButton.Click += new System.EventHandler(this.m_fontMenuButton_Click);
//
// menuItem6
//
this.menuItem6.Index = 3;
this.menuItem6.Text = "-";
//
// m_exactMatchMenuItem
//
this.m_exactMatchMenuItem.Index = 4;
this.m_exactMatchMenuItem.Text = "精确匹配";
this.m_exactMatchMenuItem.Click += new System.EventHandler(this.m_exactMatchMenuItem_Click);
//
// m_looseMatchMenuItem
//
this.m_looseMatchMenuItem.Index = 5;
this.m_looseMatchMenuItem.Text = "模糊匹配";
this.m_looseMatchMenuItem.Click += new System.EventHandler(this.m_looseMatchMenuItem_Click);
//
// m_subphraseMatchMenuItem
//
this.m_subphraseMatchMenuItem.Index = 6;
this.m_subphraseMatchMenuItem.Text = "匹配子段落";
this.m_subphraseMatchMenuItem.Click += new System.EventHandler(this.menuItem7_Click);
//
// m_subMatchMenuItem
//
this.m_subMatchMenuItem.Index = 7;
this.m_subMatchMenuItem.Text = "匹配子字符";
this.m_subMatchMenuItem.Click += new System.EventHandler(this.m_subMatchMenuItem_Click);
//
// m_reverseLookupMenuItem
//
this.m_reverseLookupMenuItem.Index = 8;
this.m_reverseLookupMenuItem.Text = "反向查询";
this.m_reverseLookupMenuItem.Click += new System.EventHandler(this.m_reverseLookupMenuItem_Click);
//
// m_pronounciationMenuItem
//
this.m_pronounciationMenuItem.Index = 9;
this.m_pronounciationMenuItem.Text = "发音";
this.m_pronounciationMenuItem.Click += new System.EventHandler(this.m_pronounciationMenuItem_Click);
//
// menuItem5
//
this.menuItem5.Index = 10;
this.menuItem5.Text = "-";
//
// df_menuShowBothToggle
//
this.df_menuShowBothToggle.Index = 11;
this.df_menuShowBothToggle.Text = "显示特殊字符";
this.df_menuShowBothToggle.Click += new System.EventHandler(this.df_menuShowBothToggle_Click);
//
// menuItem1
//
this.menuItem1.Index = 12;
this.menuItem1.Text = "-";
//
// m_saveOptionsMenuItem
//
this.m_saveOptionsMenuItem.Index = 13;
this.m_saveOptionsMenuItem.Text = "保存配置";
this.m_saveOptionsMenuItem.Click += new System.EventHandler(this.m_saveOptionsMenuItem_Click);
//
// m_enableMenuItem
//
this.m_enableMenuItem.Index = 2;
this.m_enableMenuItem.Text = "禁用";
this.m_enableMenuItem.Click += new System.EventHandler(this.m_enableMenuItem_Click);
//
// menuItem4
//
this.menuItem4.Index = 3;
this.menuItem4.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.m_aboutMenuItem});
this.menuItem4.Text = "帮助";
//
// m_aboutMenuItem
//
this.m_aboutMenuItem.Index = 0;
this.m_aboutMenuItem.Text = "关于";
this.m_aboutMenuItem.Click += new System.EventHandler(this.m_aboutMenuItem_Click);
//
// m_richTextBox
//
this.m_richTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.m_richTextBox.Font = new System.Drawing.Font("Microsoft Sans Serif", 10.2F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.m_richTextBox.Location = new System.Drawing.Point(0, 0);
this.m_richTextBox.Name = "m_richTextBox";
this.m_richTextBox.ReadOnly = true;
this.m_richTextBox.Size = new System.Drawing.Size(395, 123);
this.m_richTextBox.TabIndex = 1;
this.m_richTextBox.Text = "";
this.m_richTextBox.TextChanged += new System.EventHandler(this.m_richTextBox_TextChanged);
//
// MainForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(393, 121);
this.Controls.Add(this.m_richTextBox);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Menu = this.mainMenu1;
this.Name = "MainForm";
this.Text = "翻译小助手";
this.TopMost = true;
this.Load += new System.EventHandler(this.MainForm_Load);
this.ResumeLayout(false);
} #endregion public MainForm() { InitializeComponent(); m_dictionary = new Dictionary(); m_formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); LoadDictionaries(); LoadOptions(); m_pollingThread = new Thread(new ThreadStart(PollClipboard)); m_pollingThread.Start(); } /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.Run(new MainForm()); } // ==================== EVENT HANDLERS ================== private void DictionaryMenuItem_Click(object sender, System.EventArgs e) { if( m_enabled == false ) return;// string oldtext = m_richTextBox.Text; this.m_richTextBox.Text = "loading new dictionary..."; this.Refresh(); MenuItem mi = sender as MenuItem; Debug.Assert( mi != null ); DictionaryDefinition dictDef = null; int i = 0; for( i=0; i<m_dictDefs.Count; i++ ) if( m_dictsMenuItem.MenuItems[ i ] == sender ) break; Debug.Assert( i != m_dictDefs.Count ); dictDef = m_dictDefs[i] as DictionaryDefinition; Debug.Assert( dictDef != null ); this.SetDictionary( dictDef ); m_richTextBox.Text = "";// m_richTextBox.Text = oldtext; this.Lookup( this.GetClipText() ); } private void m_alwaysOnTopMenuItem_Click(object sender, System.EventArgs e) { m_alwaysOnTopMenuItem.Checked = ! m_alwaysOnTopMenuItem.Checked; this.TopMost = m_alwaysOnTopMenuItem.Checked; Trace.WriteLine("topmost = " + this.TopMost); } private void m_quitMenuItem_Click(object sender, System.EventArgs e) { this.Close(); } private void m_aboutMenuItem_Click(object sender, System.EventArgs e) { AboutForm about = new AboutForm(); about.ShowDialog(); } private void m_fontMenuButton_Click(object sender, System.EventArgs e) { FontDialog d = new FontDialog(); d.Font = m_richTextBox.Font; if( d.ShowDialog() != DialogResult.Cancel ) { m_richTextBox.Font = d.Font; } } private void m_exactMatchMenuItem_Click(object sender, System.EventArgs e) { this.SetMatchMode( Dictionary.MatchMode.Exact ); this.Lookup( this.GetClipText() ); } private void m_looseMatchMenuItem_Click(object sender, System.EventArgs e) { this.SetMatchMode( Dictionary.MatchMode.Loose ); this.Lookup( this.GetClipText() ); } private void m_subMatchMenuItem_Click(object sender, System.EventArgs e) { this.SetMatchMode(Dictionary.MatchMode.Subchars ); this.Lookup( this.GetClipText() ); } private void menuItem7_Click(object sender, System.EventArgs e) { this.SetMatchMode( Dictionary.MatchMode.Subphrases ); this.Lookup( this.GetClipText() ); } private void m_reverseLookupMenuItem_Click(object sender, System.EventArgs e) { this.SetMatchMode( Dictionary.MatchMode.ReverseLookup ); this.Lookup( this.GetClipText() ); }
private void m_pronounciationMenuItem_Click(object sender, System.EventArgs e)
{
this.SetMatchMode( Dictionary.MatchMode.Pronounciation ); this.Lookup( this.GetClipText() );
} private void m_popupOnLookupMenuItem_Click(object sender, System.EventArgs e) { m_popupOnLookupMenuItem.Checked = ! m_popupOnLookupMenuItem.Checked; } private void m_saveOptionsMenuItem_Click(object sender, System.EventArgs e) { this.SaveOptions(); MessageBox.Show("Preferences saved!", "Saved", MessageBoxButtons.OK); }
private void m_manageDictionariesMenuItem_Click(object sender, System.EventArgs e)
{
ManageDictionariesForm f = new ManageDictionariesForm(m_dictDefs);
f.TopMost = this.TopMost;
if( f.ShowDialog() == DialogResult.OK )
{
m_dictDefs = f.DictionaryDefinitions;
// save dictionary definitions to file...
FileStream fs = null;
try { fs = new FileStream("dicts.ini", FileMode.Create); m_formatter.Serialize(fs, m_dictDefs); } catch(System.Runtime.Serialization.SerializationException xcp) { Trace.WriteLine("Error saving dictionary definition file!\n" + xcp.ToString(), "DLTool"); } finally { if( fs != null ) fs.Close(); }
// reload the dictionaries and repopulate the menus
this.LoadDictionaries();
int i=0;
for( i=0; i<m_dictDefs.Count; i++ )
{
if( m_currentDictDef.Equals( m_dictDefs[i] ) )
{
this.m_dictsMenuItem.MenuItems[i].Checked = true;
break;
}
}
// if we can't find our dictionary any more, then flush it
// out of memory.
if( i == m_dictDefs.Count )
{
m_richTextBox.Text = "";
m_currentDictDef = new DictionaryDefinition();
m_dictionary = new Dictionary();
}
}
}
private void m_enableMenuItem_Click(object sender, System.EventArgs e)
{
if( m_enableMenuItem.Text.Equals("禁用") )
{
this.m_richTextBox.Enabled = false;
this.m_richTextBox.Text = "Disabled. Click \"Enable\" to resume automatic lookup";
this.m_enabled = false;
m_enableMenuItem.Text = "启用";
}
else
{
this.m_richTextBox.Enabled = true;
this.m_richTextBox.Text = "";
this.m_enabled = true;
m_enableMenuItem.Text = "禁用";
this.Lookup( this.GetClipText() );
// for some reason, without this, the scroll bars stop working
// on a re-enable
this.m_richTextBox.ScrollBars =
System.Windows.Forms.RichTextBoxScrollBars.None;
this.m_richTextBox.ScrollBars =
System.Windows.Forms.RichTextBoxScrollBars.Both;
}
}
//This is the code that should be used when toggling on/off the display of both
//traditional and simplified characters. Otherwise only the characters for which
//the original search was performed will be displayed.
//...Such is the utility of Unicode... -DF 02.23.05
private void df_menuShowBothToggle_Click(object sender, System.EventArgs e)
{
df_menuShowBothToggle.Checked = ! df_menuShowBothToggle.Checked;
m_dictionary.SetBothChars(df_menuShowBothToggle.Checked);
this.Lookup( this.GetClipText() );
//this.RefreshText();
}
private void m_dictsMenuItem_Click(object sender, System.EventArgs e) {
}
private void m_richTextBox_TextChanged(object sender, System.EventArgs e) {
}
private void MainForm_Load(object sender, System.EventArgs e) {
}
}}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -