@@ -20,36 +20,49 @@ public MainForm()
20
20
21
21
private void InitFormDesigner ( )
22
22
{
23
- CreateDesignSurface ( 1 ) ;
24
- CreateDesignSurface ( 2 ) ;
25
- CreateDesignSurface ( 3 ) ;
26
- CreateDesignSurface ( 4 ) ;
27
- CreateDesignSurface ( 5 ) ;
28
- CreateDesignSurface ( 6 ) ;
29
-
30
23
tabPage1 . Text = "Use SnapLines" ;
31
24
tabPage2 . Text = "Use Grid (Snap to the grid)" ;
32
25
tabPage3 . Text = "Use Grid" ;
33
26
tabPage4 . Text = "Align control by hand" ;
34
27
tabPage5 . Text = "TabControl and TableLayoutPanel" ;
35
28
tabPage6 . Text = "ToolStripContainer" ;
36
29
37
- // - enable the UndoEngines
38
30
for ( int i = 0 ; i < tabControl1 . TabCount ; i ++ )
39
31
{
40
- IDesignSurfaceExtended isurf = _listOfDesignSurface [ i ] ;
41
- isurf . GetUndoEngineExt ( ) . Enabled = true ;
42
- }
32
+ CreateDesignSurface ( i + 1 ) ;
43
33
44
- // - ISelectionService
45
- // - try to get a ptr to ISelectionService interface
46
- // - if we obtain it then hook the SelectionChanged event
47
- for ( int i = 0 ; i < tabControl1 . TabCount ; i ++ )
48
- {
49
- IDesignSurfaceExtended isurf = _listOfDesignSurface [ i ] ;
50
- _selectionService = ( ISelectionService ) ( isurf . GetIDesignerHost ( ) . GetService ( typeof ( ISelectionService ) ) ) ;
34
+ IDesignSurfaceExtended designSurfaceExtended = _listOfDesignSurface [ i ] ;
35
+
36
+ // - enable the UndoEngines
37
+ designSurfaceExtended . GetUndoEngineExt ( ) . Enabled = true ;
38
+
39
+ // - ISelectionService
40
+ // - try to get a ptr to ISelectionService interface
41
+ // - if we obtain it then hook the SelectionChanged event
42
+ _selectionService = ( ISelectionService ) designSurfaceExtended . GetIDesignerHost ( ) . GetService ( typeof ( ISelectionService ) ) ;
51
43
if ( _selectionService is not null )
44
+ {
52
45
_selectionService . SelectionChanged += OnSelectionChanged ;
46
+ }
47
+
48
+ ( ( Control ) ( designSurfaceExtended as DesignSurface ) . View ) . KeyUp += ( s , e ) =>
49
+ {
50
+ switch ( e . KeyCode )
51
+ {
52
+ case Keys . Up :
53
+ designSurfaceExtended . DoAction ( "KeyMoveUp" ) ;
54
+ break ;
55
+ case Keys . Down :
56
+ designSurfaceExtended . DoAction ( "KeyMoveDown" ) ;
57
+ break ;
58
+ case Keys . Left :
59
+ designSurfaceExtended . DoAction ( "KeyMoveLeft" ) ;
60
+ break ;
61
+ case Keys . Right :
62
+ designSurfaceExtended . DoAction ( "KeyMoveRight" ) ;
63
+ break ;
64
+ }
65
+ } ;
53
66
}
54
67
}
55
68
@@ -59,10 +72,10 @@ private void OnSelectionChanged(object sender, EventArgs e)
59
72
if ( _selectionService is null )
60
73
return ;
61
74
62
- IDesignSurfaceExtended isurf = _listOfDesignSurface [ tabControl1 . SelectedIndex ] ;
63
- if ( isurf is not null )
75
+ IDesignSurfaceExtended designSurfaceExtended = _listOfDesignSurface [ tabControl1 . SelectedIndex ] ;
76
+ if ( designSurfaceExtended is not null )
64
77
{
65
- ISelectionService selectionService = isurf . GetIDesignerHost ( ) . GetService ( typeof ( ISelectionService ) ) as ISelectionService ;
78
+ ISelectionService selectionService = designSurfaceExtended . GetIDesignerHost ( ) . GetService ( typeof ( ISelectionService ) ) as ISelectionService ;
66
79
propertyGrid . SelectedObject = selectionService . PrimarySelection ;
67
80
}
68
81
}
@@ -441,21 +454,21 @@ private void CreateDesignSurface(int n)
441
454
private void SelectRootComponent ( )
442
455
{
443
456
// - find out the DesignSurfaceExt control hosted by the TabPage
444
- IDesignSurfaceExtended isurf = _listOfDesignSurface [ tabControl1 . SelectedIndex ] ;
445
- if ( isurf is not null )
457
+ IDesignSurfaceExtended designSurfaceExtended = _listOfDesignSurface [ tabControl1 . SelectedIndex ] ;
458
+ if ( designSurfaceExtended is not null )
446
459
{
447
460
splitContainer . Panel2 . Controls . Remove ( propertyGrid ) ;
448
461
propertyGrid . Dispose ( ) ;
449
462
propertyGrid = new ( )
450
463
{
451
- DesignerHost = isurf . GetIDesignerHost ( ) ,
464
+ DesignerHost = designSurfaceExtended . GetIDesignerHost ( ) ,
452
465
Dock = DockStyle . Fill ,
453
466
Location = new Point ( 0 , 0 ) ,
454
467
Margin = new Padding ( 4 ) ,
455
468
Name = "propertyGrid" ,
456
469
Size = new Size ( 226 , 502 ) ,
457
470
TabIndex = 0 ,
458
- SelectedObject = isurf . GetIDesignerHost ( ) . RootComponent
471
+ SelectedObject = designSurfaceExtended . GetIDesignerHost ( ) . RootComponent
459
472
} ;
460
473
461
474
splitContainer . Panel2 . Controls . Add ( propertyGrid ) ;
@@ -464,14 +477,14 @@ private void SelectRootComponent()
464
477
465
478
private void undoToolStripMenuItem_Click ( object sender , EventArgs e )
466
479
{
467
- IDesignSurfaceExtended isurf = _listOfDesignSurface [ tabControl1 . SelectedIndex ] ;
468
- isurf ? . GetUndoEngineExt ( ) . Undo ( ) ;
480
+ IDesignSurfaceExtended designSurfaceExtended = _listOfDesignSurface [ tabControl1 . SelectedIndex ] ;
481
+ designSurfaceExtended ? . GetUndoEngineExt ( ) . Undo ( ) ;
469
482
}
470
483
471
484
private void redoToolStripMenuItem_Click ( object sender , EventArgs e )
472
485
{
473
- IDesignSurfaceExtended isurf = _listOfDesignSurface [ tabControl1 . SelectedIndex ] ;
474
- isurf ? . GetUndoEngineExt ( ) . Redo ( ) ;
486
+ IDesignSurfaceExtended designSurfaceExtended = _listOfDesignSurface [ tabControl1 . SelectedIndex ] ;
487
+ designSurfaceExtended ? . GetUndoEngineExt ( ) . Redo ( ) ;
475
488
}
476
489
477
490
private void OnAbout ( object sender , EventArgs e )
@@ -482,8 +495,8 @@ private void OnAbout(object sender, EventArgs e)
482
495
private void toolStripMenuItemTabOrder_Click ( object sender , EventArgs e )
483
496
{
484
497
// - find out the DesignSurfaceExt control hosted by the TabPage
485
- IDesignSurfaceExtended isurf = _listOfDesignSurface [ tabControl1 . SelectedIndex ] ;
486
- isurf ? . SwitchTabOrder ( ) ;
498
+ IDesignSurfaceExtended designSurfaceExtended = _listOfDesignSurface [ tabControl1 . SelectedIndex ] ;
499
+ designSurfaceExtended ? . SwitchTabOrder ( ) ;
487
500
}
488
501
489
502
private void MainForm_Load ( object sender , EventArgs e )
@@ -492,7 +505,7 @@ private void MainForm_Load(object sender, EventArgs e)
492
505
493
506
tabControl1 . Selected += OnTabPageSelected ;
494
507
495
- // - select into the propertygrid the current Form
508
+ // - select into the propertyGrid the current Form
496
509
SelectRootComponent ( ) ;
497
510
}
498
511
@@ -503,7 +516,7 @@ private void OnTabPageSelected(object sender, TabControlEventArgs e)
503
516
504
517
private void OnMenuClick ( object sender , EventArgs e )
505
518
{
506
- IDesignSurfaceExtended isurf = _listOfDesignSurface [ tabControl1 . SelectedIndex ] ;
507
- isurf ? . DoAction ( ( sender as ToolStripMenuItem ) . Text ) ;
519
+ IDesignSurfaceExtended designSurfaceExtended = _listOfDesignSurface [ tabControl1 . SelectedIndex ] ;
520
+ designSurfaceExtended ? . DoAction ( ( sender as ToolStripMenuItem ) . Text ) ;
508
521
}
509
522
}
0 commit comments