The rising success of Twitter has meant that it has supplanted SMS and email in many areas of business.

Now you can add a simple plug-in to each and everyone of your web pages to enable your potential clients to send you a tweet.

infotweet

There are two ways to use the plug-in: as a hyperlink to another page or as an embedded element in an “iframe” in your existing web pages. Both methods are very similar but in some cases you may not be allowed to use an iframe; like in WordPress; which is why I’m using a picture rather than the real thing.

The HTML for the iframe is:

<iframe src=”http://www.infonote.com/infonote_tweet.html?p=yourTwitterID&m=your+default+message” height=200px width= 500px scrolling=”no” frameborder=”0″> </iframe>

Notes:

yourTwitterID should not include the “@”

your+default+message should have spaces replaced with “+” signs. Also, if you use any characters such as quotes these need to be “escaped”.

An example of the embedded version can be found on our contact page.

If you want to use the hyperlink method then link to:

http://www.infonote.com/infonote_tweet.html?p=yourTwitterID&m=your+default+message

The software is free to use and contains very little infonote branding. As always, if you like our software we would like you to consider us for all your software requirements. Either that or come and buy us some beer. Please leave a comment via Twitter.

I’ve just spent a few days longer than I expected writing what I consider to be a “toy” application TweepBlog. We use such applications to learn about new technology, test out a theory and to promote our company.

Background

I was recently asked, by Microsoft, if I would like to join their Community Council but it came with two catches: One, I had to have a blog and two, I had to succumb to the clutches of twitter.

Blogging has been surprisingly good fun and I was lucky enough to get a few pointers from Eileen Brown while she was still working for Microsoft.

Twitter, on the other hand, has been a love/hate relationship; I love the potential but I’m struggling to grasp it’s true potential.

One of the things I think Twitter is great for is making announcements (products, events etc).So…. I had the idea to combine Twitter with a blog page and began programming.

Why Silverlight and FckEditor

I chose Silverlight because it’s the direction we, as a company, have decided to concentrate our efforts on for most new products. It allows us to use Dot Net in either VB or C# and allows us to do almost everything we need for commercial applications. We’re currently developing an Asset management application in SQL and Silverlight which is currently available for alpha testing (if anyone would like to try it).

I chose FckEditor because I couldn’t find a similar component in Silverlight. The available Silverlight components were expensive and I couldn’t see why I should use them when FckEditor is such a great tool.

FckEditor also allows you to have image links to picture stored anywhere on the internet.

Implementation

The application is so simple to look at it’s got the FckEditor component, a few textboxes and a button. So why did it take so long to get working?

It’s normal to place the FckEditor component inside a DIV and in JavaScript access the XHTML using something like:

function GetContents()
{
    // Get the editor instance that we want to interact with.
    var oEditor = FCKeditorAPI.GetInstance(‘FCKeditor1′) ;
    // Get the editor contents in XHTML.
    alert( oEditor.GetXHTML( true ) ) ;        // “true” means you want it formatted.
}

But adding an extra DIV to the TestPage.html and using the recommended method didn’t work. So instead of using a DIV I created a new HTML page and put this in TestPage.html inside an IFRAME.

FckEditor worked beautifully but then I had the problem of how to access the XHTML from Silverlight.

I created a javascript function on the TestPage.html to do a cross frame function call passing the XHMTL into a Textbox on the parent widow (but not visible) on Textpage.html:

HtmlPage.Window.Invoke(“GetContents”) ‘ GetContents is the javascript cross frame func

All i had to do then was was to get the Textbox value using VB in Silverlight:

textElement = HtmlPage.Document.GetElementById(“Text1″)
HTMLString = textElement .GetAttribute(“value”)

It worked! I could now use FckEditor to create pages and have them linked to twitter. That is, until I tried it in Firefox, Nothing worked. (browser compatibility !!!!)

I wont bore you with the hoops and loops I had to go to to identify the Firefox issue but it’s all down to cross frame security. The solution, in Silverlight, is so simple and it’s to use the HTML bridge.

