-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDemoObjectVisualiserForm.cs
More file actions
82 lines (72 loc) · 2.71 KB
/
Copy pathDemoObjectVisualiserForm.cs
File metadata and controls
82 lines (72 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using System;
using System.Linq;
using System.Windows.Forms;
using Microsoft.VisualStudio.DebuggerVisualizers;
namespace VisualiserDemo
{
public partial class DemoObjectVisualiserForm : Form
{
private DemoObject _objectToVisualise;
public DemoObjectVisualiserForm()
{
InitializeComponent();
}
public DemoObjectVisualiserForm(DemoObject objectToVisualise)
: this()
{
_objectToVisualise = objectToVisualise;
ShowObject();
}
private void ShowObject()
{
//Loop through each element and show its value in a table
foreach (var i in Enumerable.Range(0, _objectToVisualise.IntArray.GetUpperBound(0)))
{
foreach (var j in Enumerable.Range(0, _objectToVisualise.IntArray.GetUpperBound(1)))
{
arrayContents.Text += _objectToVisualise.IntArray[i, j].ToString() + '\t';
}
arrayContents.Text += Environment.NewLine;
}
//visualise the colour
colourBox.BackColor = _objectToVisualise.Colour;
}
private void colourBox_Click(object sender, EventArgs e)
{
//When the colour is clicked, show the dialog to change it
var colordialog = new ColorDialog();
var result = colordialog.ShowDialog();
if (result == System.Windows.Forms.DialogResult.OK)
{
colourBox.BackColor = colordialog.Color;
}
}
private void saveButton_Click(object sender, EventArgs e)
{
//This form is shown modally; hiding it allows
//control to be handed back to the calling routine
//while retaining it in memory
this.Hide();
}
}
/// <summary>
/// An instance of this is created and called by the debugger
/// </summary>
public class DemoObjectVisualiser : DialogDebuggerVisualizer
{
protected override void Show(IDialogVisualizerService windowService, IVisualizerObjectProvider objectProvider)
{
//make sure the object is the correct type
var objectToVisualise = objectProvider.GetObject() as DemoObject;
//Show the visualiser
var form = new DemoObjectVisualiserForm(objectToVisualise);
windowService.ShowDialog(form);
//If the object is replaceable, update the colour
if (objectProvider.IsObjectReplaceable)
{
objectToVisualise.Colour = form.colourBox.BackColor;
objectProvider.ReplaceObject(objectToVisualise);
}
}
}
}