Skip to content

related to issue 10466: add short cut ↑, ↓, ←, → to demo console #13513

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 47 additions & 34 deletions src/test/integration/DesignSurface/DemoConsole/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,36 +20,49 @@ public MainForm()

private void InitFormDesigner()
{
CreateDesignSurface(1);
CreateDesignSurface(2);
CreateDesignSurface(3);
CreateDesignSurface(4);
CreateDesignSurface(5);
CreateDesignSurface(6);

tabPage1.Text = "Use SnapLines";
tabPage2.Text = "Use Grid (Snap to the grid)";
tabPage3.Text = "Use Grid";
tabPage4.Text = "Align control by hand";
tabPage5.Text = "TabControl and TableLayoutPanel";
tabPage6.Text = "ToolStripContainer";

// - enable the UndoEngines
for (int i = 0; i < tabControl1.TabCount; i++)
{
IDesignSurfaceExtended isurf = _listOfDesignSurface[i];
isurf.GetUndoEngineExt().Enabled = true;
}
CreateDesignSurface(i + 1);

// - ISelectionService
// - try to get a ptr to ISelectionService interface
// - if we obtain it then hook the SelectionChanged event
for (int i = 0; i < tabControl1.TabCount; i++)
{
IDesignSurfaceExtended isurf = _listOfDesignSurface[i];
_selectionService = (ISelectionService)(isurf.GetIDesignerHost().GetService(typeof(ISelectionService)));
IDesignSurfaceExtended designSurfaceExtended = _listOfDesignSurface[i];

// - enable the UndoEngines
designSurfaceExtended.GetUndoEngineExt().Enabled = true;

// - ISelectionService
// - try to get a ptr to ISelectionService interface
// - if we obtain it then hook the SelectionChanged event
_selectionService = (ISelectionService)designSurfaceExtended.GetIDesignerHost().GetService(typeof(ISelectionService));
if (_selectionService is not null)
{
_selectionService.SelectionChanged += OnSelectionChanged;
}

((Control)(designSurfaceExtended as DesignSurface).View).KeyUp += (s, e) =>
{
switch (e.KeyCode)
{
case Keys.Up:
designSurfaceExtended.DoAction("KeyMoveUp");
break;
case Keys.Down:
designSurfaceExtended.DoAction("KeyMoveDown");
break;
case Keys.Left:
designSurfaceExtended.DoAction("KeyMoveLeft");
break;
case Keys.Right:
designSurfaceExtended.DoAction("KeyMoveRight");
break;
}
};
}
}

Expand All @@ -59,10 +72,10 @@ private void OnSelectionChanged(object sender, EventArgs e)
if (_selectionService is null)
return;

IDesignSurfaceExtended isurf = _listOfDesignSurface[tabControl1.SelectedIndex];
if (isurf is not null)
IDesignSurfaceExtended designSurfaceExtended = _listOfDesignSurface[tabControl1.SelectedIndex];
if (designSurfaceExtended is not null)
{
ISelectionService selectionService = isurf.GetIDesignerHost().GetService(typeof(ISelectionService)) as ISelectionService;
ISelectionService selectionService = designSurfaceExtended.GetIDesignerHost().GetService(typeof(ISelectionService)) as ISelectionService;
propertyGrid.SelectedObject = selectionService.PrimarySelection;
}
}
Expand Down Expand Up @@ -441,21 +454,21 @@ private void CreateDesignSurface(int n)
private void SelectRootComponent()
{
// - find out the DesignSurfaceExt control hosted by the TabPage
IDesignSurfaceExtended isurf = _listOfDesignSurface[tabControl1.SelectedIndex];
if (isurf is not null)
IDesignSurfaceExtended designSurfaceExtended = _listOfDesignSurface[tabControl1.SelectedIndex];
if (designSurfaceExtended is not null)
{
splitContainer.Panel2.Controls.Remove(propertyGrid);
propertyGrid.Dispose();
propertyGrid = new()
{
DesignerHost = isurf.GetIDesignerHost(),
DesignerHost = designSurfaceExtended.GetIDesignerHost(),
Dock = DockStyle.Fill,
Location = new Point(0, 0),
Margin = new Padding(4),
Name = "propertyGrid",
Size = new Size(226, 502),
TabIndex = 0,
SelectedObject = isurf.GetIDesignerHost().RootComponent
SelectedObject = designSurfaceExtended.GetIDesignerHost().RootComponent
};

splitContainer.Panel2.Controls.Add(propertyGrid);
Expand All @@ -464,14 +477,14 @@ private void SelectRootComponent()

private void undoToolStripMenuItem_Click(object sender, EventArgs e)
{
IDesignSurfaceExtended isurf = _listOfDesignSurface[tabControl1.SelectedIndex];
isurf?.GetUndoEngineExt().Undo();
IDesignSurfaceExtended designSurfaceExtended = _listOfDesignSurface[tabControl1.SelectedIndex];
designSurfaceExtended?.GetUndoEngineExt().Undo();
}

private void redoToolStripMenuItem_Click(object sender, EventArgs e)
{
IDesignSurfaceExtended isurf = _listOfDesignSurface[tabControl1.SelectedIndex];
isurf?.GetUndoEngineExt().Redo();
IDesignSurfaceExtended designSurfaceExtended = _listOfDesignSurface[tabControl1.SelectedIndex];
designSurfaceExtended?.GetUndoEngineExt().Redo();
}

private void OnAbout(object sender, EventArgs e)
Expand All @@ -482,8 +495,8 @@ private void OnAbout(object sender, EventArgs e)
private void toolStripMenuItemTabOrder_Click(object sender, EventArgs e)
{
// - find out the DesignSurfaceExt control hosted by the TabPage
IDesignSurfaceExtended isurf = _listOfDesignSurface[tabControl1.SelectedIndex];
isurf?.SwitchTabOrder();
IDesignSurfaceExtended designSurfaceExtended = _listOfDesignSurface[tabControl1.SelectedIndex];
designSurfaceExtended?.SwitchTabOrder();
}

private void MainForm_Load(object sender, EventArgs e)
Expand All @@ -492,7 +505,7 @@ private void MainForm_Load(object sender, EventArgs e)

tabControl1.Selected += OnTabPageSelected;

// - select into the propertygrid the current Form
// - select into the propertyGrid the current Form
SelectRootComponent();
}

Expand All @@ -503,7 +516,7 @@ private void OnTabPageSelected(object sender, TabControlEventArgs e)

private void OnMenuClick(object sender, EventArgs e)
{
IDesignSurfaceExtended isurf = _listOfDesignSurface[tabControl1.SelectedIndex];
isurf?.DoAction((sender as ToolStripMenuItem).Text);
IDesignSurfaceExtended designSurfaceExtended = _listOfDesignSurface[tabControl1.SelectedIndex];
designSurfaceExtended?.DoAction((sender as ToolStripMenuItem).Text);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,10 @@ public void DoAction(string command)
"PASTE" => StandardCommands.Paste,
"DELETE" => StandardCommands.Delete,
"INVOKESMARTTAG" => MenuCommands.KeyInvokeSmartTag,
"KEYMOVEUP" => MenuCommands.KeyMoveUp,
"KEYMOVEDOWN" => MenuCommands.KeyMoveDown,
"KEYMOVELEFT" => MenuCommands.KeyMoveLeft,
"KEYMOVERIGHT" => MenuCommands.KeyMoveRight,
_ => null,
};

Expand Down