Silverlight HTML bridge

There are lots of references on how to use the HTML bridge so I’ll stick to the code.

The Silverlight button click event calls a JavaScript function on Testpage.html:

function GetContents() {

    parent.frames[0].GetContents();
    }

that calls another function in the Iframe page:

function GetContents()
{
    // Get the editor instance that we want to interact with.
    var oEditor = FCKeditorAPI.GetInstance(‘FCKeditor1′) ;
    // Get the editor contents in XHTML.
    parent.control.Content.Page.Update(oEditor.GetXHTML( true ));
}

The “parent.control.Content.Page.Update” is the HTML bridge call back to Silverlight.

 

Imports System.Windows.Browser

 

Partial Public Class Page
    Inherits UserControl

    Public Sub New()
        InitializeComponent()
        HtmlPage.RegisterScriptableObject(“Page”, Me) ‘ register the page for the bridge

    End Sub

    <ScriptableMember()> Public Sub Update(ByVal result As String)
        HTMLString = result
    End Sub

HTMLString is a VB variable and “Update” is the routine we will call from the IFRAME in the JavaScript function above.

And finally we need to add the Iframe to our TestPage.html

    <div id=’errorLocation’ style=”font-size: small;color: Gray;”></div>
<iframe id=”ieditor” src=”./fckeditor.htm” height=”600″ width=”100%”
        frameborder=”0″></iframe>

then add:

<param name=”onLoad” value=”plugInLoaded”/>

and the javascript function to the main TestPage.html

function plugInLoaded(sender, args) {
    control = sender.getHost();
   }

Conclusion

using the HTML bridge in Silverlight was the simplest method I could find to overcome the cross frame security issues with Firefox.
 
I’m sure I could have written the application all in HTML and JavaScript but then I wouldn’t have extended my knowledge.
 
If you would like more help or information then drop me an email, a comment or a Tweep @infonotePete

I was recently asked how to decode the signature from the Hex strings in my previous post “Signature Capture for Windows Mobile”, so here goes.

Add another Picturebox to the same form of the same size as the “Please Sign here” and call it PictureBox2.

The output of the captured signature is a Hex string stored in the variable “Drawlines”; this is effectively a comma delimited series of xy pixel coordinates.

The following code takes the xy Hex coordinates and draws the pixels:

Dim lines() = DrawLines.Split(“,”)
Dim xBit As Bitmap
Dim g As Graphics
Dim myPen As Pen = New Pen(Color.Black, 2)
xBit = PictureBox2.Image

Dim cl As Color = Color.Black

g = Graphics.FromImage(xBit)

For Each line In lines
    If line <> “” Then
        sX = Integer.Parse(Mid(line, 1, 2), Globalization.NumberStyles.HexNumber)
        sY = Integer.Parse(Mid(line, 3, 2), Globalization.NumberStyles.HexNumber)
        For i = 5 To line.Length – 3 Step 4
            eX = Integer.Parse(Mid(line, i, 2), Globalization.NumberStyles.HexNumber)
            eY = Integer.Parse(Mid(line, i + 2, 2), Globalization.NumberStyles.HexNumber)
            g.DrawLine(myPen, sX, sY, eX, eY)
            sX = eX
            sY = eY
        Next
    End If

Next
PictureBox2.Image = xBit

I’ve used a Picturebox simply because it’s easy to see the resulting signature but it’s more likely you will use a bitmap and create a jpeg or png and save the result as an image.

Now all is needed is some method of transmitting the signature from the mobile device to a server.

My colleague  Neil wrote a Twitter application that integrates Twitter to Microsoft maps using the latest Silverlight control. Try it here http://tweepware.infonote.com

I’ve just made use of his software library that acts as a wrapper for the Twitter api and I thought I would share how easy it is to post to Twitter.

       Dim infoClient As New Infonote.Twitter.TwitterClient
        infoClient.Username = “infonotePete”
        infoClient.Password = “************”
        infoClient.PostUpdate(TextBox1.Text)

