Class TextStyle
Namespace: Aspose.Note
Assembly: Aspose.Note.dll (24.12.0)
Specifies the text style.
public sealed class TextStyle : Style
Inheritance
Inherited Members
Style.GetHashCode(), Style.IsBold, Style.IsItalic, Style.IsUnderline, Style.IsStrikethrough, Style.IsSuperscript, Style.IsSubscript, Style.FontName, Style.FontSize, Style.FontColor, Style.Highlight, Style.FontStyle, object.GetType(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()
Examples
Let’s emphasize page’s titles among other headers by increasing font’s size.```csharp string dataDir = RunExamples.GetDataDir_Text();
// Load the document into Aspose.Note.
Document document = new Document(dataDir + "Aspose.one");
// Iterate through page's titles.
foreach (var title in document.Select(e => e.Title.TitleText))
{
title.ParagraphStyle.FontSize = 24;
title.ParagraphStyle.IsBold = true;
foreach (var run in title.TextRuns)
{
run.Style.FontSize = 24;
run.Style.IsBold = true;
}
}
document.Save(Path.Combine(dataDir, "ChangePageTitleStyle.pdf"));
Let's emphasize latest text's changes by highlighting.```csharp
string dataDir = RunExamples.GetDataDir_Text();
// Load the document into Aspose.Note.
Document document = new Document(dataDir + "Aspose.one");
// Get RichText nodes modified last week.
var richTextNodes = document.GetChildNodes<richtext>().Where(e => e.LastModifiedTime >= DateTime.Today.Subtract(TimeSpan.FromDays(7)));
foreach (var node in richTextNodes)
{
// Set highlight color
node.ParagraphStyle.Highlight = Color.DarkGreen;
foreach (var run in node.TextRuns)
{
// Set highlight color
run.Style.Highlight = Color.DarkSeaGreen;
}
}
document.Save(Path.Combine(dataDir, "HighlightAllRecentChanges.pdf"));</richtext>
Set proofing language for a text.```csharp var document = new Document(); var page = new Page(); var outline = new Outline(); var outlineElem = new OutlineElement();
var text = new RichText() { ParagraphStyle = ParagraphStyle.Default };
text.Append("United States", new TextStyle() { Language = CultureInfo.GetCultureInfo("en-US") })
.Append(" Germany", new TextStyle() { Language = CultureInfo.GetCultureInfo("de-DE") })
.Append(" China", new TextStyle() { Language = CultureInfo.GetCultureInfo("zh-CN") });
outlineElem.AppendChildLast(text);
outline.AppendChildLast(outlineElem);
page.AppendChildLast(outline);
document.AppendChildLast(page);
document.Save(Path.Combine(RunExamples.GetDataDir_Text(), "SetProofingLanguageForText.one"));
Manipulate by text format using paragraph style.```csharp
var document = new Document();
var page = new Page();
var outline = new Outline();
var outlineElem = new OutlineElement();
var text = new RichText() { ParagraphStyle = new ParagraphStyle() { FontName = "Courier New", FontSize = 20 } }
.Append($"DefaultParagraphFontAndSize{Environment.NewLine}")
.Append($"OnlyDefaultParagraphFont{Environment.NewLine}", new TextStyle() { FontSize = 14 })
.Append("OnlyDefaultParagraphFontSize", new TextStyle() { FontName = "Verdana" });
outlineElem.AppendChildLast(text);
outline.AppendChildLast(outlineElem);
page.AppendChildLast(outline);
document.AppendChildLast(page);
document.Save(Path.Combine(RunExamples.GetDataDir_Text(), "SetDefaultParagraphStyle.one"));
Shows how to bind a hyperlink to a text.```csharp // The path to the documents directory. string dataDir = RunExamples.GetDataDir_Tasks();
// Create an object of the Document class
Document doc = new Document();
RichText titleText = new RichText() { ParagraphStyle = ParagraphStyle.Default }.Append("Title!");
Outline outline = new Outline()
{
MaxWidth = 200,
MaxHeight = 200,
VerticalOffset = 100,
HorizontalOffset = 100
};
TextStyle textStyleRed = new TextStyle
{
FontColor = Color.Red,
FontName = "Arial",
FontSize = 10,
};
TextStyle textStyleHyperlink = new TextStyle
{
IsHyperlink = true,
HyperlinkAddress = "www.google.com"
};
RichText text = new RichText() { ParagraphStyle = ParagraphStyle.Default }
.Append("This is ", textStyleRed)
.Append("hyperlink", textStyleHyperlink)
.Append(". This text is not a hyperlink.", TextStyle.Default);
OutlineElement outlineElem = new OutlineElement();
outlineElem.AppendChildLast(text);
// Add outline elements
outline.AppendChildLast(outlineElem);
// Initialize Title class object
Title title = new Title() { TitleText = titleText };
// Initialize Page class object
Page page = new Note.Page() { Title = title };
// Add Outline node
page.AppendChildLast(outline);
// Add Page node
doc.AppendChildLast(page);
// Save OneNote document
dataDir = dataDir + "AddHyperlink_out.one";
doc.Save(dataDir);
## Constructors
### <a id="Aspose_Note_TextStyle__ctor"></a> TextStyle\(\)
```csharp
public TextStyle()
Properties
Default
Gets the style with “en-US” culture.
public static TextStyle Default { get; }
Property Value
DefaultMsOneNoteTitleDateStyle
Gets default style for title date in MS OneNote.
public static TextStyle DefaultMsOneNoteTitleDateStyle { get; }
Property Value
DefaultMsOneNoteTitleTextStyle
Gets default style for title text in MS OneNote.
public static TextStyle DefaultMsOneNoteTitleTextStyle { get; }
Property Value
DefaultMsOneNoteTitleTimeStyle
Gets default style for title time in MS OneNote.
public static TextStyle DefaultMsOneNoteTitleTimeStyle { get; }
Property Value
HyperlinkAddress
Gets or sets the hyperlink address. Must be set if the value of the Aspose.Note.TextStyle.IsHyperlink property is true.
public string HyperlinkAddress { get; set; }
Property Value
Examples
Shows how to bind a hyperlink to a text.```csharp // The path to the documents directory. string dataDir = RunExamples.GetDataDir_Tasks();
// Create an object of the Document class
Document doc = new Document();
RichText titleText = new RichText() { ParagraphStyle = ParagraphStyle.Default }.Append("Title!");
Outline outline = new Outline()
{
MaxWidth = 200,
MaxHeight = 200,
VerticalOffset = 100,
HorizontalOffset = 100
};
TextStyle textStyleRed = new TextStyle
{
FontColor = Color.Red,
FontName = "Arial",
FontSize = 10,
};
TextStyle textStyleHyperlink = new TextStyle
{
IsHyperlink = true,
HyperlinkAddress = "www.google.com"
};
RichText text = new RichText() { ParagraphStyle = ParagraphStyle.Default }
.Append("This is ", textStyleRed)
.Append("hyperlink", textStyleHyperlink)
.Append(". This text is not a hyperlink.", TextStyle.Default);
OutlineElement outlineElem = new OutlineElement();
outlineElem.AppendChildLast(text);
// Add outline elements
outline.AppendChildLast(outlineElem);
// Initialize Title class object
Title title = new Title() { TitleText = titleText };
// Initialize Page class object
Page page = new Note.Page() { Title = title };
// Add Outline node
page.AppendChildLast(outline);
// Add Page node
doc.AppendChildLast(page);
// Save OneNote document
dataDir = dataDir + "AddHyperlink_out.one";
doc.Save(dataDir);
### <a id="Aspose_Note_TextStyle_IsHidden"></a> IsHidden
Gets or sets a value indicating whether the text style is hidden.
```csharp
public bool IsHidden { get; set; }
Property Value
IsHyperlink
Gets or sets a value indicating whether the text style is hyperlink.
public bool IsHyperlink { get; set; }
Property Value
Examples
Shows how to bind a hyperlink to a text.```csharp // The path to the documents directory. string dataDir = RunExamples.GetDataDir_Tasks();
// Create an object of the Document class
Document doc = new Document();
RichText titleText = new RichText() { ParagraphStyle = ParagraphStyle.Default }.Append("Title!");
Outline outline = new Outline()
{
MaxWidth = 200,
MaxHeight = 200,
VerticalOffset = 100,
HorizontalOffset = 100
};
TextStyle textStyleRed = new TextStyle
{
FontColor = Color.Red,
FontName = "Arial",
FontSize = 10,
};
TextStyle textStyleHyperlink = new TextStyle
{
IsHyperlink = true,
HyperlinkAddress = "www.google.com"
};
RichText text = new RichText() { ParagraphStyle = ParagraphStyle.Default }
.Append("This is ", textStyleRed)
.Append("hyperlink", textStyleHyperlink)
.Append(". This text is not a hyperlink.", TextStyle.Default);
OutlineElement outlineElem = new OutlineElement();
outlineElem.AppendChildLast(text);
// Add outline elements
outline.AppendChildLast(outlineElem);
// Initialize Title class object
Title title = new Title() { TitleText = titleText };
// Initialize Page class object
Page page = new Note.Page() { Title = title };
// Add Outline node
page.AppendChildLast(outline);
// Add Page node
doc.AppendChildLast(page);
// Save OneNote document
dataDir = dataDir + "AddHyperlink_out.one";
doc.Save(dataDir);
### <a id="Aspose_Note_TextStyle_IsMathFormatting"></a> IsMathFormatting
Gets or sets a value indicating whether the text style is math-formatting.
```csharp
public bool IsMathFormatting { get; set; }
Property Value
Language
Gets or sets the language of the text.
public CultureInfo Language { get; set; }
Property Value
Examples
Set proofing language for a text.```csharp var document = new Document(); var page = new Page(); var outline = new Outline(); var outlineElem = new OutlineElement();
var text = new RichText() { ParagraphStyle = ParagraphStyle.Default };
text.Append("United States", new TextStyle() { Language = CultureInfo.GetCultureInfo("en-US") })
.Append(" Germany", new TextStyle() { Language = CultureInfo.GetCultureInfo("de-DE") })
.Append(" China", new TextStyle() { Language = CultureInfo.GetCultureInfo("zh-CN") });
outlineElem.AppendChildLast(text);
outline.AppendChildLast(outlineElem);
page.AppendChildLast(outline);
document.AppendChildLast(page);
document.Save(Path.Combine(RunExamples.GetDataDir_Text(), "SetProofingLanguageForText.one"));
#### Remarks
Returns System.Globalization.CultureInfo.InvariantCulture if the property is not set.
## Methods
### <a id="Aspose_Note_TextStyle_Equals_System_Object_"></a> Equals\(object\)
Determines whether the specified object is equal to the current object.
```csharp
public override bool Equals(object obj)
Parameters
obj
object
The object.
Returns
The System.Boolean.
Equals(TextStyle)
Determines whether the specified object is equal to the current object.
public bool Equals(TextStyle other)
Parameters
other
TextStyle
The object.
Returns
The System.Boolean.
GetHashCode()
Serves as a hash function for the type.
public override int GetHashCode()
Returns
The System.Int32.