本文整理汇总了C#中System.Windows.Forms.ContextMenuStrip.Focus方法的典型用法代码示例。如果您正苦于以下问题:C# ContextMenuStrip.Focus方法的具体用法?C# ContextMenuStrip.Focus怎么用?C# ContextMenuStrip.Focus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.ContextMenuStrip
的用法示例。
在下文中一共展示了ContextMenuStrip.Focus方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: requestColorDialog
public static Color requestColorDialog(Control sender)
{
Color res = Color.Empty;
ContextMenuStrip cm = new ContextMenuStrip();
var ColorDic = new Dictionary<string, Color>();
ColorDic.Add("Red", Color.Red);
ColorDic.Add("Blue", Color.Blue);
ColorDic.Add("Yellow", Color.Yellow);
ColorDic.Add("Green", Color.Green);
ColorDic.Add("Transparent", Color.FromArgb(0, 255, 255, 255));
foreach ( KeyValuePair<string, Color> pair in ColorDic)
{
Bitmap bmp = new Bitmap(10, 10);
for(int k = 0; k < bmp.Width; k++)
{
for(int v = 0; v < bmp.Height; v++)
{
bmp.SetPixel(k, v, pair.Value);
}
}
cm.Items.Add(new ToolStripMenuItem(pair.Key, bmp, (s, e) => { res = pair.Value; }));
}
cm.Items.Add(new ToolStripMenuItem("Custom...", new Bitmap(1, 1), (s, e) => { res = oldDialogPicker(); }));
cm.Show(sender, sender.PointToClient(new Point(Cursor.Position.X, Cursor.Position.Y)));
cm.Focus();
while (cm.Visible == true) { Application.DoEvents(); }
return res;
}
示例2: ShowMenuAtCursor
/// <summary>
/// This method will show the supplied context menu at the mouse cursor, also makes sure it has focus and it's not visible in the taskbar.
/// </summary>
/// <param name="menu"></param>
private static void ShowMenuAtCursor(ContextMenuStrip menu) {
// find a suitable location
Point location = Cursor.Position;
Rectangle menuRectangle = new Rectangle(location, menu.Size);
menuRectangle.Intersect(WindowCapture.GetScreenBounds());
if (menuRectangle.Height < menu.Height) {
location.Offset(-40, -(menuRectangle.Height - menu.Height));
} else {
location.Offset(-40, -10);
}
// This prevents the problem that the context menu shows in the task-bar
User32.SetForegroundWindow(PluginUtils.Host.NotifyIcon.ContextMenuStrip.Handle);
menu.Show(location);
menu.Focus();
// Wait for the menu to close, so we can dispose it.
while (true) {
if (menu.Visible) {
Application.DoEvents();
Thread.Sleep(100);
} else {
menu.Dispose();
break;
}
}
}
示例3: ShowPickerMenu
/// <summary>
/// This method will create and show the destination picker menu
/// </summary>
/// <param name="addDynamics">Boolean if the dynamic values also need to be added</param>
/// <param name="surface">The surface which can be exported</param>
/// <param name="captureDetails">Details for the surface</param>
/// <param name="destinations">The list of destinations to show</param>
/// <returns></returns>
public ExportInformation ShowPickerMenu(bool addDynamics, ISurface surface, ICaptureDetails captureDetails, IEnumerable<IDestination> destinations) {
// Generate an empty ExportInformation object, for when nothing was selected.
ExportInformation exportInformation = new ExportInformation(Designation, Language.GetString("settings_destination_picker"));
ContextMenuStrip menu = new ContextMenuStrip();
menu.ImageScalingSize = configuration.IconSize;
menu.Tag = null;
menu.Closing += delegate(object source, ToolStripDropDownClosingEventArgs eventArgs) {
LOG.DebugFormat("Close reason: {0}", eventArgs.CloseReason);
switch (eventArgs.CloseReason) {
case ToolStripDropDownCloseReason.AppFocusChange:
if (menu.Tag == null) {
// Do not allow the close if the tag is not set, this means the user clicked somewhere else.
eventArgs.Cancel = true;
} else {
LOG.DebugFormat("Letting the menu 'close' as the tag is set to '{0}'", menu.Tag);
}
break;
case ToolStripDropDownCloseReason.ItemClicked:
case ToolStripDropDownCloseReason.CloseCalled:
// The ContextMenuStrip can be "closed" for these reasons.
break;
case ToolStripDropDownCloseReason.Keyboard:
// Dispose as the close is clicked
if (!captureDetails.HasDestination("Editor")) {
surface.Dispose();
surface = null;
}
break;
default:
eventArgs.Cancel = true;
break;
}
};
menu.MouseEnter += delegate(object source, EventArgs eventArgs) {
// in case the menu has been unfocused, focus again so that dropdown menus will still open on mouseenter
if(!menu.ContainsFocus) menu.Focus();
};
foreach (IDestination destination in destinations) {
// Fix foreach loop variable for the delegate
ToolStripMenuItem item = destination.GetMenuItem(addDynamics, menu,
delegate(object sender, EventArgs e) {
ToolStripMenuItem toolStripMenuItem = sender as ToolStripMenuItem;
if (toolStripMenuItem == null) {
return;
}
IDestination clickedDestination = (IDestination)toolStripMenuItem.Tag;
if (clickedDestination == null) {
return;
}
menu.Tag = clickedDestination.Designation;
// Export
exportInformation = clickedDestination.ExportCapture(true, surface, captureDetails);
if (exportInformation != null && exportInformation.ExportMade) {
LOG.InfoFormat("Export to {0} success, closing menu", exportInformation.DestinationDescription);
// close menu if the destination wasn't the editor
menu.Close();
// Cleanup surface, only if there is no editor in the destinations and we didn't export to the editor
if (!captureDetails.HasDestination("Editor") && !"Editor".Equals(clickedDestination.Designation)) {
surface.Dispose();
surface = null;
}
} else {
LOG.Info("Export cancelled or failed, showing menu again");
// Make sure a click besides the menu don't close it.
menu.Tag = null;
// This prevents the problem that the context menu shows in the task-bar
ShowMenuAtCursor(menu);
}
}
);
if (item != null) {
menu.Items.Add(item);
}
}
// Close
menu.Items.Add(new ToolStripSeparator());
ToolStripMenuItem closeItem = new ToolStripMenuItem(Language.GetString("editor_close"));
closeItem.Image = GreenshotResources.getImage("Close.Image");
closeItem.Click += delegate {
// This menu entry is the close itself, we can dispose the surface
menu.Close();
if (!captureDetails.HasDestination("Editor")) {
surface.Dispose();
surface = null;
}
};
menu.Items.Add(closeItem);
//.........这里部分代码省略.........
示例4: Main
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
RunParam runParam = RunParam.standart; // Params for running app ("-alert", "-input", or "")
string[] args = Environment.GetCommandLineArgs();
if (args.Length > 1)
{
if (args[1].Equals("-alert")) runParam = RunParam.alertWindow;
if (args[1].Equals("-input")) runParam = RunParam.inputTextBox;
}
switch (runParam){
// If app starts with -alert argument on first place, show alert window (with this arg app added to scheduler)
case RunParam.alertWindow:
string[] messageArray = new string[args.Length - 2];
if (args.Length > 2)
{
// args[0] => app name
// args[1] => "-alert"
// starts from args[2]:
for (int i = 2; i < args.Length; i++)
{
messageArray[(i - 2)] = args[i];
}
}
Alert alertForm = new Alert(String.Join(" ", messageArray));
alertForm.FormClosed += AlertFormClosed;
alertForm.Show();
break;
// If app starts with -input argument on first place, show input window to customize alert message
case RunParam.inputTextBox:
string taskArgs = "";
for (int i = 2; i < args.Length; i++)
{
taskArgs += args[i];
taskArgs += " ";
}
InputForm inputForm = new InputForm();
inputForm.FormClosed += InputFormClosed;
inputForm.Show();
break;
default:
var menuStrip = new ContextMenuStrip();
var gear = Parser.ReadConfigs();
if (gear == null || gear.MenuItems == null || gear.MenuItems.Count == 0)
{
TurnOffAsync();
return;
}
menuStrip.Items.AddRange(gear.MenuItems.ToArray());
menuStrip.Closed += MenuStripClosed;
menuStrip.Show(gear.StartX, gear.StartY);
menuStrip.Focus();
menuStrip.Items[gear.SelectedIndex].Select();
break;
}
Application.Run();
}
示例5: ShowMenuAtCursor
public static void ShowMenuAtCursor(ContextMenuStrip menu)
{
// find a suitable location
Point location = Cursor.Position;
Rectangle menuRectangle = new Rectangle(location, menu.Size);
menuRectangle.Intersect(WindowCapture.GetScreenBounds());
if (menuRectangle.Height < menu.Height) {
location.Offset(-40, -(menuRectangle.Height - menu.Height));
} else {
location.Offset(-40, -10);
}
menu.Show(location);
menu.Focus();
}