当前位置: 首页>>代码示例>>C#>>正文


C# MenuItem.Popup事件代码示例

本文整理汇总了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;
   }
}
开发者ID:.NET开发者,项目名称:System.Windows.Forms,代码行数:16,代码来源:MenuItem.Popup

示例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);
     }
}
开发者ID:C#程序员,项目名称:System.Windows.Forms,代码行数:96,代码来源:MenuItem.Popup


注:本文中的System.Windows.Forms.MenuItem.Popup事件示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。