I am trying to perform edit functions in a RichTextBox on a C# (Windows Forms) application and .NETFramework 3.5. I would like to be able to select any number of text characters from all text present on the RichTextBox and then change targeted font characteristics.
The trouble I have is that on my selected text each characters font properties may be set to different font. In this case the textbox ignores the event that I request.
case "Font Size": ComboTool = (Infragistics.Win.UltraWinToolbars.ComboBoxTool)this.RTFUltraToolbarsManager.Tools["Font Size"];
try
{
this.RichTextBox.SelectionFont = new Font(this.RichTextBox.SelectionFont.Name, float.Parse(ComboTool.Text), this.RichTextBox.SelectionFont.Style);
}
catch { }
break;
When I do that in my "RTFUltraToolbarsManager_ToolValueChanged", I want to change te size of the selected text and the "this.RichTextBox.SelectionFont" is null.
Do you know how can I solve my problem?
Related
I have a little help pop-up that displays some text when the user presses a "?" label next to a drop-down to explain the different selections.
I did it using the Help.ShowPopup command since that seemed the easiest.
I was hoping there was a way to add different font properties to parts of the text or at least to the whole thing without having to go the direction of a CHM/HTML help-file.
Here is what I am trying to do:
private void helpLbl_Click(object sender, EventArgs e)
{
// for some reason, it ignores the 'parent' parameter
// and lays it out on the screen's coordinates
Point helpLocation = helpLbl.PointToScreen(Point.Empty);
helpLocation.Y += helpLbl.Height; // have it display underneath the control
Help.ShowPopup(this, // hosting form
#"<b>Fixed:</b>
Removes a fixed amount from the sale
<b>Percent Value:</b>
Removes a set percentage of the selected package from the sale
...", helpLocation);
I was hoping since there's the option to use an HTML document to display the help, I could use HTML tags to format what was being displayed, but it doesn't appear so. Any ideas?
Is there a way to do something like displaying a RichTextBox in the help pop-up?
Another possibility is generating a HTML document on-the-fly, but it asks for a "url" if I'm not supplying the text directly and I think that might be a little over-kill for the small amount I'm trying to do here.
You have two options. One is to use a WebBrowser Control. This natively accepts HTML and displays it. The problem with it is its kind of bloated just to use as a simple label.
Your second option is to simply create a RichTextLabel, simply like this:
public class RichTextLabel : RichTextBox
{
public RichTextLabel()
{
BorderStyle = BorderStyle.None;
}
}
Add this to your form and set the Rtf property to your RTF code. You will have to convert your HTML to RTF, which is easy if you got a program such as Microsoft Word, for example.
I have a small windows application that has a series of labels on it. This application will be globalized and there is a possibility that the text on these labels might get truncated. I am trying to automate to identify truncated text on these labels.
For other controls, I can use TextPattern.Pattern through which I can find the visible text and the actual text inside the control. But for the labels (ControlType.text) the TextPattern is not supported. How do I find the visible text for these lables using UI automation.
Here is the code I tried. If I pass control type as Document it works. But with Text control type it gives a unsupported pattern exception.
private String TextFromSelection(AutomationElement target, Int32 length)
{
// Specify the control type we're looking for, in this case 'Document'
PropertyCondition cond = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Text);
// target --> The root AutomationElement.
AutomationElement textProvider = target.FindFirst(TreeScope.Descendants, cond);
TextPattern textpatternPattern = textProvider.GetCurrentPattern(TextPattern.Pattern) as TextPattern;
if (textpatternPattern == null)
{
Console.WriteLine("Root element does not contain a descendant that supports TextPattern.");
return null;
}
var test = textpatternPattern.DocumentRange.GetText(-1).TrimEnd('\r');
var tpr = textpatternPattern.GetVisibleRanges();
var txt = tpr[0].GetText(-1);
return txt;
}
Whether the text pattern is supported by the label element will be affected by which UI framework is being used. For example, the labels in the Win32 Run dlg don't support the Text pattern, but labels in the Windows 10 XAML Calculator do. The image below shows the Inspect SDK tool reporting that the Text pattern is supported by the "There's no history yet" label.
It's important to note that whether the UI framework (or the app if the app implements the UIA Text pattern directly) includes the truncated text in the data it returns to you when you call IUIAutomationTextPattern::GetVisibleRanges(), is up to the framework (or app) itself. For example, WordPad running on Windows 10 doesn't include the text that's clipped out of view, but Word 2013 does return the clipped text.
Thanks,
Guy
You should be able to simply use element.Current.Name (element being the instance of AutomationElement for the label).
Here is an example of UISpy retrieving the text for a label:
I have a Xamarin application with a Label which is Bound like so:
<Label Text="{Binding BackSpace}"/>
and a property in my viewmodel like so:
public string BackSpace
{
get
{
ResourceManager temp = new ResourceManager("MyProgram.ResourceStrings", typeof(MyClass).GetTypeInfo().Assembly);
result = System.Text.RegularExpressions.Regex.Unescape(temp.GetString("Backspace"));
}
}
now I have an element in my ResourceStrings called Backspace and I am trying to get the string associated with this key which I want to be the Android Backspace - ⌫
So initially I set the resource equal to the symbol ⌫ but this just gives me a label containing ?
Now I try set it equal to the HTML hex code from here: ⌫ but this gives me ⌫
How do I get my label to display the ⌫ symbol?
PS. - Even if I try:
<Label Text="⌫"/>
I get a blank label
You'll need to change your label's font to a font which contains backspace as glyphicon.
You'll need two things:
Appropriate font. Probably Noto Sans Symbols https://www.google.com/get/noto/#sans-zsym. ⌫ symbol
Label renderer which allows custom fonts. See here: https://github.com/XLabs/Xamarin-Forms-Labs/wiki/ExtendedLabel
This Xamarin link will provide more infomation on working with Fonts
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?
In my application I have a rich text-box.I use that as a text editor. I can change font,size, style when I needed. now my problem is I want to find out font-name,size, text-color of each character ?
i,e i want to retrieve every character's font-name,size, text-color after editing is done.
You can use the SelectionFont property to retrieve the font of the currently selected text. Similarly, you can use the SelectionColor property.
Never done this personally and no time to test at the moment, but the: Groups RV's DotNET forum may have your solution. Perhaps something like mentioned in the post:
for (int iCurChar = lastChar; iCurChar
richTextBox1.Text.Length; iCurChar++)
{
richTextBox1.Select(iCurChar,1);
char CurrChar = richTextBox1.Text[iCurChar];
Color CurrColor = richTextBox1.SelectionColor;
Font CurrFont = richTextBox1.SelectionFont;
float fontSize = CurrFont.Size
}
Taking a look at the Font class may be useful as well: Microsoft's Font Reference Page