Setting Ink Overlay Properties in Tablet PC


In this article, I will write an application that allows us to set the Ink Overlay properties dynamically based on the values selected by the user. The application looks like the following figure, where user can enter width and height of the overlay and select a color by clicking the Select Pen Color button. The Apply button applies the settings to the overlay.



If you don't want to download the attached project, you need to create a Windows Forms application and add reference to Microsoft Tablet PC API. See steps in
My First Tablet PC application.

Now define the following private variables.

private Color selectedColor = System.Drawing.Color.Blue;
private InkOverlay inkOverlay = null;

The Select Pen Color button code looks like following:

private void PenColorBtn_Click(object sender, System.EventArgs e)
{
ColorDialog colorDlg = new ColorDialog();
if( colorDlg.ShowDialog() == DialogResult.OK)
selectedColor = colorDlg.Color;
}

The Apply button click code looks like the following:

private void ApplyBtn_Click(object sender, System.EventArgs e)
{
// Make sure to dispose the existing InkOverlay
// object before creating a new one
if(inkOverlay != null)
{
inkOverlay.Dispose();
inkOverlay = null;
}
// Create DrawingAttributes with the width, height, and color
DrawingAttributes attributes = new DrawingAttributes();
attributes.Height = Convert.ToInt32(textBox1.Text);
attributes.Width = Convert.ToInt32(textBox2.Text);
attributes.Color = selectedColor;
RefreshView(attributes);
}

RefreshView method

private void RefreshView(DrawingAttributes da)
{
// Create new InkOverlay object
inkOverlay = new InkOverlay();
// Set DefaultDrawingAttributes
inkOverlay.DefaultDrawingAttributes = da;
// Tell the surface is the form
inkOverlay.Handle = this.Handle;
// Enable overlay
inkOverlay.Enabled = true;
}

Other Properties

DrawingAttributes object provides few more useful properties. You can use AntiAliased property to anti-aliasing of the ink and PenTip property to change the tip of the pen.

The Transparency property allows you to set the transparency of the ink.

attributes.Transparency = 120;

Download source code for more details.

Up Next
    Ebook Download
    View all
    Learn
    View all