Hi!
Can you help me produce a text when a read button is clicked? Here is my code. Hope you could help me with this.
using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Input;
using GHIElectronics.NETMF.Glide;
using GHIElectronics.NETMF.Glide.Display;
using GHIElectronics.NETMF.Glide.UI;
namespace Test
{
public class Program
{
// This will hold the main window.
static Window window;
public static void Main()
{
// Load the window
string xml;
xml = "<Glide Version=\"" + Glide.Version + "\">";
xml += "<Window Name=\"window\" Width=\"320\" Height=\"240\" BackColor=\"dce3e7\">";
xml += "<Button Name=\"btn\" X=\"4\" Y=\"202\" Width=\"80\" Height=\"32\" Alpha=\"255\" Text=\"Read\" Font=\"4\" FontColor=\"000000\" DisabledFontColor=\"808080\" TintColor=\"000000\" TintAmount=\"0\"/>";
xml += "<Button Name=\"stopbtn\" X=\"236\" Y=\"202\" Width=\"80\" Height=\"32\" Alpha=\"255\" Text=\"Stop\" Font=\"4\" FontColor=\"000000\" DisabledFontColor=\"808080\" TintColor=\"000000\" TintAmount=\"0\"/>";
xml += "<TextBlock Name=\"Frequency\" X=\"10\" Y=\"102\" Width=\"100\" Height=\"32\" Alpha=\"255\" Text=\"Frequency:\" TextAlign=\"Left\" TextVerticalAlign=\"Top\" Font=\"4\" FontColor=\"0\" BackColor=\"000000\" ShowBackColor=\"False\"/>";
xml += "<TextBlock Name=\"EPC\" X=\"10\" Y=\"73\" Width=\"100\" Height=\"32\" Alpha=\"255\" Text=\"EPC:\" TextAlign=\"Left\" TextVerticalAlign=\"Top\" Font=\"4\" FontColor=\"0\" BackColor=\"000000\" ShowBackColor=\"False\"/>";
xml += "<TextBlock Name=\"RSSI\" X=\"10\" Y=\"130\" Width=\"100\" Height=\"32\" Alpha=\"255\" Text=\"RSSI:\" TextAlign=\"Left\" TextVerticalAlign=\"Top\" Font=\"4\" FontColor=\"0\" BackColor=\"000000\" ShowBackColor=\"False\"/>";
xml += "<TextBlock Name=\"Phase\" X=\"9\" Y=\"158\" Width=\"100\" Height=\"32\" Alpha=\"255\" Text=\"Phase:\" TextAlign=\"Left\" TextVerticalAlign=\"Top\" Font=\"4\" FontColor=\"0\" BackColor=\"000000\" ShowBackColor=\"False\"/>";
xml += "<TextBlock Name=\"text1\" X=\"105\" Y=\"71\" Width=\"200\" Height=\"32\" Alpha=\"255\" Text=\" \" TextAlign=\"Left\" TextVerticalAlign=\"Top\" Font=\"4\" FontColor=\"0\" BackColor=\"000000\" ShowBackColor=\"False\"/>";
xml += "<TextBox Name=\"text2\" X=\"107\" Y=\"103\" Width=\"100\" Height=\"32\" Alpha=\"255\" Text=\"\" TextAlign=\"Left\" TextVerticalAlign=\"Top\" Font=\"4\" FontColor=\"0\" BackColor=\"000000\" ShowBackColor=\"False\"/>";
xml += "<TextBox Name=\"text3\" X=\"106\" Y=\"130\" Width=\"100\" Height=\"32\" Alpha=\"255\" Text=\"\" TextAlign=\"Left\" TextVerticalAlign=\"Top\" Font=\"4\" FontColor=\"0\" BackColor=\"000000\" ShowBackColor=\"False\"/>";
xml += "<TextBox Name=\"text4\" X=\"106\" Y=\"157\" Width=\"100\" Height=\"32\" Alpha=\"255\" Text=\"\" TextAlign=\"Left\" TextVerticalAlign=\"Top\" Font=\"4\" FontColor=\"0\" BackColor=\"000000\" ShowBackColor=\"False\"/>";
xml += "<TextBlock Name=\"tagsdet\" X=\"89\" Y=\"203\" Width=\"100\" Height=\"32\" Alpha=\"255\" Text=\"Tags Detected:\" TextAlign=\"Left\" TextVerticalAlign=\"Top\" Font=\"0\" FontColor=\"0\" BackColor=\"000000\" ShowBackColor=\"False\"/>";
xml += "<TextBox Name=\"text5\" X=\"199\" Y=\"200\" Width=\"35\" Height=\"32\" Alpha=\"255\" Text=\"\" TextAlign=\"Left\" TextVerticalAlign=\"Top\" Font=\"0\" FontColor=\"0\" BackColor=\"000000\" ShowBackColor=\"False\"/>";
xml += "<Image Name=\"img1\" X=\"2\" Y=\"6\" Width=\"317\" Height=\"35\" Alpha=\"255\"/>";
// xml += "<Button Name=\"btn\" X=\"100\" Y=\"104\" Width=\"120\" Height=\"32\" Alpha=\"255\" Text=\"Read\" Font=\"4\" FontColor=\"000000\" DisabledFontColor=\"808080\" TintColor=\"000000\" TintAmount=\"0\"/>";
xml += "</Window>";
xml += "</Glide>";
// Resize any loaded Window to the LCD's size.
Glide.FitToScreen = true;
// Load the Window XML string.
window = GlideLoader.LoadWindow(xml);
// Activate touch
GlideTouch.Initialize();
// Initialize the window.
InitWin();
// Assigning a window to MainWindow flushes it to the screen.
// This also starts event handling on the window.
Glide.MainWindow = window;
Thread.Sleep(-1);
}
static void InitWin()
{
TextBlock freq = (TextBlock)window.GetChildByName("Frequency");
TextBlock epc = (TextBlock)window.GetChildByName("EPC");
TextBlock rssi = (TextBlock)window.GetChildByName("RSSI");
TextBlock phase = (TextBlock)window.GetChildByName("Phase");
TextBlock tagsdet = (TextBlock)window.GetChildByName("tagsdet");
// Get the Button
Button btn = (Button)window.GetChildByName("btn");
Button stopbtn = (Button)window.GetChildByName("stopbtn");
// Listen for tap events
btn.TapEvent += new OnTap(btn_TapEvent);
}
// Handle tap events
static void btn_TapEvent(object sender)
{
TextBlock text1 = (TextBlock)window.GetChildByName("text1");
text1.Text = "30003hjlasdjf";
Thread.Sleep(1000);
TextBox text2 = (TextBox)window.GetChildByName("text2");
TextBox text3 = (TextBox)window.GetChildByName("text3");
TextBox text4 = (TextBox)window.GetChildByName("text4");
TextBox text5 = (TextBox)window.GetChildByName("text5");
Thread.Sleep(1);
}
}
}
Apparently, the “sample text (text1.Text)” doesn’t appear if i click the button. what should I do? Also, I would like to ask for the difference of TextBlock and TextBox. Thank you again!