abhas

hi friends, anyone of you know how to convert a TextBox object into a StrokeCollection form. I tried it using the StrokeCollectionConvertor to convert a TextBox to StrokeCollection but it was giving an error which specifies that it is unable to convert a TextBox to StrokeCollection. I need this conversion so I am able to save the textbox into a file by calling function called inkcanvas.Strokes.Save method but before calling this function we have to convert TextBox to stroke or StrokeCollection. So, please help me...




Re: Notebook, Tablet PC, and UMPC Development Convert TextBox to StrokeCollection

joe zhou - MSFT

This question seems can be answered better in tablet related forum. I'll try to move it there.



Re: Notebook, Tablet PC, and UMPC Development Convert TextBox to StrokeCollection

Mark Hopkins - MSFT

Hi:

It sounds like you should use XamlWriter.Save instead of StrokeCollection.Save. XamlWriter.Save enables you to serialize any XAML tree and it's children. StrokeCollection.Save will only save the ink strokes. Check out this thread for more information about this topic.

Regards,
 - Mark Hopkins (MSFT)






Re: Notebook, Tablet PC, and UMPC Development Convert TextBox to StrokeCollection

abhas

hi mark, thanks for the thread you gave me to understand the main difference between strokes.save() method and XamlWriter.Save() method. I need to convert the textbox into stroke so as when I save the stroke and latter reload it I can select the stroke and delete it in the way I modify the general stroke. Basically, I am creating a WhiteBoard in which each elements are drawn using strokes. For this purpose, if I can convert TextBox to StrokeCollection, then I can save and reload it. Using XamlWriter I will store it but after loading it, I will not be able to select and delete it and use other functionalities. Please if you have any other suggestion, then let me know. If you are not able to understand this post, then let me know. I will explain you in more detail about the problem.


Thanks,

Abhas






Re: Notebook, Tablet PC, and UMPC Development Convert TextBox to StrokeCollection

Mark Hopkins - MSFT

Hi Abhas:

I'm not sure what you mean when you say you want to convert a TextBox to a StrokeCollection. Do you mean you want to convert the contents of the TextBox to a StrokeCollection or the actual TextBox control, itself

Thanks,
- Mark Hopkins (MSFT)






Re: Notebook, Tablet PC, and UMPC Development Convert TextBox to StrokeCollection

abhas

hi mark, I want to create a textbox dynamically and then write text onto it and convert the textbox with it's contents to stroke collection. If you know any class or library which provides this functionality, then please let me know.

I hope your doubts regarding my post is clear now. If you need me to explain the post in more detail then let me know. I will welcome your query.

Thanks,

Abhas.






Re: Notebook, Tablet PC, and UMPC Development Convert TextBox to StrokeCollection

Mark Hopkins - MSFT

Hi Abhas:

The TextBox is used for keyboard input. If you are gathering stylus input, you should use an InkCanvas, which already has a StrokeCollection that you can save. Is there a specific reason you are using a TextBox Have you looked at InkCanvas

Thanks,
- Mark Hopkins (MSFT)






Re: Notebook, Tablet PC, and UMPC Development Convert TextBox to StrokeCollection

abhas

hi Mr.Hopkins, I apologize to reply late to your post. Thanks for spending your time to respond to my query. Sir, I am using the TextBox as I am creating a software similar to Microsoft Paint. The software enables the user to write the text. I have saved the objects such as triangle, rectangle in form of StrokeCollection so that strokes can be saved using InkCanvas.Strokes.Save method. So I needed to convert the whole TextBox object into strokecollection. I thurridly searched on the net in search for a convertor but unable to find it. Please let me know if you know how to convert the TextBox object to StrokeCollection which contains strokes.



Thanks,

Abhas.






Re: Notebook, Tablet PC, and UMPC Development Convert TextBox to StrokeCollection

Charles.Forget

Abhas,

i don't personnaly know any way of doing what you're asking for but, maybe you should take a look at the Microsoft.Ink InkEdit object.
The InkEdit object is like a RichTextBox that allows you to convert strokes to text. (never used it but, read a bit about it and, it seems to work quite fine)

Some infos in french : http://labo-microsoft.supinfo.com/articles/web/tabletpc_dev/
Some infos in english : http://www2.sys-con.com/ITSG/virtualcd/Dotnet/archives/0108/mccabe/index.htm

I don't know if this object can help you but, it's worth taking a look at...






Re: Notebook, Tablet PC, and UMPC Development Convert TextBox to StrokeCollection

abhas

hi charles, thanks for spending your precious time in giving me the links of the InkEdit control. I will explain you in detail what I want. I am constructing a module for drawing objects and saving them in InkCanvas and the software is similar to the Microsoft Paint. I am drawing the objects by first collecting their stylus points and drawing strokes then and for saving I am using InkCanvas.Strokes.Save method. I want to save text in the same format by which I am drawing and saving the other objects. I searched on microsoft site and found that there is DrawingContext.DrawText() method to draw text and then Stroke.Draw(DrawingContext) to render stroke over the Drawing Context. I tried but was unsuccessful and also there are no samples available demonstrating the issue. I know that we can add TextBox dynamically and store the textbox as children of Inkcanvas but when saving the inkcanvas the textbox will not be saved.


