Setting Ink Overlay Properties in Tablet PC in VB.NET
In this article, I will write an application that allows us to set the Ink Overlay properties such as height, width, and color of the ink dynamically based on the values selected by the user.
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.
Now define the following private variables:
Private selectedColor As Color = System.Drawing.Color.Blue
Private inkOverlay As InkOverlay = Nothing
The Select Pen Color button code looks like following:
Private Sub PenColorBtn_Click(sender As Object, e As System.EventArgs)
Dim colorDlg As New ColorDialog()
If colorDlg.ShowDialog() = DialogResult.OK Then
selectedColor = colorDlg.Color
End Sub 'PenColorBtn_Click
The Apply button click code looks like the following:
Private Sub ApplyBtn_Click(sender As Object, e As System.EventArgs)
' Make sure to dispose the existing InkOverlay
' object before creating a new one
If Not (inkOverlay Is Nothing) Then
inkOverlay = Nothing
' Create DrawingAttributes with the width, height, and color
Dim attributes As New DrawingAttributes()
attributes.Height = Convert.ToInt32(textBox1.Text)
attributes.Width = Convert.ToInt32(textBox2.Text)
attributes.Color = selectedColor
End Sub 'ApplyBtn_Click
Private Sub RefreshView(da As DrawingAttributes)
' Create new InkOverlay object
inkOverlay = New InkOverlay()
' Set DefaultDrawingAttributes
inkOverlay.DefaultDrawingAttributes = da
' Tell the surface is the form
inkOverlay.Handle = Me.Handle
' Enable overlay
inkOverlay.Enabled = True
End Sub 'RefreshView
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.