Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

help with .net micro framework code!!!

3 views
Skip to first unread message

Anthony

unread,
Dec 14, 2009, 6:36:01 PM12/14/09
to
Hi,
I am currently working on a project that has to do with drawing graphs using
.net micro framework on a Tahoe board. Basically I've been able to draw a
line on the display, but now I'm trying to move the line Up or Down using the
up/down switch on the emulator. I've pasted the code below, and may I add
that I'm a newbie to .net micro framework.
Concept
I decided to create a variable "a" in the class "borderpanel". So what I
want to do is to increase/decrease this variable "a" by "50" every time the
Up/Down switch is pressed, but the code I have isn't doing that. I can only
get the line to show but no movements when the up/down button is pressed.

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;
}

}

}

}

Jan Kučera

unread,
Dec 15, 2009, 5:24:10 AM12/15/09
to
Hi Anthony, without checking the rest of your code, how should the WPF
engine detect that the value of "a" has changed, and, that it means it
should re-render?

Try calling Invalidate(); after changing the a value.

Jan

"Anthony" <Ant...@discussions.microsoft.com> wrote in message
news:AFC916F6-C4A4-40A1...@microsoft.com...

Anthony

unread,
Dec 15, 2009, 7:08:01 AM12/15/09
to
thanks for the reply Jan. I did as you said, calling invalidate after
changing variable "a", but it still doesn't change. Can you PLEASE check the
code, to know where this might be coming from. I have edited the code so that
it can be easier to understand (I hope).

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;
}

}
}

}

Jens Kühner

unread,
Dec 15, 2009, 8:50:34 AM12/15/09
to
Hi Anthony,

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...

Anthony

unread,
Dec 15, 2009, 11:19:02 AM12/15/09
to
Thanks alot Jens, I just set the button focus to the panel and it worked. Now
I need to know, suppose there were two panels, is it possible to switch the
button focus between both panels?


regards,
Anthony.


Jan Kučera

unread,
Dec 15, 2009, 3:30:36 PM12/15/09
to
Sure, you can call Buttons.Focus every time you need to change it.

Jan

"Anthony" <Ant...@discussions.microsoft.com> wrote in message

news:F57AB6A4-2839-4A3D...@microsoft.com...

0 new messages