I think to be able to post to Twitter in just 4 lines of code is cool.

Over the past few years we have developed Windows Mobile applications that require a a signature to be recorded; either for a collection, a delivery or to indicate a customer is satisfied with a job.

There are several examples on how to do this in C# or Visual Basic but we’ve never been happy with the form of the data that gets sent back to the server. One of my colleagues had a requirement for a windows mobile application that recorded a signature and the signature was then viewable in a Silverlight application; this is how we did it.

This first post is only about the signature capture and the methods to convert a signature into a simple ascii string ready to be sent via a HTTP Post.

sign here

First we start by creating a new project and adding a picturebox to the main form.  The “please sign here” image is then inserted into the picturebox as the default image.

To allow drawing on the picturebox (so we can make a signature) we only need to trap three events: MouseDown, MouseMove and MouseUp.

If we look at the following code:

Public Class Form1
    Dim lastx As Int16
    Dim lasty As Int16
    Dim bit As Bitmap
    Dim mdown As Boolean

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    bit = PictureBox1.Image

End Sub

Private Sub PictureBox1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown 
    mdown = True ‘ global boolean
End Sub

Private Sub PictureBox1_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
    Dim g As Graphics = Graphics.FromImage(bit)
    Dim myPen As Pen = New Pen(Color.Black, 2)

    If mdown Then
        g.DrawLine(myPen, lastx, lasty, e.X, e.Y) 
        PictureBox1.Image = bit ‘ bit is the bitmap of the picturebox defined as a global
        lastx = e.X
        lasty = e.Y

    End If
End Sub

Private Sub PictureBox1_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp
    mdown = False ‘ global boolean
   

End Sub

End Class

If you take this code and paste it into your project you’ll find you can now draw in the picturebox.

We now need to add the code to allow the signature to be sent via HTTP to a server.

We do this by capturing the “Drawline” coordinates and converting these into a HEX string.

First add two global strings to your project:

Public DrawLines As String = “”
Public CurrentLine As String = “”

Then amend your MouseDown, MouseUp and MouseMove routines to be:

Private Sub PictureBox1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
    lastx = e.X
    lasty = e.Y
    CurrentLine = Hexit(e.X) & Hexit(e.Y)
    mdown = True
End Sub

We record the mousedown xy coordinates and we also assign these values to the string CurrentLine, in Hex. Each Hex number is two characters long.

Private Sub PictureBox1_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
    Dim g As Graphics = Graphics.FromImage(bit)
    Dim myPen As Pen = New Pen(Color.Black, 2)

    If mdown Then
        g.DrawLine(myPen, lastx, lasty, e.X, e.Y)

        CurrentLine = CurrentLine & Hexit(e.X) & Hexit(e.Y)
        PictureBox1.Image = bit
        lastx = e.X
        lasty = e.Y

    End If
End Sub

For each MouseMove we add the new xy coordinates to the CurrentLine in Hex.

sig

Private Sub PictureBox1_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp
    mdown = False
    If CurrentLine.Length > 4 Then
        If DrawLines = “” Then
            DrawLines = CurrentLine
        Else
            DrawLines = DrawLines & “,” & CurrentLine
        End If
    End If

End Sub

When we finish the line we are drawing we append the CurrentLine to DrawLines and separate each line with commas so we end up with a CSV line.

And add the following simple HEX conversion function to your project:

Private Function Hexit(ByVal v As Integer) As String
    Hexit = Hex(v)
    If Hexit.Length = 1 Then Hexit = “0″ & Hexit
End Function

Add a textbox to your Form and make it multiline and add vertical scrollbars. And a single MenuItem:

Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem1.Click
    TextBox1.Text = DrawLines
End Sub

That’s all it takes to capture a signature and convert it to an ascii string that is easy to understand, easy to transmit and is reasonably efficient in space. Oh and it runs fast too.