本文整理汇总了C#中System.Windows.Forms.MenuItem.Popup事件的典型用法代码示例。如果您正苦于以下问题:C# MenuItem.Popup事件的具体用法?C# MenuItem.Popup怎么用?C# MenuItem.Popup使用的例子?那么, 这里精选的事件代码示例或许可以为您提供帮助。您也可以进一步了解该事件所在类System.Windows.Forms.MenuItem
的用法示例。
在下文中一共展示了MenuItem.Popup事件的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PopupMyMenu
private void PopupMyMenu(object sender, System.EventArgs e)
{
if (textBox1.Enabled == false || textBox1.Focused == false ||
textBox1.SelectedText.Length == 0)
{
menuCut.Enabled = false;
menuCopy.Enabled = false;
menuDelete.Enabled = false;
}
else
{
menuCut.Enabled = true;
menuCopy.Enabled = true;
menuDelete.Enabled = true;
}
}
示例2: Main
//引入命名空间
using System;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
class RichTextPaste: Form
{
string strPastedText = "";
MenuItem miPastePlain, miPasteRTF, miPasteHTML, miPasteCSV;
public static void Main()
{
Application.Run(new RichTextPaste());
}
public RichTextPaste()
{
ResizeRedraw = true;
Menu = new MainMenu();
MenuItem mi = new MenuItem("&Edit");
mi.Popup += new EventHandler(MenuEditOnPopup);
Menu.MenuItems.Add(mi);
miPastePlain = new MenuItem("Paste &Plain Text");
miPastePlain.Click += new EventHandler(MenuEditPastePlainOnClick);
Menu.MenuItems[0].MenuItems.Add(miPastePlain);
miPasteRTF = new MenuItem("Paste &Rich Text Format");
miPasteRTF.Click += new EventHandler(MenuEditPasteRTFOnClick);
Menu.MenuItems[0].MenuItems.Add(miPasteRTF);
miPasteHTML = new MenuItem("Paste &HTML");
miPasteHTML.Click += new EventHandler(MenuEditPasteHTMLOnClick);
Menu.MenuItems[0].MenuItems.Add(miPasteHTML);
miPasteCSV = new MenuItem("Paste &Comma-Separated Values");
miPasteCSV.Click += new EventHandler(MenuEditPasteCSVOnClick);
Menu.MenuItems[0].MenuItems.Add(miPasteCSV);
}
void MenuEditOnPopup(object obj, EventArgs ea)
{
miPastePlain.Enabled = Clipboard.GetDataObject().GetDataPresent(typeof(string));
miPasteRTF.Enabled = Clipboard.GetDataObject().GetDataPresent(DataFormats.Rtf);
miPasteHTML.Enabled = Clipboard.GetDataObject().GetDataPresent(DataFormats.Html);
miPasteCSV.Enabled = Clipboard.GetDataObject().GetDataPresent(DataFormats.CommaSeparatedValue);
}
void MenuEditPastePlainOnClick(object obj, EventArgs ea)
{
IDataObject data = Clipboard.GetDataObject();
if (data.GetDataPresent(typeof(string)))
{
strPastedText = (string) data.GetData(typeof(string));
Invalidate();
}
}
void MenuEditPasteRTFOnClick(object obj, EventArgs ea)
{
IDataObject data = Clipboard.GetDataObject();
if (data.GetDataPresent(DataFormats.Rtf))
{
strPastedText = (string) data.GetData(DataFormats.Rtf);
Invalidate();
}
}
void MenuEditPasteHTMLOnClick(object obj, EventArgs ea)
{
IDataObject data = Clipboard.GetDataObject();
if (data.GetDataPresent(DataFormats.Html))
{
strPastedText = (string) data.GetData(DataFormats.Html);
Invalidate();
}
}
void MenuEditPasteCSVOnClick(object obj, EventArgs ea)
{
IDataObject data = Clipboard.GetDataObject();
if (data.GetDataPresent(DataFormats.CommaSeparatedValue))
{
MemoryStream memstr = (MemoryStream) data.GetData("Csv");
StreamReader streamreader = new StreamReader(memstr);
strPastedText = streamreader.ReadToEnd();
Invalidate();
}
}
protected override void OnPaint(PaintEventArgs pea)
{
pea.Graphics.DrawString(strPastedText, Font, new SolidBrush(ForeColor),
ClientRectangle);
}
}