Now having a single class for both text and bitmap field.
Thus we should soon be able to use common functions to pass in fields.
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
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 iCallback = new Callback(this);
36 iClient = new Client(iCallback);
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 Trace.TraceInformation("Closing client: " + iClient.SessionId);
74 Trace.TraceInformation("Closed client: " + iClient.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.State == CommunicationState.Opened);
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 iClient.SetText(iTextFieldTop);
140 private void buttonSetText_Click(object sender, EventArgs e)
142 //iClient.SetText(0,"Top");
143 //iClient.SetText(1, "Bottom");
144 //TextField top = new TextField(0, textBoxTop.Text, ContentAlignment.MiddleLeft);
146 iClient.SetTexts(new DataField[]
148 new DataField(0, textBoxTop.Text, Alignment),
149 new DataField(1, textBoxBottom.Text, Alignment)
153 private void buttonLayoutUpdate_Click(object sender, EventArgs e)
155 //Define a 2 by 2 layout
156 TableLayout layout = new TableLayout(2,2);
157 //Second column only takes up 25%
158 layout.Columns[1].Width = 25F;
159 //Send layout to server
160 iClient.SetLayout(layout);
163 private void buttonSetBitmap_Click(object sender, EventArgs e)
170 Bitmap bitmap = new Bitmap(x2,y2);
171 Pen blackPen = new Pen(Color.Black, 3);
173 // Draw line to screen.
174 using (var graphics = Graphics.FromImage(bitmap))
176 graphics.DrawLine(blackPen, x1, y1, x2, y2);
177 graphics.DrawLine(blackPen, x1, y2, x2, y1);
180 DataField field = new DataField(0, bitmap);
181 field.ColumnSpan = 2;
182 iClient.SetBitmap(field);
185 private void buttonBitmapLayout_Click(object sender, EventArgs e)
187 SetLayoutWithBitmap();
191 /// Define a layout with a bitmap field on the left and two lines of text on the right.
193 private void SetLayoutWithBitmap()
195 //Define a 2 by 2 layout
196 TableLayout layout = new TableLayout(2, 2);
197 //First column only takes 25%
198 layout.Columns[0].Width = 25F;
199 //Second column takes up 75%
200 layout.Columns[1].Width = 75F;
201 //Send layout to server
202 iClient.SetLayout(layout);
204 //Set a bitmap for our first field
210 Bitmap bitmap = new Bitmap(x2, y2);
211 Pen blackPen = new Pen(Color.Black, 3);
213 // Draw line to screen.
214 using (var graphics = Graphics.FromImage(bitmap))
216 graphics.DrawLine(blackPen, x1, y1, x2, y2);
217 graphics.DrawLine(blackPen, x1, y2, x2, y1);
220 //Create a bitmap field from the bitmap we just created
221 DataField field = new DataField(0, bitmap);
222 //We want our bitmap field to span across two rows
224 //Send it to our server
225 iClient.SetBitmap(field);
228 iClient.SetTexts(new DataField[]
230 new DataField(1, textBoxTop.Text, Alignment),
231 new DataField(2, textBoxBottom.Text, Alignment)