C # applets-menus with history

Source: Internet
Author: User

I wrote a program with the history menu function a few days ago. It was not very well written and too complicated. Yesterday I found a new method, so I wrote it again. The code for dynamically adding a menu is as follows:
[Csharp]
// Menu. ini is a configuration file to store history.
If (File. Exists ("Menu. ini "))
{
StreamReader sr = new StreamReader ("Menu. ini ");
Int I = this. File ToolStripMenuItem. DropDownItems. Count-2;
While (sr. Peek ()> 0)
{
ToolStripMenuItem tlomenu = new ToolStripMenuItem (sr. ReadLine ());
This. File ToolStripMenuItem. DropDownItems. Insert (I, tlomenu );
I ++;
}
Sr. Close ();
}

I also used Visio to draw a simple program process.


The following is the code for the help window:

[Csharp]
/Call API functions
[DllImport ("user32")]
Private static extern long FlashWindow (IntPtr handle, bool bInvert );
 
Private void btnClose_Click (object sender, EventArgs e)
{
This. Close ();
}
 
Private void timereffectick (object sender, EventArgs e)
{
FlashWindow (this. Handle, true );
}

Select the font window code:

[Csharp]
Public FrmFont (Frm frm)
{
InitializeComponent ();
MianFrm = frm;
}
 
Frm mianFrm = new Frm ();
// Define the intermediate variable.
Public Font newFont;
Public bool getBlod;
Public bool getItalic;
 

// Add the font and size to the program.
Private void FrmFont_Load (object sender, EventArgs e)
{
InstalledFontCollection iof = new InstalledFontCollection ();
Foreach (FontFamily font in iof. Families)
{
CboFont. Items. Add (font. Name );
}
For (int I = 1; I <100; I ++)
CboSize. Items. Add (I );
}
 
Public void UpdateFrmMain ()
{
If (cboFont. SelectedIndex> 0)
{
Try
{
NewFont = new Font (cboFont. SelectedItem. ToString (), newFont. Size );
}
Catch
{}
}
If (cboSize. SelectedIndex> 0)
{
NewFont = new Font (newFont. FontFamily, float. Parse (cboSize. SelectedItem. ToString ()));
}
MianFrm. rtbNotePad. Font = newFont;
}
// Font selection changes
Private void cboFont_SelectedIndexChanged (object sender, EventArgs e)
{
UpdateFrmMain ();
}
// Font size drop-down box change
Private void cboSize_SelectedIndexChanged (object sender, EventArgs e)
{
UpdateFrmMain ();
}
 
The program runs as follows:



The main form code is as follows:
[Csharp]
// Define variables
StreamWriter str = null;
String strTemp;
String path = System. IO. Directory. GetCurrentDirectory ();
 
Private void help ToolStripMenuItem_Click (object sender, EventArgs e)
{
// Call the help form
FrmHelp help = new FrmHelp ();
Help. ShowDialog ();
}

// Open the file
Private void open ToolStripMenuItem_Click (object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog ();
If (ofd. ShowDialog () = DialogResult. OK)
{
This. rtbNotePad. Text + = ofd. FileName;
This. rtbNotePad. LoadFile (ofd. FileName, RichTextBoxStreamType. PlainText );
String destination FileName = ofd. FileName. Substring (ofd. FileName. LastIndexOf ("\") + 1 );
This. Text = optional filename;
 
ToolStripMenuItem tlomenu = new ToolStripMenuItem (ofd. FileName );
Int I = this. File ToolStripMenuItem. DropDownItems. Count-2;
This. File ToolStripMenuItem. DropDownItems. Insert (I, tlomenu );
Tlomenu. Click + = new EventHandler (ToolStripMenuItem_Click );
}
}
 
Private void create ToolStripMenuItem_Click (object sender, EventArgs e)
{
SaveFileDialog ofd = new SaveFileDialog ();
If (ofd. ShowDialog () = DialogResult. OK)
{
Str = new StreamWriter (ofd. FileName, false );
}
}

Private void exit ToolStripMenuItem_Click (object sender, EventArgs e)
{
This. Close ();
}
 
Private void save ToolStripMenuItem_Click (object sender, EventArgs e)
{
If (str! = Null)
{
StrTemp = rtbNotePad. Text;
Str. Write (strTemp );
}
}
 
Private void Frm_FormClosing (object sender, FormClosingEventArgs e)
{
Try
{
Str. Close ();
}
Catch
{};
}
 
Private void font ToolStripMenuItem_Click (object sender, EventArgs e)
{
FrmFont frmfont = new FrmFont (this );
Font tempFont = rtbNotePad. Font;
Frmfont. newFont = rtbNotePad. Font;
Frmfont. ShowDialog ();
}
 
Private void Frm_Load (object sender, EventArgs e)
{
If (File. Exists ("Menu. ini "))
{
HaveMenu = true;
String temp;
StreamReader sr = new StreamReader ("Menu. ini", Encoding. Default, false );
Int I = this. File ToolStripMenuItem. DropDownItems. Count-2;
While (temp = sr. ReadLine ())! = Null)
{
ToolStripMenuItem tlomenu = new ToolStripMenuItem (temp );
This. File ToolStripMenuItem. DropDownItems. Insert (I, tlomenu );
Tlomenu. Click + = new EventHandler (ToolStripMenuItem_Click );
I ++;
}
Sr. Close ();
}
}
 
Private void ToolStripMenuItem_Click (object sender, EventArgs e)
{Www.2cto.com
// Click history
String temp = (ToolStripMenuItem) sender). Text;
This. rtbNotePad. LoadFile (temp, RichTextBoxStreamType. PlainText );
String parameter filename = temp. Substring (temp. LastIndexOf ("\") + 1 );
This. Text = optional filename;
 
String newpath = path + @ "\ Menu. ini ";
StreamWriter sr = new StreamWriter (newpath, true, Encoding. Default );
Sr. WriteLine (temp );
Sr. Close ();
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.