PLEASE URGENT HELP NEEDED!!!!
using System;
using System.Collections;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Input;
using Microsoft.SPOT.Hardware;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Shapes;
namespace Tahoe_App
{
public class Program : Microsoft.SPOT.Application
{
public static void Main()
{
Program myApplication = new Program();
Window mainWindow = myApplication.CreateWindow();
// Create the object that configures the GPIO pins to buttons.
GPIOButtonInputProvider inputProvider = new
GPIOButtonInputProvider(null);
// Start the application
myApplication.Run(mainWindow);
}
/// <summary>
///
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// </summary>
private Window mainWindow;
public Window CreateWindow()
{
// Create a window object and set its size to the
// size of the display.
mainWindow = new Window();
mainWindow.Height = SystemMetrics.ScreenHeight;
mainWindow.Width = SystemMetrics.ScreenWidth;
// create main stack panel
StackPanel stack = new StackPanel(Orientation.Vertical);
// Create stack panels for the current temperature and target
temperature
StackPanel stack1 = new StackPanel(Orientation.Vertical);
// Create border panels for the current temperature and target
temperature
BorderPanel panel1;
panel1 = new BorderPanel(SystemMetrics.ScreenWidth,
(int)(SystemMetrics.ScreenHeight));
// Add the border panels to the panels containing the current
temperature and target temperature
panel1.Children.Add(stack1);
// Add the stack panels to the border panels
stack.Children.Add(panel1);
mainWindow.Child = stack;
// Connect the button handler to all of the buttons.
//mainWindow.AddHandler(Buttons.ButtonUpEvent, new
ButtonEventHandler(OnButtonUp), false);
// Set the window visibility to visible.
mainWindow.Visibility = Visibility.Visible;
// Attach the button focus to the window.
Buttons.Focus(mainWindow);
return mainWindow;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/* private void OnButtonUp(object sender, ButtonEventArgs e)
{
// Print the button code to the Visual Studio output window.
Debug.Print(e.Button.ToString());
}*/
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
}
/// <summary>
///
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// </summary>
internal sealed class BorderPanel: Panel
{
// Private members for width and height so they can be set manually.
private int _width;
private int _height;
private int a = 0;// adds an integer to shift the line up or down
// Special constructor that takes a width and a height
public BorderPanel(int width, int height)
{
// Set the width and height
_width = width;
_height = height;
}
// Override the MeasureOverride to tell the GUI it should not set
the width and height
// according to the controls contained inside this object. That is
the default
// behavior. Set a width and height such that when the border is
drawn,
// it is uniform and of a specific size.
protected override void MeasureOverride(int availableWidth, int
availableHeight, out int desiredWidth, out int desiredHeight)
{
// By setting the desiredWidth and desiredHeight parameters, the
GUI uses these
// values instead of ones it would have calculated based on what
controls
// are contained in this object.
desiredWidth = _width;
desiredHeight = _height;
}
// Override OnRender to handle drawing.
public override void OnRender(DrawingContext dc)
{
// Call the base class
base.OnRender(dc);
Pen redpen = new Pen((Color)0x0000ff, 1);
dc.DrawLine(redpen, 0, a+100, 240, a+100);//draws the Line
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
}
// used to add 50 to variable a so the line goes up/down depending
on whats pressed
protected override void OnButtonDown(ButtonEventArgs e)
{
switch (e.Button)
{
case Button.VK_UP:
{
a += 50;
}
break;
case Button.VK_DOWN:
{
a -= 50;
}
break;
}
}
}
}
Try calling Invalidate(); after changing the a value.
Jan
"Anthony" <Ant...@discussions.microsoft.com> wrote in message
news:AFC916F6-C4A4-40A1...@microsoft.com...
Anthony.
using System;
using System.Collections;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Input;
using Microsoft.SPOT.Hardware;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Shapes;
namespace Tahoe_App
{
public class Program : Microsoft.SPOT.Application
{
public static void Main()
{
Program myApplication = new Program();
Window mainWindow = myApplication.CreateWindow();
// Create the object that configures the GPIO pins to buttons.
GPIOButtonInputProvider inputProvider = new
GPIOButtonInputProvider(null);
// Start the application
myApplication.Run(mainWindow);
}
/// <summary>
///
////////////////////////////////////////////////////////////////////////////////////////////////////
private Window mainWindow;
public Window CreateWindow()
{
// Create a window object and set its size to the
// size of the display.
mainWindow = new Window();
mainWindow.Height = SystemMetrics.ScreenHeight;
mainWindow.Width = SystemMetrics.ScreenWidth;
// create main stack panel
StackPanel stack = new StackPanel(Orientation.Vertical);
StackPanel stack1 = new StackPanel(Orientation.Vertical);
BorderPanel panel1;
panel1 = new BorderPanel(SystemMetrics.ScreenWidth,
(int)(SystemMetrics.ScreenHeight));
panel1.Children.Add(stack1);
// Add the stack panels to the border panels
stack.Children.Add(panel1);
mainWindow.Child = stack;
// Connect the button handler to all of the buttons.
mainWindow.AddHandler(Buttons.ButtonUpEvent, new
ButtonEventHandler(OnButtonUp), false);
// Set the window visibility to visible.
mainWindow.Visibility = Visibility.Visible;
// Attach the button focus to the window.
Buttons.Focus(mainWindow);
return mainWindow;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
private void OnButtonUp(object sender, ButtonEventArgs e)
{
// Print the button code to the Visual Studio output window.
Debug.Print(e.Button.ToString());
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
}
/// <summary>
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////
/// </summary>
internal sealed class BorderPanel: Panel
{
// Private members for width and height so they can be set manually.
private int _width;
private int _height;
private int a = 0;// adds an integer to shift the line up or down
// Special constructor that takes a width and a height
public BorderPanel(int width, int height)
{
// Set the width and height
_width = width;
_height = height;
}
// Override the MeasureOverride to tell the GUI it should not set
the width //and height
// according to the controls contained inside this object. That is
the default
// behavior. Set a width and height such that when the border is
drawn,
// it is uniform and of a specific size.
protected override void MeasureOverride(int availableWidth, int
availableHeight, out int desiredWidth, out int desiredHeight)
{
// By setting the desiredWidth and desiredHeight parameters, the
GUI //uses these
// values instead of ones it would have calculated based on what
controls
// are contained in this object.
desiredWidth = _width;
desiredHeight = _height;
}
// Override OnRender to handle drawing.
public override void OnRender(DrawingContext dc)
{
// Call the base class
base.OnRender(dc);
Pen redpen = new Pen((Color)0x0000ff, 1);
dc.DrawLine(redpen, 0, a+100, 240, a+100);//draws the Line
///////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
}
// used to add 50 to variable a so the line goes up/down depending
on //whats pressed
protected override void OnButtonDown(ButtonEventArgs e)
{
switch (e.Button)
{
case Button.VK_UP:
{
a += 50;
Invalidate();
}
break;
case Button.VK_DOWN:
{
a -= 50;
Invalidate();
}
break;
}
}
}
}
the OnButtonDown method of the panel will never be called, becuase the panel
does not have the button input focus.
Just set the focus to the panel instead of the main window in the
CreateWindowMethod. (caution: Only visible elements can get the focus. If
you set the focus and it is ignored, please check if the element and all its
parents are visible).
best
Jens
########################################################################
Jens Kühner author of "Expert .NET Micro Framework" second edition 2009 book
at Apress
Innobedded Rich Media Extension for the .NET Micro Framework
(www.innobedded.com)
########################################################################
"Anthony" <Ant...@discussions.microsoft.com> schrieb im Newsbeitrag
news:B51991C0-83BB-457A...@microsoft.com...
regards,
Anthony.
Jan
"Anthony" <Ant...@discussions.microsoft.com> wrote in message
news:F57AB6A4-2839-4A3D...@microsoft.com...