void ShowContextMenu() { ContextMenuStrip ctx; if (!IsSelected) { ctx = WatchVarWrapper.GetContextMenuStrip(); } else { ctx = new ContextMenuStrip(); if (_watchVariablePanel != null) { foreach (var item in _watchVariablePanel.GetSelectionToolStripItems()) { ctx.Items.Add(item); } } } ctx.Show(System.Windows.Forms.Cursor.Position); }
public WatchVariableControl( WatchVariableControlPrecursor watchVarPrecursor, string name, WatchVariable watchVar, WatchVariableSubclass subclass, Color?backgroundColor, bool?useHex, bool?invertBool, WatchVariableCoordinate?coordinate, List <VariableGroup> groupList) { // Store the precursor _watchVarPrecursor = watchVarPrecursor; // Initialize main fields _varName = name; GroupList = groupList; _showBorder = false; _editMode = false; _renameMode = false; FixedAddressList = null; // Initialize color fields _baseColor = backgroundColor ?? DEFAULT_COLOR; _currentColor = _baseColor; _isFlashing = false; _flashStartTime = DateTime.Now; // Initialize size fields _variableNameWidth = VariableNameWidth; _variableValueWidth = VariableValueWidth; _variableHeight = VariableHeight; // Create controls InitializeBase(); _namePanel = CreateNamePanel(); _nameTextBox = CreateNameTextBox(); _lockPictureBox = CreateLockPictureBox(); _pinPictureBox = CreatePinPictureBox(); _valueTextBox = CreateValueTextBox(); _valueCheckBox = CreateValueCheckBox(); // Add controls to their containers base.Controls.Add(_valueTextBox, 1, 0); base.Controls.Add(_valueCheckBox, 1, 0); base.Controls.Add(_namePanel, 0, 0); _namePanel.Controls.Add(_pinPictureBox); _namePanel.Controls.Add(_lockPictureBox); _namePanel.Controls.Add(_nameTextBox); // Create var x _watchVarWrapper = WatchVariableWrapper.CreateWatchVariableWrapper( watchVar, this, subclass, useHex, invertBool, coordinate); // Initialize context menu strip _valueTextboxOriginalContextMenuStrip = _valueTextBox.ContextMenuStrip; _nameTextboxOriginalContextMenuStrip = _nameTextBox.ContextMenuStrip; ContextMenuStrip = _watchVarWrapper.GetContextMenuStrip(); _nameTextBox.ContextMenuStrip = ContextMenuStrip; _valueTextBox.ContextMenuStrip = ContextMenuStrip; // Set whether to start as a checkbox SetUseCheckbox(_watchVarWrapper.StartsAsCheckbox()); // Add functions _namePanel.Click += (sender, e) => OnNameTextBoxClick(); _nameTextBox.Click += (sender, e) => OnNameTextBoxClick(); _nameTextBox.Leave += (sender, e) => { RenameMode = false; }; _nameTextBox.KeyDown += (sender, e) => OnNameTextValueKeyDown(e); _valueTextBox.DoubleClick += (sender, e) => { EditMode = true; }; _valueTextBox.KeyDown += (sender, e) => OnValueTextValueKeyDown(e); _valueTextBox.Leave += (sender, e) => { EditMode = false; }; _valueCheckBox.Click += (sender, e) => OnCheckboxClick(); }