Content by Category
.NET 1.x
.NET 2.0
.NET 3.0
.NET 3.5
.NET 4.0
.NET Assemblies
.NET Framework
.NET Getting Started
Accessibility
ADO.NET
Advertorials
Agile Development
AJAX
Architecture
ASP.NET
ASP.NET MVC
ASP.NET WebForms
B2B (Business Integration)
BizTalk
Book Excerpts
Build and Deploy
C#
C++
Code Contracts
CODE on the Road!
COM+
Community
Conferences
Continuous Integration
Crystal Reports
CSLA.NET
CSS
Data
Design Patterns
Development Process
Display Technologies
Distributed Computing
DotNetNuke
DSL
Dynamic Programming
Editorials
Enterprise Services ("COM+")
Entity Framework
Events
Expression Blend
F#
Fox to Fox
Frameworks
Functional Programming
Graphics
Internet Explorer 8.0
Interviews
iPhone
Java
Java Script
jQuery
LINQ
Linux
Mac OS X
MDX
Microsoft Application Blocks
Microsoft Business Rules Framework
Microsoft Expression
Microsoft Office
Mobile Development
Mobile PC
Mono
Network
NHibernate
Object Oriented Development
Open Source
Opinion
Opinions
Oracle
ORM
Other Languages
Parallel Programming
Patterns
Podcasts
Post Mortem
PowerPoint
Print/Output
Product News
Product Reviews
Project Management
Python
Q&A
Reporting Services
REST
RIA Services
Ruby
Search
Security
Services
SharePoint
Silverlight
SOA
Social Networks
Software & Law
Software Business
Source Control
Speech-Enabled Applications
SQL Server
SQL Server 2000
SQL Server 2005
SQL Server 2008
SQL Server CE/AnyWhere/Mobile/Compact
Subversion
Sync Framework
Tablet PC
TDD
Team System
Techniques
Testing and Quality Control
Tips
UI Design
UML
User Groups
VB Script
VB.NET
VFP and .NET
VFP and SQL Server
Virtual Earth
Vista
Visual Basic
Visual Basic 6 (and older)
Visual FoxPro
Visual Studio .NET
Visual Studio 2005
Visual Studio 2008
Visual Studio 2010
Visual Studio Tools for Office
VSX
WCF
Web Development (general)
Web Services
WF
Whitepapers
Windows 7
Windows Azure
Windows Live
Windows Server
Windows Vista
WinForms
Workflow
WPF
XAML
XML
XNA
XSLT



State of .NET


 


GiveCamp - Coding for Charity


Reader rating:
Click here to read 4 comments about this article.
Article source: CoDe (2005 - Vol. 3 - Issue 1 - Tablet PC and Mobile PC)


Article Pages: < Previous - 1 2  3  4 - Next >


Ink on the Web (Cont.)

Add Format and Functionality

So, now you can draw on a Web page, but there’s not really very much that you can do with this. You only have a black pen to play with and when the page is gone, so is your Ink. Let’s add some more functionality to this Inkable page.

This is a great time to remember that the Ink-enabled control is getting downloaded to the client computer. Because of this, it is impossible to interact with the control from the Web server. Normally, you put all kinds of functionality in the code behind the Web page. But code behind is server-side code. The control is not on the server. Any interaction you need to do between the page and the control must be done in client-side code. And because client-side scripting can be extremely cumbersome, it is advantageous to build as much of the control’s functionality as you can into the control itself.

Let’s say that you wanted to allow your users to use additional pen colors, erase their Ink using the stroke erase method, and also move Ink using the lasso tool. All of this functionality will be part of the control itself. You have two ways to expose it to the end user interacting with the Web page: create public methods inside of the control that are called by the client side script and create internal functions that are completely handled by the control.

As an example of the first approach, you could have a method in the control to change the pen’s Ink color to red.

Public Sub ChangeInktoRed
  inkO.DefaultDrawingAttributes.Color=Color.Red
End Sub

On the Web page, such as in Figure 3, you may have a button to allow the user to change the pen color to red. The onclick method of the button calls a client-side function called RedInk.

Click for a larger version of this image.

