I have a problem, I want to somehow mark text in my richtextbox. I tried to change font between adding content to richtextbox (below is code, but it works only on first text).
Font bolded = new Font("Georgia", 14, FontStyle.Bold);
Font normal = new Font("Georgia", 14, FontStyle.Regular);
logBox.Font = bolded;
logBox.Text += "Number of elements: " + dir.GetLength(0) +
Environment.NewLine + Environment.NewLine;
logBox.Font = normal;
So, can I change anything to mark my text (bolding it would be the best), and If I can't do it on richtextbox is there any other way? (my app writes a lot to this item)
Edit: I'm targetting Windows Forms Application.
Related
So i am currently writing a small IRC bot for Twitch, and i am doing it with WPF, and i would like to color only username in the text line i add to richTextBox. I tryed with simple Foreground coloring but it colors me everytime everything.
My current code:
if (e.ChatMessage.ColorHex.StartsWith("#"))
{
richTextBox.Foreground = ChatUtils.convertHexToBrush(e.ChatMessage.ColorHex);
}
richTextBox.AppendText(String.Format("[{0}] <{1}>: {2}",
DateTime.Now.ToString("HH:mm:ss"),
e.ChatMessage.DisplayName, e.ChatMessage.Message) + "\n");
richTextBox.ScrollToEnd();
So how would i color only the parameter {1} which is e.ChatMessage.DisplayName?
Try like this-
TextRange tr = new TextRange(rtb.Document.ContentEnd, rtb.Document.ContentEnd);
tr.Text = e.ChatMessage.DisplayName;
tr.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Red);
See if this helps.
are there a way to change a some part of the labels content in C#?
i know you can do that in the xaml but thats just for manualy typing in the text
i want
Resultatfor_nu_Copy.Content = oprofilbox.Text(green) + "/(yellow)" + obredebox.Text(green) + "-(yellow)" + oFælgestr.Text(green);
Create multiple Run instances, each with its own color, and add them to a TextBlock's Inlines collection.
var textBlock = new TextBlock();
textBlock.Inlines.Add(new Run("Green") { Foreground = Brushes.Green });
textBlock.Inlines.Add(new Run("Yellow") { Foreground = Brushes.Yellow });
myLabel.Content = textBlock;
(If you're curious about why the TextBlock needs to be there, this answer might interest you.)
The font property of richtextbox doesn't seem to be working.
//
// textBox_rawdata
//
this.textBox_rawdata.DetectUrls = false;
this.textBox_rawdata.Font = new System.Drawing.Font("NSimSun", 9F);
this.textBox_rawdata.HideSelection = false;
this.textBox_rawdata.Location = new System.Drawing.Point(22, 43);
this.textBox_rawdata.Name = "textBox_rawdata";
this.textBox_rawdata.Size = new System.Drawing.Size(368, 68);
this.textBox_rawdata.TabIndex = 2;
this.textBox_rawdata.Text = "AAAAAA";
I want the font of the richtextbox to be NSimSun, 9pt. As you can see in the picture, The first few A's are preset and the last 3 A's are typed in by me. The issues is, the preset characters and any characters generated by the program are correctly displayed as NSimSun, 9pt. But as soon as I start typing in there, the font changes. (Like the last 3 A's)
How can I make the font NSimSun, 9pt for all text?
This might work for you.
this.textBox_rawdata.SelectionFont = new System.Drawing.Font("Tahoma", 12, System.Drawing.FontStyle.Bold)
if you want your font type, size and style to be set once you run your code put this in designer:
this.textBox_rawdata.Font = new System.Drawing.Font("Tahoma", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
Try to set SelectionFont property of richtextbox to System.Drawing.Font("NSimSun", 9F) also.
From MSDN it is:
A Font that represents the font to apply to the current text selection or to text entered after the insertion point.
I want to display one or more CheckBoxes on a tile in my Windows Phone app. This works already for TextBlocks, but with a CheckBox it shows only the Text of the CheckBox and not the Checkmark itself.
This is a sample of my code:
public void CreateTile()
{
StackPanel panel = new StackPanel();
panel.VerticalAlignment = VerticalAlignment.Top;
panel.Margin = new Thickness(7.0, 7.0, 7.0, 0);
panel.Width = 336;
panel.Height = 336;
panel.Orientation = Orientation.Vertical;
// Create and add a CheckBox for each task
foreach (var task in _tasks)
{
TextBlock textBlock = new TextBlock();
textBlock.TextWrapping = TextWrapping.Wrap;
textBlock.Style = App.Current.Resources["PhoneTextLargeStyle"] as Style;
textBlock.Foreground = new SolidColorBrush(Colors.White);
textBlock.Text = task.Text;
CheckBox checkBox = new CheckBox();
checkBox.IsChecked = task.IsDone;
checkBox.Content = textBlock;
panel.Children.Add(checkBox);
}
Grid layoutRoot = new Grid();
layoutRoot.Background = new SolidColorBrush(Colors.Blue);
layoutRoot.Width = 336;
layoutRoot.Height = 336;
layoutRoot.Children.Add(panel);
layoutRoot.Measure(new Size(336, 336));
layoutRoot.Arrange(new Rect(0, 0, 336, 336));
layoutRoot.UpdateLayout();
// Render grid into bitmap
WriteableBitmap bitmap = new WriteableBitmap(336, 336);
bitmap.Render(layoutRoot, null);
bitmap.Invalidate();
// Save background image for tile to isolated storage
Uri backgroundImage = TileHelper.SaveTileImage(bitmap);
}
If I create a tile with a background image created by the method above, the tile will look like this:
As you can see the text is displayed but there is no checkmark/square before the text.
I personally like to use Segoe UI Symbol as the Font Family in such situations. This gives me the flexibility to use Text and Symbols together while not messing around too much with code / images. SUS has great modern icons (or characters if you may call them) that are very much Metroish, I'd say.
Just open up Charmap (Win + R and type in charmap) and in the Font Select -> Segoe UI Symbol. Now you can select any character you like and paste into Visual Studio Editor itself. Yes, it works!
The symbol may not display properly in the Editor itself but it will at Runtime
Here are some suggestions:
Here are the corresponding characters:
☑
✅
Don't worry about them not looking right HERE. They should when you follow the above steps.
You can always "hack" it by using images of checkbox controls. Did you try to show created control in UI? i.e. adding it to page? Just to see if your code is executed correctly.
Or another solution would be to use check mark character - http://www.fileformat.info/info/unicode/char/2713/index.htm
I'll try to replicate this problem in my test app since it is strange that it does not work.
setting the footer..
in the above screen the footer is displayed after new member report and reporting period but i dont want like this
I'm working on windows application using C#.
I have generated the "Report" using Ms chart control. While printing and exporting into XPS format, Header and Footer are appearing its fine .
But i want the Footer will be displayed at the bottom of the report at present it was appearing just after the header, I want to add this Footer at the bottom using C#. So user can print page with Header and Footer. How to do this.
can any one have idea about this ..
Many thanks....
this is my code
Title maintitle = kpiChartControl.Titles.Add("New Members Report" + Environment.NewLine);
maintitle.Alignment = ContentAlignment.TopLeft;
maintitle.Font = new Font(FontFamily.GenericSansSerif, 11, FontStyle.Bold);
Title rangetitle = kpiChartControl.Titles.Add(string.Format("Report period from : {0} to {1}{2}", dStartDate.Value.ToString(xxx.dateFormat),
denddate.Value.ToString(xxxx.dateFormat), Environment.NewLine));
rangetitle.Alignment = ContentAlignment.TopLeft;
rangetitle.Font = new Font(FontFamily.GenericSansSerif, 11, FontStyle.Bold);
Title footertitle = kpiChartControl.Titles.Add("--------------------------------------------------------" + Environment.NewLine);
footertitle.Alignment = ContentAlignment.BottomCenter;
Title gompanytitle = kpiChartControl.Titles.Add("xxxx");
gompanytitle.Alignment = ContentAlignment.BottomLeft;
gompanytitle.Font = new Font(FontFamily.GenericSansSerif, 9, FontStyle.Regular);
Title printedby = kpiChartControl.Titles.Add(string.Format("Printed By ("+text+") On :{0}", dt,Environment.NewLine));
printedby.Alignment = ContentAlignment.BottomRight;
printedby.Font = new Font(FontFamily.GenericSansSerif, 9, FontStyle.Regular);
kpiChartControl.Printing.Print(true);
kpiChartControl.Titles.Remove(maintitle);
kpiChartControl.Titles.Remove(rangetitle);
kpiChartControl.Titles.Remove(footertitle);
kpiChartControl.Titles.Remove(gompanytitle);
kpiChartControl.Titles.Remove(printedby);
The trick is to use the Docking property. So for all items that you wish to place below the graph, do the following
printedby.Docking = Docking.Bottom;
gompanytitle.Docking = Docking.Bottom;
footertitle.Docking = Docking.Bottom;
I'm kinda guessing here to be honest - but it seems to me that you need to be adding the footer in the XPS document, rather than as part of the chart. My guess is that the chart will always by displaying titles at the top.
This SO - about adding header/footer to an XPS - should help: add footer to FlowDocumentsdocuments, both Sauron's and Vikram's answers there should provide the information you need.