Главная » C#, Компоненты » "Горячие" команды формы

0

Метод AddCommand сервиса I Menu Commands е г vice позволяет создавать обработчики "горячих" команд, как показано в листинге 7.5. Обратите внимание, что перед тем как добавить пункт меню, его надо удалить, чтобы избежать дублирования. Конкретная команда назначается с помощью класса MenuCommands или standardcommands. Эти команды не являются напрямую отражением клавиатурных комбинаций, это именно набор команд (листинг 7.6). Например, LockCommand или Brii tF r,v iro нс ЯИЛЯЮ1СЯ кодлми кгтииш

Листинг 7 5 Создл-шо "горячей" команды формы и режим о разработки

using System;

using System.Windows.Forms.Design; using System.ComponentModel; using System.ComponentModel.Design;

namespace MyControl {

class GradientLabelDesigner : ControlDesigner (

DesignerVerb dverb; MenuCommand mc;

public override void Initialize(iComponent component) (

base.Initialize(component);

// Получаем интерфейс сервиса

IMenuCommandServi.ee mcs = (IMenuCommandService) component. Site.

GetService(typeof(IMenuCommandService));

// Добавляем обработчик клавиши <Hame> mc = new MenuCommand(new EventHandler(OnKeyHome), MenuCommands.KeyHome);

mc.Enabled = true; mc.Visible = true; mc.Supported = true; mcs. Remove Ccanmand (mc) ; mcs.AddCommand(mc);

}

// Обработчик клавиши <Home>

private void OnKeyHame(object sender, EventArgs e)

{

System.Windows.Forms.MessageBox.Show("Нажата клавиша <Hame>.") ;

}

1

}

Лрсгинг 7 6 Классы SLandardCcankir.ds и MenuCcsnmands

using System;

namespace System. Component Model. Design

{

public class StandardCommands

}

public static readonly CommandlD AlignBottom;

public static readonly CommandlD AlignHorizontalCenters;

public static readonly CanmandlD AlignLeft;

public static readonly CommandlD AlignRight;

public static readonly CommandlD AlignToGrid;

public static readonly CommandlD AlignTop;

public static readonly CanmandlD AlignVerticalCenters;

public static readonly CommandlD ArrangeBottom;

public static readonly CommandlD Arrangelcons;

public static readonly CommandlD ArrangeRight;

pablic static readonly CommandlD BringForward;

public static readonly CommandlD BringToFront;

public static readonly CommandlD CenterHorizontally;

public static readonly CommandlD CenterVertically;

public static readonly CommandlD Copy; public static readonly CommandlD Cut; public static readonly CommandlD Deleter- public static readonly CommandlD DocumentOutlme; public static readonly CommandlD FlHelp; public static readonly CommandlD Group;

public static readonly CcmmandID HorizSpaceConcatenate;

public static readonly CommandlD HorizSpaceDecrease;

public static readonly CommandlD HorizSpacelncrease;

public static readonly CommandlD HorizSpaceMakeEqual;

public static readonly CommandlD Lineuplcons;

public static readonly CommandlD LockControls;

public static readonly CommandlD MultiLevelRedo;

public static readonly CommandlD MultiLevelUndo;

public static readonly CommandlD Paste;

public static readonly CommandlD Properties;

public static readonly CommandlD PropertiesWindow;

public static readonly CommandlD Redo;

public static readonly CommandlD Replace;

public static readonly CommandlD SelectAll;

public static readonly CommandlD SendBackward;

public static readonly CommandlD SendToBack;

public static readonly CommandlD ShowGrid;

public static readonly CommandlD ShowLargelcons;

public static readonly CommandlD SizeToControl;

public static readonly CommandlD SizeToControlHeight;

public static readonly CommandlD SizeToControlWidth;

public static readonly CommandlD SizeToFit;

public static readonly CommandlD SizeToGrid;

public static readonly CommandlD SnapToGrid;

public static readonly CommandlD TabOrder;

public static readonly CommandlD Undo;

public static readonly CommandlD Ungroup;

public static readonly CommandlD VerbFirst;

public static readonly CommandlD VerbLast;

public static readonly CommandlD VertSpaceConcatenate;

public static readonly CommandlD VertSpaceDecrease;

public static readonly CommandlD VertSpacelncrease;

public static readonly CommandlD VertSpaceMakeEqual;

public static readonly CommandlD ViewCode;

public static readonly CommandlD ViewGrid;

public StandardCommands();

using System.ComponentModel.Design;

namespace System. Windows. E’orms. Design

{

public sealed class MenuCommands : StandardComraands

{

public static       readonly  CommandID ComponentTrayMenu;

public static       readonly  CommandID ContainerMenu;

public static       readonly  CommandID DesignerProperties;

public static       readonly  CommandID EditLabel;

public static       readonly  CommandID KeyCancel;

public static       readonly  CommandID KeyDefaultAction;

public static       readonly  CommandID KeyEnd;

public static       readonly  CommandID KeyHome;

public static       readonly  CommandID KeylnvokeSmartTag;

public static       readonly  CommandID KeyMoveDown;

public static       readonly  CommandID KeyMoveLeft;

public static       readonly  CommandID KeyMoveRight;

public static       readonly  CommandID KeyMoveUp;

public static      readonly   CommandID KeyNudgeDown;

public static      readonly   CommandID KeyNudgeHeightDecrease;

public static      readonly   CommandID KeyNudgeHeightlncrease;

public static       readonly  CommandID KeyNudgeLeft;

public static      readonly   CommandID KeyNudgeRight;

public static      readonly   CommandID KeyNudgeUp;

public static      readonly   CommandID KeyNudgeWidthDecrease;

public static      readonly   CommandID KeyNudgeWidthincrease;

public static      readonly   CommandID KeyReverseCancel;

public static      readonly  CommandID KeySelectNext;

public static      readonly  CommandID KeySelectPrevious;

public static      readonly  CommandID KeyShiftEnd;

public static      readonly  CommandID KeyShiftHome;

public static      readonly  CommandID KeySizeHeightDecrease;

public static      readonly  CommandID KeySizeHeightlncrease;

public static      readonly  CommandID KeySizeWidthDecrease;

public static      readonly  CommandID KeySizeWidthlncrease;

public static      readonly  CommandID KeyTabOrderSelect;

public static      readonly  CommandID SelectionMenu;

public static      readonly  CommandID SetStatusP-ectangle;

public static      readonly  CommandID SetStatusText;

public static      readonly   CommandID TraySelectionMenu;

public MenuCommands();

Литература:

Агуров П. В. C#. Разработка компонентов в MS Visual Studio 2005/2008. – СПб.: БХВ-Петербург, 2008. — 480 е.: ил.

По теме:

  • Комментарии