Making display resize work.
Clearing the display before when closing.
2 using System.Collections.Generic;
3 using System.ComponentModel;
8 using System.Threading.Tasks;
9 using System.Windows.Forms;
10 using System.ServiceModel;
11 using System.ServiceModel.Channels;
12 using System.Diagnostics;
16 namespace SharpDisplayClient
18 public partial class MainForm : Form
20 DisplayClient iClient;
22 ContentAlignment Alignment;
23 DataField iTextFieldTop;
27 InitializeComponent();
28 Alignment = ContentAlignment.MiddleLeft;
29 iTextFieldTop = new DataField(0);
33 private void MainForm_Load(object sender, EventArgs e)
35 iClient = new DisplayClient(this);
38 //Connect using unique name
39 //string name = DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.fff tt");
40 string name = "Client-" + (iClient.ClientCount() - 1);
41 iClient.SetName(name);
42 //Text = Text + ": " + name;
43 Text = "[[" + name + "]] " + iClient.SessionId;
46 textBoxTop.Text = iClient.Name;
47 textBoxBottom.Text = iClient.SessionId;
53 public delegate void CloseConnectionDelegate();
54 public delegate void CloseDelegate();
59 public void CloseConnectionThreadSafe()
61 if (this.InvokeRequired)
63 //Not in the proper thread, invoke ourselves
64 CloseConnectionDelegate d = new CloseConnectionDelegate(CloseConnectionThreadSafe);
65 this.Invoke(d, new object[] { });
69 //We are in the proper thread
72 string sessionId = iClient.SessionId;
73 Trace.TraceInformation("Closing client: " + sessionId);
75 Trace.TraceInformation("Closed client: " + sessionId);
85 public void CloseThreadSafe()
87 if (this.InvokeRequired)
89 //Not in the proper thread, invoke ourselves
90 CloseDelegate d = new CloseDelegate(CloseThreadSafe);
91 this.Invoke(d, new object[] { });
95 //We are in the proper thread
101 private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
103 CloseConnectionThreadSafe();
106 public bool IsClientReady()
108 return (iClient != null && iClient.IsReady());
111 private void buttonAlignLeft_Click(object sender, EventArgs e)
113 Alignment = ContentAlignment.MiddleLeft;
114 textBoxTop.TextAlign = HorizontalAlignment.Left;
115 textBoxBottom.TextAlign = HorizontalAlignment.Left;
118 private void buttonAlignCenter_Click(object sender, EventArgs e)
120 Alignment = ContentAlignment.MiddleCenter;
121 textBoxTop.TextAlign = HorizontalAlignment.Center;
122 textBoxBottom.TextAlign = HorizontalAlignment.Center;
125 private void buttonAlignRight_Click(object sender, EventArgs e)
127 Alignment = ContentAlignment.MiddleRight;
128 textBoxTop.TextAlign = HorizontalAlignment.Right;
129 textBoxBottom.TextAlign = HorizontalAlignment.Right;
132 private void buttonSetTopText_Click(object sender, EventArgs e)
134 //TextField top = new TextField(0, textBoxTop.Text, ContentAlignment.MiddleLeft);
135 iTextFieldTop.Text = textBoxTop.Text;
136 iTextFieldTop.Alignment = Alignment;
137 bool res = iClient.SetField(iTextFieldTop);
141 MessageBox.Show("Create you fields first", "Field update error", MessageBoxButtons.OK, MessageBoxIcon.Error);
147 private void buttonSetText_Click(object sender, EventArgs e)
149 //Set one column two lines layout
150 TableLayout layout = new TableLayout(1, 2);
151 iClient.SetLayout(layout);
154 iClient.CreateFields(new DataField[]
156 new DataField(0, textBoxTop.Text, Alignment),
157 new DataField(1, textBoxBottom.Text, Alignment)
161 private void buttonLayoutUpdate_Click(object sender, EventArgs e)
163 //Define a 2 by 2 layout
164 TableLayout layout = new TableLayout(2,2);
165 //Second column only takes up 25%
166 layout.Columns[1].Width = 25F;
167 //Send layout to server
168 iClient.SetLayout(layout);
171 private void buttonSetBitmap_Click(object sender, EventArgs e)
178 Bitmap bitmap = new Bitmap(x2,y2);
179 Pen blackPen = new Pen(Color.Black, 3);
181 // Draw line to screen.
182 using (var graphics = Graphics.FromImage(bitmap))
184 graphics.DrawLine(blackPen, x1, y1, x2, y2);
185 graphics.DrawLine(blackPen, x1, y2, x2, y1);
188 DataField field = new DataField(0, bitmap);
189 //field.ColumnSpan = 2;
190 iClient.SetField(field);
193 private void buttonBitmapLayout_Click(object sender, EventArgs e)
195 SetLayoutWithBitmap();
199 /// Define a layout with a bitmap field on the left and two lines of text on the right.
201 private void SetLayoutWithBitmap()
203 //Define a 2 by 2 layout
204 TableLayout layout = new TableLayout(2, 2);
205 //First column only takes 25%
206 layout.Columns[0].Width = 25F;
207 //Second column takes up 75%
208 layout.Columns[1].Width = 75F;
209 //Send layout to server
210 iClient.SetLayout(layout);
212 //Set a bitmap for our first field
218 Bitmap bitmap = new Bitmap(x2, y2);
219 Pen blackPen = new Pen(Color.Black, 3);
221 // Draw line to screen.
222 using (var graphics = Graphics.FromImage(bitmap))
224 graphics.DrawLine(blackPen, x1, y1, x2, y2);
225 graphics.DrawLine(blackPen, x1, y2, x2, y1);
228 //Create a bitmap field from the bitmap we just created
229 DataField field = new DataField(0, bitmap);
230 //We want our bitmap field to span across two rows
234 iClient.CreateFields(new DataField[]
237 new DataField(1, textBoxTop.Text, Alignment),
238 new DataField(2, textBoxBottom.Text, Alignment)
243 private void buttonIndicatorsLayout_Click(object sender, EventArgs e)
245 //Define a 2 by 4 layout
246 TableLayout layout = new TableLayout(2, 4);
248 layout.Columns[0].Width = 87.5F;
250 layout.Columns[1].Width = 12.5F;
251 //Send layout to server
252 iClient.SetLayout(layout);
254 //Create a bitmap for our indicators field
260 Bitmap bitmap = new Bitmap(x2, y2);
261 Pen blackPen = new Pen(Color.Black, 3);
263 // Draw line to screen.
264 using (var graphics = Graphics.FromImage(bitmap))
266 graphics.DrawLine(blackPen, x1, y1, x2, y2);
267 graphics.DrawLine(blackPen, x1, y2, x2, y1);
270 //Create a bitmap field from the bitmap we just created
271 DataField indicator1 = new DataField(2, bitmap);
272 //Create a bitmap field from the bitmap we just created
273 DataField indicator2 = new DataField(3, bitmap);
274 //Create a bitmap field from the bitmap we just created
275 DataField indicator3 = new DataField(4, bitmap);
276 //Create a bitmap field from the bitmap we just created
277 DataField indicator4 = new DataField(5, bitmap);
280 DataField textFieldTop = new DataField(0, textBoxTop.Text, Alignment);
281 textFieldTop.RowSpan = 2;
283 DataField textFieldBottom = new DataField(1, textBoxBottom.Text, Alignment);
284 textFieldBottom.RowSpan = 2;
288 iClient.CreateFields(new DataField[]
300 private void buttonUpdateTexts_Click(object sender, EventArgs e)
303 bool res = iClient.SetFields(new DataField[]
305 new DataField(0, textBoxTop.Text, Alignment),
306 new DataField(1, textBoxBottom.Text, Alignment)
311 MessageBox.Show("Create you fields first", "Field update error", MessageBoxButtons.OK, MessageBoxIcon.Error);