I don't know how to put all the text styles in dropdownlist in asp.net . can you help me ? I'm new in it
Use System.Drawing.Text.InstalledFontCollection class to list all fonts installed on server.
Note that some these fonts may not be available on client side.
using System.Drawing.Text;
...
InstalledFontCollection inst = new InstalledFontCollection();
foreach (FontFamily fnt in inst.Families)
{
comboBox.Items.Add(fnt.Name);
}
If you want to use the server's fonts and don't care if the client has them, then use Alexander's answer to get a list of available fonts.
If you want to display fonts that the client has available, then you can use flash.
Source:
https://github.com/gabriel/font-detect-js
Demo:
http://font-detect.s3.amazonaws.com/index.html
Related
I'm currently evaluating Xamarin Forms as an alternative to our webbased HTML applications targeting mobile platforms.
Our applications often use graphical symbols embedded in paragraphs of text.
The desired effect looks like this:
Of course the text also has to be able to freely wrap around, including all the symbols. In HTML this is simply achieved like this:
<p>Sample text with <img src="sample.jpg"> embedded</p>
How can I achieve the same effect using Xamarin Forms? I already looked at FormattedStrings which allow formatting of subparagraphs of Labels, however they do not seem to allow embedding of images.
Also please note that the solution is required to support iOS, Android and Windows Phone 8.1 at least.
Obviously being forced to use a WebView almost defeats the point of moving a HTML5 app to Xamarin!
In the Xamarin Forums a similar question has been asked: https://forums.xamarin.com/discussion/1649/text-with-image
To solve the problem Tomasz Cielecki cooked up some sample code here: https://gist.github.com/Cheesebaron/5034440
He then went onto blog about it here:
http://blog.ostebaronen.dk/2013/02/adding-images-to-textview-and-edittext.html
<snip>
I started out with a super simple sample trying to get an Image shown in a TextView. I googled up some solutions and sure, Spannables allow using ImageSpan inside of them! There were nice samples and such, and I came up with this.
ImageSpan in TextView
//Load up your drawable.
var imageSpan = new ImageSpan(this, Resource.Drawable.Icon);
//Set the text of SpannableString from TextView
var spannableString = new SpannableString(textView.Text);
//Add image at end of string
spannableString.SetSpan(imageSpan, textView.Text.Length-1, textView.Text.Length, 0);
Easy, huh? And you can add loads of other Spans to the Spannable, such as StyleSpan, which you can style your fonts with bold, italic and other styles.
Since that was so easy, I quickly tried to do that with an EditText. It also works just fine...
</snip>
Currently, the only way to have symbols and images within text blocks is to use WebView (https://developer.xamarin.com/guides/xamarin-forms/working-with/webview/)
var browser = new WebView();
var htmlSource = new HtmlWebViewSource ();
htmlSource.Html = #"<html><body>
<h1>Xamarin.Forms</h1>
<p>Welcome to WebView.</p>
</body></html>";
browser.Source = htmlSource;
I have an asp.net website, in which I need to change the textbox font depending upon the language selected by the user.There are 2 radio buttons for 2 different languages English and Hindi.When the user selects one of these languages,the textbox font is changed through the following piece of code:
if(rbEnglish.Checked==true)
{
TextBox1.Font.Name="Times New Roman";
}
else if(rbHindi.Checked==true)
{
TextBox1.Font.Name="Shivaji05";
}
This works on the local computer but when the website is hosted,the Hindi font does not appear.What should be done to get this working?
Your question is strange; I think you made a simple mistake. Did you check your website with some developers tools like FireBug(in firefox), be sure that your text box gets your font style; there may be a css style in your host that overrides your internal style with somthing like "!important". Another possibility, Are you sure that you are visiting it on a client that has your Hindi font? Are you updating your text box with asp:UpdatePanel? does it work fine for other activities?
How to use custom font asp.net application.
I have a font file with me. I want to add that file as a resource and use it inside the project.
how to do it?
PrivateFontCollection pfc = new PrivateFontCollection();
Stream fontStream = this.GetType().Assembly.GetManifestResourceStream(Server.MapPath("~/Resources/EAN-13.ttf"));
byte[] fontdata = new byte[fontStream.Length];
fontStream.Read(fontdata, 0, (int)fontStream.Length);
fontStream.Close();
unsafe
{
fixed (byte* pFontData = fontdata)
{
pfc.AddMemoryFont((System.IntPtr)pFontData, fontdata.Length);
}
}
I tried this. But its not working.
You must distinguish between the code that run on server and the code that run on client browser.
The fonts that you have on your computer, on your server, can not be visible on user computer using the code behind just because you loading the fonts.
So you have two options here.
Load the fonts, and render a text in an image using this fonts, then show this image to the user.
Use client side techniques to show this fonts. Some of them are cross browser font embedding, and other can be javascript that can rendered them on client side.
You can google it with "embed custom fonts website".
Also you can check : http://typeface.neocracy.org/
and Is it possible to use custom fonts - using font-face?
I am using a 2 web browsers to compare texts, and when the lines become to long it wraps my text, i would like to remove this or lower my font size to avoid this.
Can some one please advise me on how to remove the word warp or change font size on web Browsers?
The word wrap below totally miss alines my compare:
As far as I know, there is no property of the web browser control that can do this. The presentation of the web page is controlled entirely by the web page itself.
If you cannot change the web page itself, the best you can do is to possibly cache a local version and change its styling using WebBrowser.Document.ExecCommand(). WebBrowser.Document.InvokeScript() also works but requires already-defined JS, so we have to go ahead and add in the script manually.
HtmlElement head = webBrowser.Document.GetElementsByTagName("head")[0];
HtmlElement script = webBrowser.Document.CreateElement("script");
IHTMLScriptElement element = (IHTMLScriptElement)script.DomElement;
element.text = "function adjust { document.getElementById('yourIdHere').style.whiteSpace='nowrap'; }";
head.AppendChild(script);
webBrowser.Document.InvokeScript("adjust");
Just find the div id of the text by looking at the web page's source code and you should be golden. If it doesn't have a div id, you can use other JS methods (such as getElementsByTagName) to find it.
You can not adjust font size or wrapper text from the web control its self. So you should adjust the styling of the elements inside the web browser.
I adjusted the styling at the same place i styled the green and red highlighting.
html.Append("<ins style=\"white-space:nowrap; display:inline; background:#e6ffe6;\">")
.Append(text)
.Append("</ins>");
"white-space:nowrap; display:inline;
The above code is what i added to remove word wrapping.
Inspired by Pomster's Answer, that's what I did to get the best result:
String.Format("<div style='white-space:nowrap; display:inline;'>{0}</div>",text);
c# 6.0 version:
$"<div style='white-space:nowrap; display:inline;'>{text}</div>";
I am building a mobile site and the footer has an background.
I want to check if the browser supports css property, background-image, if true display background with specific html, else display a different set of html.
I am using the following :
HttpBrowserCapabilities bc = new HttpBrowserCapabilities();
I can't seem to get a check for backgrounds.
The reason why I want to check for BG-image support is coz I have to switch between 2 sets of html. 1 with html text and bg image, and the other with the text on the image - sliced for each word/link...to give the same effect.
to get information by HttpBrowserCapabilities, you have to use Request.Browser property.
HttpBrowserCapabilities browerCapabilities = Request.Browser;
I think Asp.net will automatically check the type of the browser and render the page accordingly. So if the the browser don't support background images it will not come.
Another idea to solve the issue is getting the browser type by using code, then you can show or hide the background images based on the type.