Figure 3: This Web page contains an Inkable Windows Forms control with no additional user interface built in. The Web page itself contains a button whose onclick event interacts with public methods in the control.

<INPUT onclick="RedInk()" type="button"
value="Red" >

The client-side RedInk function, here written with JavaScript, calls into the control’s exposed method. Note that in the sample Web page, the control, which was given the ID of MyInkControl, is inside a <Form> tag with an ID of inkForm.

function RedInk()      
{
  inkForm.MyInkControl.ChangeInktoRed;
}

Everything here is case-sensitive-a demand that could have you scratching your head for quite some time if you haven’t met it.

If you are designing a Web page where the Web UI elements are an important part of the design, you will most likely want to use the above method. My recommendation is to do as much of the work as you can inside the control and keep the JavaScript interaction minimal. The reason for this recommendation is three-fold.

The first is that if you have problems with the control, you could easily drop the control into a Windows Form to debug it. It will be more useful if the functionality you need to test and debug is in the control.

The second reason is that client-side coding is cumbersome and difficult to debug.

The third is that any end user can see your client-side code. You can hide your intellectual property if you have it compiled into your dll. There are fewer people who know how to find the dll and how to get at the code that is inside.

The other way to enable users to interact with your control is to build additional UI elements directly into the control. The button for turning the pen color to red can be part of the control itself. Rather than having a public method to change the Ink color, this can be a private method or part of an event handler.

Remember that the current example control has its entire surface Ink enabled. If you would like to have additional controls, you also want to have a defined area, such as a panel control or a picture control, that has the Ink overlay attached to it.

Let’s go back to the custom control and make some changes. Drop two panel controls onto the control changing the dock parameter of the first to top and of the second to fill. Figure 2 shows what the control should look like with the panels. Drop a button onto the top panel and then resize it to 24 x 24. Next, change the background color to red. This will be an obvious visual element for users. I didn’t use a toolbar because you cannot affect the background color of the toolbar buttons. In the Load method, modify the InkOverlay instantiation to attach the InkOverlay to the panel.

Click for a larger version of this image.

Figure 2: This control in Design view shows a panel (Panel 1) that is docked to the top of the control and a panel (Panel 2) with its Dock property set to fill.

Private Sub MyInkControl_Load _

(ByVal sender As Object, ByVal e As _
System.EventArgs) Handles MyBase.Load
  inkO = New Microsoft.Ink.InkOverlay(InkPanel)
  inkO.Enabled = True
End Sub

Now add a click handler to the red button and move the line of code that changes the Ink color into this method.

Private Sub RedPen_Click(ByVal sender As _
System.Object, ByVal e As System.EventArgs) _
Handles RedPen.Click
  inkO.DefaultDrawingAttributes.Color = Color.Red
End Sub

This is a simple take on this method. A more realistic control might have a variety of colored buttons to choose from and possibly one event handler written to accommodate changing all of the colors. This is no different than you would do for any other Tablet PC application that you write for a Windows application, and there are many examples of this type of coding elsewhere in this issue.

Figure 4 shows the inkable Web page in action. Note that I put borders around the two panels so that I can see where my inkable region is on the Web page.

Click for a larger version of this image.

Figure 4: This red button that lets the user select red Ink is part of the Windows Form control. The control is entirely responsible for the functionality, which means that nothing extra is required in the Web page.

To test out how this works, rebuild the control and then re-add the resulting dll to the Web application. You don’t have to do anything to the Web page because the Ink functionality is completely contained in the control.

&


Moving Ink Around

There are many ways to move Ink around on the Web. You need to consider postbacks, and sending inkdata to another page, to a database, to a Web service, or just saving it as an image. See “Persisting Ink on the Web” on the Mobile Developer Center at http://msdn.microsoft.com/tabletpc.



Article Pages: < Previous - 1 2  3  4 - Next Page: 'Saving the Ink' >>

Page 1: Ink on the Web
Page 2: Why a Custom Control?
Page 3: Add Format and Functionality
Page 4: Saving the Ink

How would you rate the quality of this article?
1 2 3 4 5
Poor      Outstanding

Tell us why you rated the content this way. (optional)

Average rating:
3.6 out of 5

25 people have rated this article.

      CODE TRAINING

 

QCon London