本文整理汇总了C#中System.Windows.Forms.ContextMenu.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# ContextMenu.Dispose方法的具体用法?C# ContextMenu.Dispose怎么用?C# ContextMenu.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.ContextMenu
的用法示例。
在下文中一共展示了ContextMenu.Dispose方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Application_Startup
private void Application_Startup(object sender, StartupEventArgs e)
{
//build the context menu
_trayContextMenu = new System.Windows.Forms.ContextMenu();
_trayContextMenu.MenuItems.Add(new System.Windows.Forms.MenuItem("E&xit", ContextMenuExit));
//setup the system tray icon
_trayIcon = new NotifyIcon();
_trayIcon.ContextMenu = _trayContextMenu;
_trayIcon.Icon = images.IDS04;
_trayIcon.Click += new EventHandler(TrayIconClick);
_trayIcon.Visible = true;
//host the service
ServiceHost host1 = new ServiceHost(typeof(CrossDomainService));
host1.Open();
ServiceHost host2 = new ServiceHost(typeof(BiometricsService));
host2.Open();
//display the main window
_mainWindow = new Main();
_mainWindow.Closing += new CancelEventHandler(MainWindowClosing);
_mainWindow.ShowDialog();
//cleanup
_trayContextMenu.Dispose();
_trayIcon.Dispose();
}
示例2: PopUpSystemContextMenu
public static int PopUpSystemContextMenu(IDLWrapper idlw, Point pntShow, ref IContextMenu2 pIContextMenu2, IntPtr hwndParent, bool fCanRemove) {
IShellFolder ppv = null;
int num5;
try {
IntPtr ptr;
if((!idlw.Available || (PInvoke.SHBindToParent(idlw.PIDL, ExplorerGUIDs.IID_IShellFolder, out ppv, out ptr) != 0)) || (ppv == null)) {
return -1;
}
IntPtr[] apidl = new IntPtr[] { ptr };
uint rgfReserved = 0;
Guid riid = ExplorerGUIDs.IID_IContextMenu;
object obj2 = null;
ppv.GetUIObjectOf(IntPtr.Zero, (uint)apidl.Length, apidl, ref riid, ref rgfReserved, out obj2);
if(pIContextMenu2 != null) {
Marshal.ReleaseComObject(pIContextMenu2);
pIContextMenu2 = null;
}
pIContextMenu2 = obj2 as IContextMenu2;
if(pIContextMenu2 == null) {
return -2;
}
ContextMenu menu = new ContextMenu();
uint uFlags = 0;
if((Control.ModifierKeys & Keys.Shift) == Keys.Shift) {
uFlags |= 0x100;
}
pIContextMenu2.QueryContextMenu(menu.Handle, 0, 1, 0xffff, uFlags);
if(fCanRemove) {
PInvoke.AppendMenu(menu.Handle, 0x800, IntPtr.Zero, null);
PInvoke.AppendMenu(menu.Handle, 0, new IntPtr(0xffff), QTUtility.ResMain[0x19]);
}
if((idlw.HasPath && (idlw.Path.Length > 3)) && (idlw.IsFileSystemFolder || idlw.IsFileSystemFile)) {
if(!fCanRemove) {
PInvoke.AppendMenu(menu.Handle, 0x800, IntPtr.Zero, null);
}
PInvoke.AppendMenu(menu.Handle, 0, new IntPtr(0xfffe), QTUtility.ResMain[0x1a]);
}
uint num3 = PInvoke.TrackPopupMenu(menu.Handle, 0x100, pntShow.X, pntShow.Y, 0, hwndParent, IntPtr.Zero);
int num4 = -3;
switch(num3) {
case 0:
num4 = 0xfffd;
break;
case 0xffff:
menu.Dispose();
return 0xffff;
case 0xfffe:
if(idlw.HasPath) {
try {
string directoryName = Path.GetDirectoryName(idlw.Path);
if(Directory.Exists(directoryName)) {
IntPtr currentHandle = QTUtility.instanceManager.CurrentHandle;
if(PInvoke.IsWindow(currentHandle)) {
QTUtility2.SendCOPYDATASTRUCT(currentHandle, (IntPtr)0x10, directoryName, IntPtr.Zero);
num4 = 0xfffe;
}
else {
Process.Start(directoryName);
num4 = -4;
}
}
}
catch {
SystemSounds.Asterisk.Play();
}
}
break;
default: {
CMINVOKECOMMANDINFO structure = new CMINVOKECOMMANDINFO();
structure.cbSize = Marshal.SizeOf(structure);
structure.fMask = 0;
structure.hwnd = hwndParent;
structure.lpVerb = (IntPtr)((num3 - 1) & 0xffff);
structure.lpParameters = IntPtr.Zero;
structure.lpDirectory = IntPtr.Zero;
structure.nShow = 1;
structure.dwHotKey = 0;
structure.hIcon = IntPtr.Zero;
num4 = pIContextMenu2.InvokeCommand(ref structure);
break;
}
}
menu.Dispose();
num5 = num4;
}
catch {
num5 = -1;
}
finally {
if(ppv != null) {
Marshal.ReleaseComObject(ppv);
ppv = null;
}
}
return num5;
}
示例3: TrackGroupContextMenu
public static string TrackGroupContextMenu(string groupName, Point pnt, IntPtr pDropDownHandle) {
string str;
string name = string.Empty;
if(!QTUtility.GroupPathsDic.TryGetValue(groupName, out str)) {
return name;
}
string[] strArray = str.Split(QTUtility.SEPARATOR_CHAR);
ContextMenu menu = new ContextMenu();
if(!QTUtility.IsXP) {
foreach(string str2 in strArray) {
string text;
if(str2.StartsWith(@"\\")) {
text = str2;
}
else {
text = ShellMethods.GetDisplayName(str2);
}
MenuItem item = new MenuItem(text);
item.Name = str2;
menu.MenuItems.Add(item);
}
}
else {
foreach(string path in strArray) {
string displayName;
if(path.StartsWith(@"\\")) {
displayName = path;
}
else {
displayName = ShellMethods.GetDisplayName(path);
}
MenuItemEx ex = new MenuItemEx(displayName);
ex.Name = path;
ex.Image = QTUtility.ImageListGlobal.Images[QTUtility.GetImageKey(path, null)];
menu.MenuItems.Add(ex);
}
}
List<IntPtr> list = new List<IntPtr>();
if(!QTUtility.IsXP) {
for(int k = 0; k < strArray.Length; k++) {
string imageKey = QTUtility.GetImageKey(strArray[k], null);
IntPtr hbitmap = ((Bitmap)QTUtility.ImageListGlobal.Images[imageKey]).GetHbitmap(Color.Black);
if(hbitmap != IntPtr.Zero) {
list.Add(hbitmap);
PInvoke.SetMenuItemBitmaps(menu.Handle, k, 0x400, hbitmap, IntPtr.Zero);
}
}
}
uint maxValue = uint.MaxValue;
if(menu.MenuItems.Count > 0) {
maxValue = PInvoke.TrackPopupMenu(menu.Handle, 0x180, pnt.X, pnt.Y, 0, pDropDownHandle, IntPtr.Zero);
if(maxValue != 0) {
for(int m = 0; m < menu.MenuItems.Count; m++) {
if(maxValue == PInvoke.GetMenuItemID(menu.Handle, m)) {
name = menu.MenuItems[m].Name;
break;
}
}
}
}
menu.Dispose();
if(!QTUtility.IsXP) {
foreach(IntPtr ptr2 in list) {
PInvoke.DeleteObject(ptr2);
}
}
if(maxValue != 0) {
return name;
}
return null;
}
示例4: AddNewDeal
public void AddNewDeal(MenuItem _mi_)
{
//_mi_.MenuItems.Clear();
// Сначала просканировать линии на наличие незаконченных и неопределенных сдач
ArrayOfInt NotDefinedLines = new ArrayOfInt();
for (int i = 0; i < VALUES.Count; i++)
{
for(int j = 0 ; j < VALUES[i].Count ; j++)
{
if(VALUES[i, j] != null && !NotNecessaryValues.Contains(j) && VALUES[i, j].GetType().IsSubclassOf(typeof(BaseChangedData)) && (VALUES[i, j] as BaseChangedData).IsDefined() == false)
{
// пропускать пустые значения из-за "нет контракта"
bool skip_if_no_contract = false;
for (int k = 0; k < ContractColumns.Count; k++)
{
if (VALUES[i, ContractColumns[k]] != null && (VALUES[i, ContractColumns[k]] as Contract).NoContract)
if (NotNecessaryValues_NOCONTRACT[k].Contains(j))
skip_if_no_contract = true;
}
if (skip_if_no_contract)
continue;
// если нет в списке пропущенных столбцов, значит линия НЕЗАПОЛНЕНА
if (!NotDefinedLines.Contains(i))
NotDefinedLines.Add(i);
}
}
}
if(NotDefinedLines.Count != 0)
{
String s = "Сначала введите все данные в сдачи:\n";
for(int i = 0 ; i < NotDefinedLines.Count ; i++)
{
if(i > 0)
s += ", ";
if (this.isRobber)
s += (PAGE__VIEW ? "" : (ROBBERS.GetRobberNo(NotDefinedLines[i]) + 1 + (PAGE__VIEW ? PAGE__NO : 0)).ToString() + ".") + (ROBBERS.GetRobDealNo(NotDefinedLines[i]) + 1).ToString();
else
s += (PAGE__VIEW ? "" : (MATCHES_GetMatchNo(NotDefinedLines[i]) + 1 + (PAGE__VIEW ? PAGE__NO : 0)).ToString() + ".") + (MATCHES_GetMDealNo(NotDefinedLines[i]) + 1).ToString();
}
MessageBox.Show(s);
return;
}
if (this.isRobber)
{
ArrayOfInt arrNotCompletedRobbers = new ArrayOfInt();
if (ROBBERS.Count > 1)
{
for (int i = 0; i < (ROBBERS.Count - 1); i++)
if (ROBBERS[i].IsCompleted() == false)
arrNotCompletedRobbers.Add(i);
}
if (arrNotCompletedRobbers.Count == 0) //нет незаконченных робберов
{
NewDealMenu_NewRDeal(null, null);
}
else //в меню возможность закончить робберы
{
ContextMenu ContMenu = new ContextMenu();
for (int i = 0; i < arrNotCompletedRobbers.Count; i++)
{
MenuItem_RDeal mi = new MenuItem_RDeal();
mi.robNo = arrNotCompletedRobbers[i];
mi.Text = "Продолжить роббер " + (mi.robNo + 1 + (PAGE__VIEW ? PAGE__NO : 0)).ToString();
mi.Click += NewDealMenu_InsertRDeal;
ContMenu.MenuItems.Add(mi);
}
MenuItem mi2 = new MenuItem();
mi2.Text = (ROBBERS.Count == 0 || ROBBERS[ROBBERS.Count - 1].IsCompleted()) ? "Новый роббер" : "Текущий роббер";
mi2.Click += NewDealMenu_NewRDeal;
ContMenu.MenuItems.Add(mi2);
ContMenu.Show(Program.MainForm, new Point(0, Program.MainForm.Height - MENUHEIGHT - 1));
// Удалить конт.меню
ContMenu.MenuItems.Clear();
ContMenu.Dispose();
ContMenu = null;
}
}
else if (this.isSplit)
{
ArrayList arrNotCompletedDeals = new ArrayList();
for (int i = 0; i < VALUES.Count; i++)
{
for (int j = 0; j < SUBDEALS.Count; j++)
{
if (VALUES[i, SUBDEALS[j, 0]] == null)
{
arrNotCompletedDeals.Add(new subdeal(i, j));
}
}
}
if (arrNotCompletedDeals.Count == 0) //нет незаконченных сдач
{
NewDealMenu_NewMDeal(null, null);
}
//.........这里部分代码省略.........
示例5: AddServer
public void AddServer(IMetadataProvider provider, ConnectionInfo connection)
{
//Check if the current connection can create subscription
DataTable dt = null;
try
{
dt = connection.Query("SELECT CanCreate FROM Metadata.Entity WHERE FullName='System.Subscription'");
}
catch (ApplicationException e)
{
log.Info("Exception checking if we can create subscriptions.", e);
}
if (dt != null && (dt.Rows.Count == 1 && dt.Columns.Count == 1))
{
connection.CanCreateSubscription = Convert.ToBoolean(dt.Rows[0][0]);
}
var tableContextMenu = new ContextMenu();
tableContextMenu.MenuItems.Add("Generate Select Statement", (s, e) => GenerateSelectStatement(_contextMenuNode.Tag as Entity, false));
tableContextMenu.MenuItems.Add("Generate Select Statement (with Inherited Properties)", (s, e) => GenerateSelectStatement(_contextMenuNode.Tag as Entity, true));
if (connection.CanCreateSubscription)
tableContextMenu.MenuItems.Add("Subscribe", StartSubscription);
_tableContextMenuItems.Add(connection.Title, tableContextMenu);
var serverContextMenu = new ContextMenu();
serverContextMenu.MenuItems.Add("Refresh", (s, e) => RefreshServer(_contextMenuNode));
if (connection.CanCreateSubscription)
serverContextMenu.MenuItems.Add("Activity Monitor", (s, e) => OpenActivityMonitor(_contextMenuNode));
serverContextMenu.MenuItems.Add("Generate C# Code...", (s, e) => GenerateCSharpCode(_contextMenuNode));
serverContextMenu.MenuItems.Add("Close", (s, e) => CloseServer(_contextMenuNode));
_serverContextMenuItems.Add(connection.Title, serverContextMenu);
TreeNode node = CreateDatabaseNode(provider, connection);
TreeNode[] existingNodes = _tree.Nodes.Find(node.Name, false);
if (existingNodes.Length == 0)
{
// Node doesn't already exist. Add it
_tree.Nodes.Add(node);
_tree.SelectedNode = node;
RefreshServer(node);
}
else
{
// Node exists. Just focus on it.
_tree.SelectedNode = existingNodes[0];
}
connection.ConnectionClosed += (o, e) =>
{
_tableContextMenuItems.Remove(connection.Title);
tableContextMenu.Dispose();
tableContextMenu = null;
_serverContextMenuItems.Remove(connection.Title);
serverContextMenu.Dispose();
serverContextMenu = null;
};
}
示例6: ShowHideTest
public void ShowHideTest ()
{
ContextMenu formMenu = new ContextMenu ();
formMenu.MenuItems.Add ("form item 1");
Form.ContextMenu = formMenu;
Label label = new Label ();
label.Text = "I have my own context menu";
ContextMenu labelMenu = new ContextMenu ();
labelMenu.MenuItems.Add ("label item 1");
label.ContextMenu = labelMenu;
Form.Controls.Add (label);
label.Show ();
var labelProvider = ProviderFactory.FindProvider (label);
Assert.IsNotNull (labelProvider,
"Form's label should have a provider");
// No menu providers unless shown
IRawElementProviderFragment formMenuProvider =
ProviderFactory.FindProvider (formMenu);
Assert.IsNull (formMenuProvider,
"Form menu provider not expected until shown");
IRawElementProviderFragment labelMenuProvider =
ProviderFactory.FindProvider (labelMenu);
Assert.IsNull (labelMenuProvider,
"Label menu provider not expected until shown");
bridge.ResetEventLists ();
// Test showing Form menu
System.Windows.Point winPoint = (System.Windows.Point)
FormProvider.GetPropertyValue (AEIds.ClickablePointProperty.Id);
formMenu.Show (Form, new System.Drawing.Point ((int) winPoint.X, (int) winPoint.Y));
formMenuProvider =
ProviderFactory.FindProvider (formMenu);
Assert.IsNotNull (formMenuProvider,
"Form menu provider expected once menu is shown");
labelMenuProvider =
ProviderFactory.FindProvider (labelMenu);
Assert.IsNull (labelMenuProvider,
"Label menu provider not expected until shown");
Assert.AreEqual (FormProvider,
formMenuProvider.Navigate (NavigateDirection.Parent),
"Form menu parent should be Form");
Assert.IsTrue (ProviderContainsChild (FormProvider, formMenuProvider),
"Form menu should be Form's child");
var tuple = bridge.GetAutomationEventFrom (formMenuProvider,
AEIds.MenuOpenedEvent.Id);
Assert.IsNotNull (tuple,
"MenuOpenedEvent expected");
bridge.ResetEventLists ();
// Test closing Form menu
formMenu.Dispose ();
tuple = bridge.GetAutomationEventFrom (formMenuProvider,
AEIds.MenuClosedEvent.Id);
Assert.IsNotNull (tuple,
"MenuClosedEvent expected");
formMenuProvider =
ProviderFactory.FindProvider (formMenu);
Assert.IsNull (formMenuProvider,
"Form menu provider should be gone after menu closed");
Assert.IsFalse (ProviderContainsChildOfType (FormProvider, ControlType.Menu),
"Form should have no menu child after menu closed");
bridge.ResetEventLists ();
// Test showing Label menu
winPoint = (System.Windows.Point)
labelProvider.GetPropertyValue (AEIds.ClickablePointProperty.Id);
labelMenu.Show (label, new System.Drawing.Point ((int) winPoint.X, (int) winPoint.Y));
formMenuProvider =
ProviderFactory.FindProvider (formMenu);
Assert.IsNull (formMenuProvider,
"Form menu provider not expected while closed");
labelMenuProvider =
ProviderFactory.FindProvider (labelMenu);
Assert.IsNotNull (labelMenuProvider,
"Label menu provider expected once menu is shown");
Assert.AreEqual (labelProvider,
labelMenuProvider.Navigate (NavigateDirection.Parent),
"Label menu parent should be Label");
Assert.IsTrue (ProviderContainsChild (labelProvider, labelMenuProvider),
"Label menu should be Label's child");
tuple = bridge.GetAutomationEventFrom (labelMenuProvider,
AEIds.MenuOpenedEvent.Id);
Assert.IsNotNull (tuple,
"MenuOpenedEvent expected");
bridge.ResetEventLists ();
//.........这里部分代码省略.........
示例7: RebuildTaskbarMenu
private void RebuildTaskbarMenu()
{
trayMenu = new ContextMenu();
/*This first checks if we have a tray icon already so we can toggle it off */
if (trayIcon != null)
{
trayIcon.Visible = false;
trayMenu.Dispose();
trayIcon.Dispose();
}
/*Set up and build tray menu */
trayMenu.MenuItems.Add(Btn1.Text, Btn1_Click);
trayMenu.MenuItems.Add(Btn2.Text, Btn2_Click);
trayMenu.MenuItems.Add(Btn3.Text, Btn3_Click);
trayMenu.MenuItems.Add(Btn4.Text, Btn4_Click);
trayMenu.MenuItems.Add(Btn5.Text, Btn5_Click);
trayMenu.MenuItems.Add(Btn6.Text, Btn6_Click);
trayMenu.MenuItems.Add(Btn7.Text, Btn7_Click);
trayMenu.MenuItems.Add(Btn8.Text, Btn8_Click);
trayMenu.MenuItems.Add(Btn9.Text, Btn9_Click);
trayMenu.MenuItems.Add(Btn10.Text, Btn10_Click);
foreach (MenuItem item in trayMenu.MenuItems)
{
if (item.Text == "")
{
item.Dispose();
}
}
trayMenu.MenuItems.Add("-");
trayMenu.MenuItems.Add("Show App", ShowApp);
trayMenu.MenuItems.Add("Exit", exitBtn_Click);
trayIcon = new NotifyIcon();
trayIcon.Text = "Eclipse Tech Dashboard";
trayIcon.Icon = new Icon(SystemIcons.Application, 40, 40);
trayIcon.ContextMenu = trayMenu;
trayIcon.Visible = true;
}
示例8: ShowContextMenu
//.........这里部分代码省略.........
case 250:
this._ShellView.RefreshContents();
break;
case 251:
this._ShellView.View = ShellViewStyle.ExtraLargeIcon;
break;
case 252:
this._ShellView.View = ShellViewStyle.LargeIcon;
break;
case 253:
this._ShellView.View = ShellViewStyle.Medium;
break;
case 254:
this._ShellView.View = ShellViewStyle.SmallIcon;
break;
case 255:
this._ShellView.View = ShellViewStyle.List;
break;
case 256:
this._ShellView.View = ShellViewStyle.Details;
break;
case 257:
this._ShellView.View = ShellViewStyle.Tile;
break;
case 258:
this._ShellView.View = ShellViewStyle.Content;
break;
case 259:
this._ShellView.View = ShellViewStyle.Thumbstrip;
break;
case 260:
if (this._ShellView.IsGroupsEnabled) {
this._ShellView.DisableGroups();
}
break;
case 301:
this._ShellView.RaiseMiddleClickOnItem(this._Items.First());
break;
default:
break;
}
if (command >= 262 && command <= 262 + this._ShellView.Collumns.Count) {
this._ShellView.SetSortCollumn(true, this._ShellView.Collumns[command - 262], SortOrder.Ascending);
} else if (command > 260 && command != 301) {
if (!this._ShellView.IsGroupsEnabled)
this._ShellView.EnableGroups();
this._ShellView.GenerateGroupsFromColumn(this._ShellView.Collumns[command - (262 + this._ShellView.Collumns.Count) - 1], false);
}
}
if (command > m_CmdFirst) {
string info = string.Empty;
byte[] bytes = new byte[256];
int index;
m_ComInterface.GetCommandString(command - (int)m_CmdFirst, 4, 0, bytes, 260);
index = 0;
while (index < bytes.Length - 1 && (bytes[index] != 0 || bytes[index + 1] != 0)) { index += 2; }
if (index < bytes.Length - 1)
info = Encoding.Unicode.GetString(bytes, 0, index);
switch (info) {
case "open":
(control as ShellView)?.OpenOrNavigateItem();
break;
case "rename":
(control as ShellView)?.RenameSelectedItem();
break;
case "cut":
(control as ShellView)?.CutSelectedFiles();
break;
case "copy":
(control as ShellView)?.CopySelectedFiles();
break;
default:
InvokeCommand((IntPtr)(command - m_CmdFirst), pos, (IntPtr)(command - m_CmdFirst));
break;
}
}
//if (command == 0) {
// if (this._ShellView != null)
// this._ShellView.IsRenameNeeded = false;
//}
User32.DestroyMenu(mnu.Handle);
view.Dispose();
User32.DestroyMenu(view.Handle);
sortMenu.Dispose();
User32.DestroyMenu(sortMenu.Handle);
groupMenu.Dispose();
User32.DestroyMenu(groupMenu.Handle);
}
Marshal.ReleaseComObject(m_ComInterface);
Marshal.ReleaseComObject(m_ComInterface2);
Marshal.ReleaseComObject(m_ComInterface3);
Marshal.Release(_Result);
_Result = IntPtr.Zero;
}