Drawing border around a TextBox

I am trying to draw a TextBox with a border around it. The DrawFieldSet method of the Canvas class seems to be what I should use.

It is almost working… The border that is drawn does not properly enclose the TextBox. It is shifted down, and the top of the border is only partially drawn.

I suspect I might be missing something with the proper parameters for the DrawFieldSet method.

Below is the code I am using:

using System;
using Microsoft.SPOT;
using System.Threading;
using GHIElectronics.NETMF.Glide;
using GHIElectronics.NETMF.Glide.Display;
using GHIElectronics.NETMF.Glide.UI;

using GHIElectronics.NETMF.Hardware;

namespace SpiderTests
{
    public class Program
    {
        private static Window window = null;
        public static void Main()
        {
            window = new Window("main", 320, 240);
            window.BackColor = Colors.White;

            TextBlock tb = new TextBlock("tb1", 255, 50, 50, 50, 24);
            tb.Font = FontManager.GetFont(FontManager.FontType.droid_reg10);
            tb.TextAlign = HorizontalAlignment.Center;
            tb.TextVerticalAlign = VerticalAlignment.Middle;
            tb.Text = "Test";
            window.AddChild(tb);
            Canvas canvas = new Canvas();
            window.AddChild(canvas);
            canvas.DrawFieldset(tb, 2, 2, 28, Microsoft.SPOT.Presentation.Media.Color.Black, 1);
            Glide.MainWindow = window;
            Thread.Sleep(Timeout.Infinite);
        }

    }
}

DrawFieldSet looks exactly like the HTML fieldset tag.
http://www.webstandards.org/files/accessible-forms/fieldset.gif.pagespeed.ce.5gm2HKTIKo.gif

I ran your code and it looks right. Try running the canvas example to get the full idea. If you want a border around the TextBlock, then you’ll need to use DrawRectangle and figure the coordinates yourself.

Thanks Josh.

I now understand. It sort of creates a GroupBox.