blue123
October 25, 2012, 7:52am
21
The one that isnt working is the one that I posted above. here is one that is working
using System.Threading;
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=\"ffff28\">";
xml += "<TextBlock Name=\"textBlock\" X=\"40\" Y=\"40\" Width=\"50\" Height=\"32\" Alpha=\"255\" Text=\"Login\" TextAlign=\"Right\" TextVerticalAlign=\"Middle\" Font=\"4\" FontColor=\"000000\"/>";
xml += "<TextBlock Name=\"emailTxt\" X=\"40\" Y=\"72\" Width=\"75\" Height=\"32\" Alpha=\"255\" Text=\"Email\" TextAlign=\"Right\" TextVerticalAlign=\"Middle\" Font=\"2\" FontColor=\"000000\"/>";
xml += "<TextBlock Name=\"passTxt\" X=\"40\" Y=\"109\" Width=\"75\" Height=\"32\" Alpha=\"255\" Text=\"Password\" TextAlign=\"Right\" TextVerticalAlign=\"Middle\" Font=\"2\" FontColor=\"000000\"/>";
xml += "<TextBox Name=\"emailTxt\" X=\"125\" Y=\"72\" Width=\"150\" Height=\"32\" Alpha=\"255\" Text=\"\" TextAlign=\"Left\" Font=\"2\" FontColor=\"000000\"/>";
xml += "<TextBox Name=\"passTxt\" X=\"125\" Y=\"109\" Width=\"150\" Height=\"32\" Alpha=\"255\" Text=\"\" TextAlign=\"Left\" Font=\"4\" FontColor=\"000000\"/>";
xml += "<Button Name=\"loginBtn\" X=\"125\" Y=\"160\" Width=\"150\" Height=\"32\" Alpha=\"255\" Text=\"Login\" Font=\"2\" FontColor=\"000000\" DisabledFontColor=\"808080\" TintColor=\"000000\" TintAmount=\"0\"/>";
xml += "<TextBlock Name=\"titleTxt\" X=\"0\" Y=\"0\" Width=\"320\" Height=\"32\" Alpha=\"255\" Text=\"Canvas Example\" TextAlign=\"Center\" TextVerticalAlign=\"Middle\" Font=\"4\" FontColor=\"0000FF\"/>";
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()
{
// Create a Canvas
// The Canvas object has no parameters as it's only used to issue draw commands when rendered.
Canvas canvas = new Canvas();
window.AddChild(canvas);
// Draw a separator line.
canvas.DrawLine(Colors.Blue, 1, 0, 32, window.Width, 32);
// Draw a fieldset around our "Login" text block.
TextBlock textBlock = (TextBlock)window.GetChildByName("textBlock");
canvas.DrawFieldset(textBlock, 10, 200, 150, Colors.DarkGray, 1);
}
}
}
Justin
October 25, 2012, 7:54am
22
The other one is missing some fluff at the bottom.
blue123
October 25, 2012, 7:56am
23
Ah yes sorry! here is the one that isnt working in its entirety
using System;
using System.Threading;
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.
private static Window window;
// Data Grid
static DataGrid dataGrid;
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 += "<DataGrid Name=\"dataGrid\" X=\"5\" Y=\"5\" Width=\"310\" Height=\"150\" Alpha=\"255\" Font=\"4\" RowCount=\"5\" RowHeight=\"30\" Draggable=\"True\" TappableCells=\"True\" SortableHeaders=\"True\" ShowHeaders=\"True\" ShowScrollbar=\"True\" ScrollbarWidth=\"5\" HeadersBackColor=\"707476\" HeadersFontColor=\"FFFFFF\" ItemsBackColor=\"FFFFFF\" ItemsAltBackColor=\"F4F4F4\" ItemsFontColor=\"000000\" SelectedItemBackColor=\"FFF299\" SelectedItemFontColor=\"000000\" GridColor=\"BFC5C9\" ScrollbarBackColor=\"C0C0C0\" ScrollbarScrubberColor=\"000000\"/>";
xml += "<TextBlock Name=\"textBlock1\" X=\"5\" Y=\"160\"Width=\"50\" Height=\"32\" Alpha=\"255\" Text=\"Scroll\" TextAlign=\"Right\" TextVerticalAlign=\"Middle\" Font=\"3\" FontColor=\"000000\"/>";
xml += "<TextBlock Name=\"textBlock2\" X=\"5\" Y=\"202\" Width=\"50\" Height=\"32\" Alpha=\"255\" Text=\"Select\" TextAlign=\"Right\" TextVerticalAlign=\"Middle\" Font=\"3\" FontColor=\"000000\"/>";
xml += "<TextBlock Name=\"textBlock3\" X=\"175\" Y=\"160\" Width=\"40\" Height=\"32\" Alpha=\"255\" Text=\"List\" TextAlign=\"Right\" TextVerticalAlign=\"Middle\" Font=\"3\" FontColor=\"000000\"/>";
xml += "<Button Name=\"scrollUpBtn\" X=\"60\" Y=\"160\" Width=\"45\" Height=\"32\" Alpha=\"255\" Text=\"Up\" Font=\"3\" FontColor=\"000000\" DisabledFontColor=\"808080\" TintColor=\"000000\" TintAmount=\"0\">";
xml += "<Button Name=\"scrollDownBtn\" X=\"110\" Y=\"160\" Width=\"60\" Height=\"32\" Alpha=\"255\" Text=\"Down\" Font=\"3\" FontColor=\"000000\" DisabledFontColor=\"808080\" TintColor=\"000000\" TintAmount=\"0\"/>";
xml += "<Button Name=\"selectUpBtn\" X=\"60\" Y=\"202\" Width=\"45\" Height=\"32\" Alpha=\"255\" Text=\"Up\" Font=\"3\" FontColor=\"000000\" DisabledFontColor=\"808080\" TintColor=\"000000\" TintAmount=\"0\"/>";
xml += "<Button Name=\"selectDownBtn\" X=\"110\" Y=\"202\" Width=\"60\" Height=\"32\" Alpha=\"255\" Text=\"Down\" Font=\"3\" FontColor=\"000000\" DisabledFontColor=\"808080\" TintColor=\"000000\" TintAmount=\"0\"/>";
xml += "<Button Name=\"selectClearBtn\" X=\"175\" Y=\"202\" Width=\"50\" Height=\"32\" Alpha=\"255\" Text=\"Clear\" Font=\"3\" FontColor=\"000000\" DisabledFontColor=\"808080\" TintColor=\"000000\" TintAmount=\"0\"/>";
xml += "<Button Name=\"selectDeleteBtn\" X=\"230\" Y=\"202\" Width=\"70\" Height=\"32\" Alpha=\"255\" Text=\"Delete\" Font=\"3\" FontColor=\"000000\" DisabledFontColor=\"808080\" TintColor=\"000000\" TintAmount=\"0\"/>";
xml += "<Button Name=\"clearBtn\" X=\"220\" Y=\"160\" Width=\"50\" Height=\"32\" Alpha=\"255\" Text=\"Clear\" Font=\"3\" FontColor=\"000000\" DisabledFontColor=\"808080\" TintColor=\"000000\" TintAmount=\"0\"/>";
xml += "<Button Name=\"fillBtn\" X=\"275\" Y=\"160\" Width=\"40\" Height=\"32\" Alpha=\"255\" Text=\"Fill\" Font=\"3\" 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()
{
// Setup the dataGrid reference.
dataGrid = (DataGrid)window.GetChildByName("dataGrid");
// Possible configurations...
//dataGrid.ShowHeaders = false;
//dataGrid.SortableHeaders = false;
//dataGrid.TappableCells = false;
//dataGrid.Draggable = false;
//dataGrid.ShowScrollbar = false;
//dataGrid.ScrollbarWidth = 4;
// Listen for tap cell events.
dataGrid.TapCellEvent += new OnTapCell(dataGrid_TapCellEvent);
// Create our three columns.
dataGrid.AddColumn(new DataGridColumn("ID", 50));
dataGrid.AddColumn(new DataGridColumn("First Name", 125));
dataGrid.AddColumn(new DataGridColumn("Last Name", 125));
// Populate the data grid with random data.
Populate(false);
// Add the data grid to the window before rendering it.
window.AddChild(dataGrid);
dataGrid.Render();
// Setup the button controls.
Button scrollUpBtn = (Button)window.GetChildByName("scrollUpBtn");
scrollUpBtn.TapEvent += new OnTap(scrollUpBtn_TapEvent);
Button scrollDownBtn = (Button)window.GetChildByName("scrollDownBtn");
scrollDownBtn.TapEvent += new OnTap(scrollDownBtn_TapEvent);
Button selectUpBtn = (Button)window.GetChildByName("selectUpBtn");
selectUpBtn.TapEvent += new OnTap(selectUpBtn_TapEvent);
Button selectDownBtn = (Button)window.GetChildByName("selectDownBtn");
selectDownBtn.TapEvent += new OnTap(selectDownBtn_TapEvent);
Button selectClearBtn = (Button)window.GetChildByName("selectClearBtn");
selectClearBtn.TapEvent += new OnTap(selectClearBtn_TapEvent);
Button selectDeleteBtn = (Button)window.GetChildByName("selectDeleteBtn");
selectDeleteBtn.TapEvent += new OnTap(selectDeleteBtn_TapEvent);
Button clearBtn = (Button)window.GetChildByName("clearBtn");
clearBtn.TapEvent += new OnTap(clearBtn_TapEvent);
Button fillBtn = (Button)window.GetChildByName("fillBtn");
fillBtn.TapEvent += new OnTap(fillBtn_TapEvent);
}
static void Populate(bool invalidate)
{
// Add items with random data
for (int i = 0; i < 20; i++)
{
// DataGridItems must contain an object array whose length matches the number of columns.
dataGrid.AddItem(new DataGridItem(new object[3] { i, RandomString(10), RandomString(10) }));
}
if (invalidate)
dataGrid.Invalidate();
}
static void dataGrid_TapCellEvent(object sender, TapCellEventArgs args)
{
// Get the data from the row we tapped.
object[] data = dataGrid.GetRowData(args.RowIndex);
if (data != null)
GlideUtils.Debug.Print("GetRowData[" + args.RowIndex + "] = ", data);
}
static void scrollUpBtn_TapEvent(object sender)
{
dataGrid.ScrollUp(1);
dataGrid.Invalidate();
}
static void scrollDownBtn_TapEvent(object sender)
{
dataGrid.ScrollDown(1);
dataGrid.Invalidate();
}
static void selectUpBtn_TapEvent(object sender)
{
if (dataGrid.SelectedIndex > 0)
dataGrid.SelectedIndex--;
}
static void selectDownBtn_TapEvent(object sender)
{
if (dataGrid.SelectedIndex < dataGrid.NumItems - 1)
dataGrid.SelectedIndex++;
}
static void selectClearBtn_TapEvent(object sender)
{
dataGrid.SelectedIndex = -1;
}
static void selectDeleteBtn_TapEvent(object sender)
{
dataGrid.RemoveItemAt(dataGrid.SelectedIndex);
dataGrid.Invalidate();
}
static void clearBtn_TapEvent(object sender)
{
dataGrid.Clear();
dataGrid.Invalidate();
}
static void fillBtn_TapEvent(object sender)
{
Populate(true);
}
// -------------------------------------------------------------------
// This is used to generate random strings.
private static Random random = new Random((int)DateTime.Now.Ticks);
private static string RandomString(int size)
{
string str = String.Empty;
double d;
ushort u;
char ch;
for (int i = 0; i < size; i++)
{
d = System.Math.Floor(26 * random.NextDouble() + 65);
u = Convert.ToUInt16(d.ToString());
ch = Convert.ToChar(u);
str += ch;
}
return str;
}
}
}
blue123
October 25, 2012, 8:09am
24
Maybe this will make things a bit clearer. Its from the debug output window and shows the error.
‘Microsoft.SPOT.Emulator.Sample.SampleEmulator.exe’ (Managed): Loaded ‘C:\Documents and Settings\nzcznr\My Documents\Visual Studio 2010\Projects\Data Grid Example\bin\Debug\le\Data Grid Example.exe’, Symbols loaded.
The thread ‘’ (0x2) has exited with code 0 (0x0).
#### Exception System.Xml.XmlException - CLR_E_WRONG_INTERRUPT_TYPE (1) ####
#### Message:
#### System.Xml.XmlReader::Read [IP: 00d7] ####
#### GHIElectronics.NETMF.Glide.GlideLoader::LoadWindow [IP: 00ba] ####
#### GHIElectronics.NETMF.Glide.GlideLoader::LoadWindow [IP: 000a] ####
#### Test.Program::Main [IP: 008e] ####
A first chance exception of type ‘System.Xml.XmlException’ occurred in System.Xml.dll
An unhandled exception of type ‘System.Xml.XmlException’ occurred in System.Xml.dll
The program ‘[4808] Micro Framework application: Managed’ has exited with code 0 (0x0).
Justin
October 25, 2012, 8:14am
25
It’s because your xml is duff.
First textbox your missing a space and one of your buttons is missing a closing /
Justin
October 25, 2012, 8:16am
26
xml += "<TextBlock Name=\"textBlock1\" X=\"5\" Y=\"160\"Width=\"50\"
should be
xml += "<TextBlock Name=\"textBlock1\" X=\"5\" Y=\"160\" Width=\"50\"
and
xml += "<Button Name=\"scrollUpBtn\" X=\"60\" Y=\"160\" Width=\"45\" Height=\"32\" Alpha=\"255\" Text=\"Up\" Font=\"3\" FontColor=\"000000\" DisabledFontColor=\"808080\" TintColor=\"000000\" TintAmount=\"0\">";
should be
xml += "<Button Name=\"scrollUpBtn\" X=\"60\" Y=\"160\" Width=\"45\" Height=\"32\" Alpha=\"255\" Text=\"Up\" Font=\"3\" FontColor=\"000000\" DisabledFontColor=\"808080\" TintColor=\"000000\" TintAmount=\"0\"/>";
blue123
October 25, 2012, 8:20am
27
Ahhh I see. A bit red faced. Thanks Justin!
Justin
October 25, 2012, 8:22am
28
Your welcome mate, my face is usually red as well
Thank you ruimsimao & Nubiarn, this thread saved me. I’ve been banging my head against this Check hardware error off and on for weeks, my problem appears solved and I can continue my work.