Getting Started with .NET Gadgeteer by Simon Monk

Getting Started with .NET Gadgeteer by Simon Monk

Author:Simon Monk [Simon Monk]
Language: eng
Format: epub, pdf
Tags: COMPUTERS / Hardware / General
ISBN: 9781449328221
Publisher: Make
Published: 2012-05-06T16:00:00+00:00


Note

These numbers are not truly random, they are actually in a sequence and are an example of pseudorandom numbers. If you are interested, you can find more information on pseudorandom number generation here: http://en.wikipedia.org/wiki/Pseudorandom_number_generator.

Figure 3-3 shows the structure of the screen. You can see how the background, label, and two Rectangles make up the items to be displayed.

Figure 3-3. Screen Objects

The SetupUI method, which creates this structure, is quite similar to that of the previous project:

void SetupUI() { // initialize window mainWindow = display.WPFWindow; // setup the layout layout = new Canvas(); Border background = new Border(); background.Background = new SolidColorBrush(Colors.Black); background.Height = 240; background.Width = 320; layout.Children.Add(background); Canvas.SetLeft(background, 0); Canvas.SetTop(background, 0); //add the tongue tongue = new Rectangle(tongueWidth, 40); tongue.Fill = new SolidColorBrush(Colors.Red); layout.Children.Add(tongue); //add the snowflake snowflake = new Rectangle(10, 10); snowflake.Fill = new SolidColorBrush(Colors.White); layout.Children.Add(snowflake); // add the text area label = new Text(); label.Height = 240; label.Width = 320; label.ForeColor = Colors.White; label.Font = Resources.GetFont(Resources.FontResources.NinaB); layout.Children.Add(label); Canvas.SetLeft(label, 0); Canvas.SetTop(label, 0); mainWindow.Child = layout; }

One difference between this and the previous project is that here, all parts of the display remain visible all of the time. There is no showing and hiding of controls.

SetupUI is called from the ProgramStarted method:

void ProgramStarted() { SetupUI(); Canvas.SetLeft(tongue, tongueLeftPosition); Canvas.SetTop(tongue, 200); Canvas.SetLeft(snowflake, snowflakeLeftPosition); Canvas.SetTop(snowflake, snowflakeTopPosition); joystickTimer.Tick += new GT.Timer.TickEventHandler(JoystickTimer_Tick); joystickTimer.Start(); snowFlakeTimer.Tick += new GT.Timer.TickEventHandler(SnowflakeTimer_Tick); snowFlakeTimer.Start(); }

The ProgramStarted then sets the positions of the tongue and snowflake rectangles on the layout Canvas using the methods SetLeft and SetTop. Later, we will use these same methods to change the positions of the tongue and snowflake. They will automatically handle any redrawing required, so we do not need to worry about erasing them from their old position before allowing them to be redrawn at their new one.

Finally, ProgramStarted creates the two timers and starts them.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.