Is there an easy way to convert HTML to display in the new Windows Phone 7.1 (Mango) RichTextBox control. I'm mostly concerned about retaining links and images without using a web browser control.
thanks,
Sam
I would use HTML Agility pack to parse the HTML and transform each type of node in the equivalent in the Document namespace: http://htmlagilitypack.codeplex.com/
You need to handle the nested elements and depending of the level of conformity of the HTML, handling bad formatted content can be hard but HA is a good library.
There's a sample in the source code I think.
public void ConvertRtfToHtml()
{
System.Windows.Forms.WebBrowser webBrowser =
new System.Windows.Forms.WebBrowser();
webBrowser.CreateControl(); // only if needed
webBrowser.DocumentText = richTextBox1.Text;
while (webBrowser.DocumentText != richTextBox1.Text)
Application.DoEvents();
webBrowser.Document.ExecCommand("SelectAll", false, null);
webBrowser.Document.ExecCommand("Copy", false, null);
richTextBox2.Paste();
}
Related
I have a WindowsForm application having all text(On form labels/buttons/other controls) written in the Norwegian language. I want to convert all text in English using localization. Is there any way in Devexpress where we can convert all text into English without writing the meaning of every text in a resource file manually?
For example:- In the attachment, "Brukernavn" is hardcoded on a label. I want to auto-convert it into English without assigning its value in English-ResourceFile. What should be the approach in Devexpress localization?
I'm not aware of any Devexpress method to do this. A good solution would be to actually do the work of building a localisation file for English which would work like following.
Add a InternationlisationLayer to your application.
This layer
scours the application to locate all Controls you would possible want
to translate.
After finding all Controls you have to match their
Text values to the translated text.
After finding a matching English
text you will have to replace the Text Property on these Controls.
If you want to avoid building a proper Localisation system a far easier solution is explained below.
Make a List of type and fill it with all control texts you want translated.
Translate the strings and add format them as such that you have a Dictionary of type (where Key would be the original text and Value being the translated text).
At application Start get a list of all Controls you want to translate and do something like the following:
public static IEnumerable<System.Windows.Forms.Control> GetAllControlsOfType(this System.Windows.Forms.Control control, Type type)
{
var controls = control.Controls.Cast<System.Windows.Forms.Control>();
return controls.SelectMany(ctrl => GetAllControlsOfType(ctrl, type))
.Concat(controls)
.Where(c => c.GetType() == type);
}
public void DoTranslation()
{
var ctrls = this.GetAllControlsOfTypes(new List<Type>() { typeof(Label), typeof(Button) });
foreach (var ctr in ctrls)
{
var element = dict.FirstOrDefault(i => i.Key == ctr.Text);
ctr.Text = element.Value;
}
}
This a Panel Control Contain Invoice Bill:
I want to make this Panel in Pdf and Excel file,but not in image format as a regular pdf file. This code is Written in Windows c#.
Graphics grp = panel.CreateGraphics();
Size formSize = this.ClientSize;
bitmap = new Bitmap(formSize.Width, 610, grp);
grp = Graphics.FromImage(bitmap);
Point panelLocation = PointToScreen(panel.Location);
grp.CopyFromScreen(panelLocation.X, panelLocation.Y, 0, 0, formSize);
printPreviewDialog1.Document = printDocument1;
printPreviewDialog1.PrintPreviewControl.Zoom = 1;
printPreviewDialog1.ShowDialog();
but it makes screen shot and create pdf file..
There is nothing that I know of that will take your image and create a "nice" PDF (small, searchable, zoomable) automatically. There is just too much room for error.
You will need to use something that is report-specific or pdf-specific to create your document. Depending on your requirements Docmosis and iText are good at this. Docmosis lets you build your layout in a doc template so it's easier than building in code, but it will still take work specific to the report you are creating. Please note I work for Docmosis. If you prefer a code-approach, iText is very good.
I hope that helps.
I am new to silverlight, I'm working on a wince 6 camera application and I want use silverlight embedded as GUI, the data from camera is DIB format, so I test code like below, but the IXRBitmapImage is abstract class, can't be instantiated.
IXRImagePtr image;
IXRBitmapImagePtr source = new IXRBitmapImage();
if (FAILED(retcode=root->FindName(TEXT("MyImage"), &image)))
return -1;
source->SetBitmapSource(SHLoadDIBitmap(TEXT("/NandFlash/images/test.bmp")));
image->SetSource(source);
IXMBitmapImagePtr are initialized through IXRApplication->CreateObject(REFIID riid, IXRDependencyObject** ppObject) = 0;
IXRApplication->CreateObject on MSDN:
http://msdn.microsoft.com/en-us/library/ee503673%28v=winembedded.60%29.aspx
For a tutorial:
http://geekswithblogs.net/WindowsEmbeddedCookbook/archive/2009/11/18/silverlight-for-windows-embedded-tutorial-step-3.aspx
Excerpt from the last link:
We declared two IXRBitmapImagePtr objects but we still haven't initialized them.
To create a Silverlight for Windows Embedded object we should use the CreateObject method of the IXRApplication object:
if (FAILED(retcode=app->CreateObject(IID_IXRBitmapImage,&img01)))
return retcode;
When populating my treeview I would like to use the same images that I use in my toolbar etc which are stored in a resource file.
The treeview seems to on accept images via an image list.
I was thinking of reflecting and adding the resources to an image list on load...
How do you guyz n girlz generally do this?
Just for completeness, that "sledge hammer" approach to add all images from a resource
foreach (var propertyInfo in
typeof(Resources).GetProperties(BindingFlags.Static | BindingFlags.NonPublic)
.Where(info => info.PropertyType == typeof (Bitmap))) {
mainImageList.Images.Add(
propertyInfo.Name,
(Bitmap)propertyInfo.GetValue(null, null));
}
I usually have an image list that I populate using images from the resource file. This can easily be done when initializing the form.
Example (with three images in Resources.resx, called one, two and three):
private void PopulateImageList()
{
_treeViewImageList.Images.Add("one", Resources.one);
_treeViewImageList.Images.Add("two", Resources.two);
_treeViewImageList.Images.Add("three", Resources.three);
}
Today I'm playing with localization. I have a winforms app where I've set localizable to true on my screen, then I went and converted all the text to spanish as best as I could. So now I have my screen.resx and my screen.es.resx and everything looks good/bueno. How do I now run my app and have the spanish version come up? I tried going into regional and language options and setting my 'standards and formats' option to spanish. Now my dates are in spanish which is good, but the text on my app is still the english version. How do I get this thing to load with my screen.es.resx?
Did you set your applications Culture/UI Culture to Spanish?
In following code, en-US will be replaced by your UI culture and it will use appropriate resx file depending on the way you have them set up
HTH
System.Globalization.CultureInfo myCI = new System.Globalization.CultureInfo("en-US", false);
System.Threading.Thread.CurrentThread.CurrentUICulture = myCI;
System.Threading.Thread.CurrentThread.CurrentCulture = myCI;
You control which language resource that are used by setting the CurrentUICulture of the current thread. You will most likely also want to set the CurrentCulture (that controls number and date formats and such) (C# code):
// the following using statements must be present
// using System.Threading;
// using System.Globalization;
Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("es-ES");
Thread.CurrentThread.CurrentCulture = Thread.CurrentThread.CurrentUICulture;
For a more detailed discussion on the difference between CurrentUICulture and CurrentCulture, there is a blog post by Michael Kaplan on the topic.