I hope everyone including you reading the post are now able to understand what exactly I want. Please let me know if you have some samples or other ideas in order to solve the problem. If you are not able to understand then let me know I will post the code through which everyone will get some idea.

Thanks,

Abhas.






Re: Notebook, Tablet PC, and UMPC Development Convert TextBox to StrokeCollection

Mark Hopkins - MSFT

Hello Abhas:

There is no way to convert a TextBox into a StrokeCollecion. InkCanvas.Stroke.Save will only save ink data. You cannot store text or controls in this format. Sorry to keep asking you to clarify. I've been trying to understand your problem so I can recommend a good way to accomplish your task.

I think your best option is to use XamlWriter.Save. You can save the TextBox as a child of the InkCanvas and it will be restored when you oad it back in. Here is a link to a thread that explains how to do this:

http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=1168352&SiteID=1

Regards,
- Mark Hopkins (MSFT)






Re: Notebook, Tablet PC, and UMPC Development Convert TextBox to StrokeCollection

abhas

hi mark, thanks for spending your time in understanding my issue. You should not apologize for asking me regarding the problem I faced. I really liked giving the details of the problem and discussing with you. If you have gone through my last post, I mentioned about System.Windows.Ink.Stroke.Draw(DrawingContext object) method which is used to render stroke on the object Drawn by the DrawingContext.DrawText(). If we can't draw convert the text typed by the user in stroke in the above manner specified, then what is the use of Stroke.Draw(DrawingContext). I think it is not defined for nothing by microsoft. I am posting the code through which you can better understand the problem and find the solution to it. XamlSerialization is another solution but I need it so that I can convert any object to stroke form.



Please go through the code as follows :

System.Windows.Controls.Image img = new System.Windows.Controls.Image();
StylusPointCollection pointcol = new StylusPointCollection();
pointcol.Add(new StylusPoint(mypoint.X, mypoint.Y - 55.0));
pointcol.Add(new StylusPoint(mypoint.X + img.Width, mypoint.Y - 55.0));
pointcol.Add(new StylusPoint(mypoint.X, mypoint.Y - 55.0 + img.Height));
pointcol.Add(new StylusPoint(mypoint.X + img.Width, mypoint.Y - 55.0 + img.Height));
pointcol.Add(new StylusPoint(mypoint.X, mypoint.Y - 55.0));
Stroke news = new Stroke(pointcol);
DrawingVisual vis = new DrawingVisual();

DrawingContext cont = vis.RenderOpen();
cont.DrawImage(source, new Rect(mypoint.X, mypoint.Y - 55.0, img.Height + 5.0, img.Width + 5.0));
news.DrawingAttributes.IgnorePressure = true;
news.Draw(cont);
cont.Close();
inkcanvas1.Strokes.Add(news);

Waiting for your reply....

Abhas.






Re: Notebook, Tablet PC, and UMPC Development Convert TextBox to StrokeCollection

Stefan Wick - MSFT

If your goal is to render text inside of InkCanvas, then you can just add a TextBlock (or a TextBox or a Label or a RichTextBox) as a child of the InkCanvas:

TextBlock tb = new TextBlock();
tb.Text = "foo";
inkcanvas1.Children.Add(tb);

If your goal is to add text as ink strokes so that you you could use InkCanvas's editing tools (eraser, selection, etc.), then you would need to convert the font data to ink strokes. For that you would have to break down each letter into a collection of point arrays so you can create S.W.Ink.Stroke objects. I don't think there is an easy, automatic way to do this conversion.

Thanks,

Stefan Wick






Re: Notebook, Tablet PC, and UMPC Development Convert TextBox to StrokeCollection

abhas

Thanks Mr. Wick, I am thinking in the same direction now after putting so much efforts in finding an easy solution. However, I found another alternative to achieve these without converting each font letter into strokes. I will convert the TextBox class into xaml string using XamlWriter class and store in a Text file and while loading the application I will read the Text File and from the xaml string I will deserialize into TextBox object using XamlReader class and add it as a children of Inkcanvas.

Mr. Wick, I need a bit more help from you. I am currently during my winter training on a live project in WinFX technology. I am looking for a job in the company working in this new technology. Do you know such companies and their eligibility criteria. I do not have any work experience in the background but have worked on ASP.net and possess good knowledge in it. If you know such companies then please let me know by replying to this post. I will be much more thankful to you.

Waiting for your reply....
Abhas.






Re: Notebook, Tablet PC, and UMPC Development Convert TextBox to StrokeCollection

Stefan Wick - MSFT

I have replied privately to your last question, using the e-mail address from your user profile.

Thanks,

Stefan Wick