private void ultraToolbarsManager1_ToolClick(object sender,
Infragistics.Win.UltraWinToolbars.ToolClickEventArgs e)
{
// Determine which tool was clicked
switch (e.Tool.Key)
{
case "New":
{
// Change the image and Tag on the New tool to indicate the last
// item chosen was an RTF Document
this.ultraToolbarsManager1.Tools["New"].
SharedProps.AppearancesSmall.Appearance.Image =
e.Tool.SharedProps.AppearancesSmall.Appearance.Image;
this.ultraToolbarsManager1.Tools["New"].SharedProps.Tag = "New RTF Document";
// Create a new RTF Doc
NewRTFDocument();
break;
}
case "MRUList":
{
// User clicked an item on the MRU List tool.
Infragistics.Win.UltraWinToolbars.ListTool aListTool;
Infragistics.Win.UltraWinToolbars.ListToolItem
aListToolItem;
// Cast e.Tool (which is a ToolBase) into a List too, so we can access
// tool-specific properties
aListTool =
(Infragistics.Win.UltraWinToolbars.ListTool)e.Tool;
// Get the ListToolItem which was clicked
aListToolItem = aListTool.SelectedItem;
// Open the document based on the ListToolItem
// The Key of the ListToolItem is the filename of the
// document to load.
OpenDocument(aListToolItem.Key);
break;
}
}
}
private void NewRTFDocument()
{
int LastDocumentNumber=0;
frmRTFDocument frm = new frmRTFDocument();
LastDocumentNumber += 1;
frm.MdiParent = this;
frm.Text = "New RTF Document " + LastDocumentNumber;
frm.Show();
}
private void OpenDocument(string FileName)
{
Open(FileName, false);
}
private void Open(string FileName, bool PromptToReOpen)
{
Form ExistingChildForm;
ExistingChildForm = GetExistingChildForm(FileName);
if (!(ExistingChildForm == null))
{
DialogResult dlResult;
if (PromptToReOpen)
{
dlResult = MessageBox.Show("This file is already open. Do you want to reload it?",
"Confirm?", MessageBoxButtons.YesNo, MessageBoxIcon.Question );
if (dlResult == System.Windows.Forms.DialogResult.Yes)
{
ExistingChildForm.Close();
}
else
{
return;
}
}
else
{
ExistingChildForm.Focus();
return;
}
}
System.IO.FileInfo File;
File = new System.IO.FileInfo(FileName);
switch (File.Extension.ToLower())
{
case ".rtf":
frmRTFDocument frmRTF = new frmRTFDocument();
frmRTF.MdiParent = this;
frmRTF.Text = FileName;
frmRTF.richTextBox1.LoadFile(FileName);
frmRTF.HasFileName = true;
frmRTF.Show();
break;
}
}
// Tries to get an existing form based on the filename of the document
// This is mostly used to prevent opening the same document twice.
private Form GetExistingChildForm(string FileName)
{
foreach (Form ChildForm in this.MdiChildren)
{
if (ChildForm.Text == FileName)
{
return ChildForm;
}
}
return null;
}