How to center a bold element? - c#

Hy my example code:
Bold b = new Bold(new Run("TODO"));
b.FontSize = 50;
My Question is:
How to center the bold element?

I assume this is in reference to classes in System.Windows.Documents. You need to set the TextAlignment property on the thing (a Paragraph usually) that b is contained in.

The paragraph around the Run should define the alignment.
Bold b = new Bold(new Run("TODO"));
b.FontSize = 50;
var p = new Paragraph(b) {TextAlignment = TextAlignment.Center};

Related

How to place the label of ChartCustomPoint in a Syncfusion Chart (winform)

I have a syncfusion chart in my winform application.
I add a series of data.
I want to highlight a specific point of the series (let's say the 25th data point of the first series) with a red circle and the "Focus" text.
ChartCustomPoint cp = new ChartCustomPoint();
cp.CustomType = ChartCustomPointType.PointFollow;
cp.PointIndex=25;
cp.SeriesIndex=1;
cp.Symbol.Shape = ChartSymbolShape.Circle;
cp.Symbol.Color = Color.Red;
cp.Symbol.Marker.LineInfo.Width = 4;
cp.Alignment = ChartTextOrientation.Up;
cp.Text = "Focus";
chartControl1.CustomPoints.Add(cp);
but, the displayed text is stuck to the symbol. I would like to add space between the label and the symbol.
Is there a property I missed ?
Thank you
Thanks for using Syncfusion Products.
We have analyzed your query. While using the Custom Points the space between the text and the symbol can be provided by using the Alignment property of the Custom points.
The alignment property is used to align the text in the center, top, topleft , topright ,left ,right ,bottom ,bottomleft ,bottomright and when the symbol is present the RegionUp, RegionDown, RegionCenter will consider the symbol and the align the text accordingly.
When the RegionUp is set to the alignment the space is provided between the symbol and the text
ChartCustomPoint cp1 = new ChartCustomPoint();
// Point that follows a series point:
cp1.PointIndex = 2;
cp1.SeriesIndex = 0;
cp1.CustomType = ChartCustomPointType.PointFollow;
cp1.Symbol.Shape = ChartSymbolShape.Circle;
cp1.Offset = 20;
cp1.Font.Facename = "Times New Roman";
cp1.Font.Bold = true;
cp1.Font.Size = 11f;
cp1.Symbol.Color = Color.FromArgb(0Xc1, 0X39, 0x2b);
// Provide space between the symbol and the text
cp1.Alignment = ChartTextOrientation.RegionUp;
cp1.Text = "Circle";
cp1.Symbol.Marker.LineInfo.Width = 4;
chart.CustomPoints.Add(cp1);
We have attached the sample for your reference.
Sample link:http://www.syncfusion.com/downloads/support/directtrac/general/ze/Custom_points-2112217385
Please let us know if you have any concerns.
Regards,
Deepaa.

how to get cursor from name of cursor?

like below that we get color , I Want set the Cursor property of Button
Color red = Color.FromName("Red");
button1.BackColor = red;
may be something like this:
String x = "Hand"
button1.Cursor = Cursor.FromName(x);
Here is simple example:
https://stackoverflow.com/a/37101840/6306993
CursorConverter cConverter = new CursorConverter();
Cursor c = (Cursor) cConverter.ConvertFromString("Hand");
this.button1.Cursor = c;
as my understanding, you are looking for how to set Cursor for button depend in existing variable. Please see the example below:
Cursor x = Cursors.Hand;
button1.Cursor = x;
if you still get error please check again "Cursors" not "Cursor" in the first line.
Looks like you are looking for CursorConverter.
Here is simple example:
CursorConverter cConverter = new CursorConverter();
Cursor c = (Cursor) cConverter.ConvertFromString("Hand");
this.button1.Cursor = c;
More information:
https://msdn.microsoft.com/en-us/library/system.windows.forms.cursorconverter(v=vs.110).aspx

Issue with set up paragraph width in MigraDoc

How to set up paragraph width in MigraDoc? All what I imagine is create table and set the column width and then paragraph populate all width. But I need something like next:
var paragraph016 = section.AddParagraph();
paragraph016.Format.Borders.Bottom.Visible = true;
paragraph016.Format.WidowControl = true;
//here must be define paragraph width
Or maybe anybody know how can I draw line on the page, where I can setup width and position of my line?
I use paragraph width as a part of my 'add a horizontal rule' helper method. Using left and right indent works great:
public static void AddHorizontalRule(Section section, double percentWidth, Color? color = null)
{
double percent = (percentWidth < 0.0 || percentWidth > 1.0) ? 1.0 : percentWidth;
Color hrColor = color ?? new Color(96, 96, 96); // Lt Grey default
Unit contentWidth = section.PageSetup.PageWidth - section.PageSetup.LeftMargin - section.PageSetup.RightMargin;
Unit indentSize = (contentWidth - (percent * contentWidth)) / 2.0;
Paragraph paragraph = section.AddParagraph();
paragraph.Format.LeftIndent = indentSize;
paragraph.Format.RightIndent = indentSize;
paragraph.Format.Borders.Top.Visible = true;
paragraph.Format.Borders.Left.Visible = false;
paragraph.Format.Borders.Right.Visible = false;
paragraph.Format.Borders.Bottom.Visible = false;
paragraph.Format.Borders.Top.Color = hrColor;
}
Note that because a section's PageSetup values are 0 and therefore use the default document settings, that to use the client area width as shown above, you need to explicitly set these values in the section.PageSetup before calling this method. I do it this way so that I don't have to pass around the document nor depend on document.LastSection being the section that I am working on. I just pass in a Section object and have at it.
Enjoy!
Brian
You can set the width indirectly by specifying left and right indent. I don't know if this leads to the desired line, but it's worth a try.
A table will work.
An image would also work - best with a vector image (could be PDF), but a raster image with a single pixel in the desired color should also work.

Labelling and circle a specific point in zedgraph

I am currently doing a project in which I've managed to identify the peak I want. However, I wanted to do more like circling the particular point with a label attached to it. Is it possible to do that in Zedgraph?
I've attached a snippet of my code which only include a text label to that point, and I wanted to do more so people will identify the point more easily.
PointPair pt = myCurve.Points[i-1];
const double offset = 0.8;
TextObj text = new TextObj("P", pt.X, pt.Y + offset,
CoordType.AxisXYScale, AlignH.Left, AlignV.Center);
text.ZOrder = ZOrder.A_InFront;
text.FontSpec.Border.IsVisible = false;
text.FontSpec.Fill.IsVisible = false;
text.FontSpec.Fill = new Fill( Color.FromArgb( 100, Color.White ) );
myPane.GraphObjList.Add(text);
Any help is appreciated! Thanks!
Make a LineItem as follows
LineItem line = new LineItem("Point", new double[] {pt.x}, new double[] {pt.y}, Color.Black, SymbolType.Circle);
line.Symbol.Size = 20;
line.Symbol.Fill = new Fill(Color.Transparent);
myPane.CurveList.Add(line);
This should create a large empty circle centered around your point. Obviously, you can adjust color and size as you see fit, and the ZOrder if you need to. You might want to adjust your legend so it doesn't include this point. Alternatively, you can name this line with your label and leave it in the legend as a way of tagging it. The only other way for a label is to do what you're doing, as I'm not sure of a way to associate labels directly to a line.

Write text with coefficient like C₁, C₂, C₃ on label

I have to write text with coefficient value like C1, C2, C3 on label text, so please tell me how can i write ???
thanks
Shashi Jaiswal
You need a font that comes with glyphs for Unicode codepoints U+2080 to U+2089:
label1.Font = new Font("DejaVu Sans", 10);
label1.Text = "C₁"; // or "C\u2081"
(assuming WinForms)
In WinForms you need to emulate that with a RichTextBox
// Appearance as a label
var subscriptFont = new System.Drawing.Font(
richTextBox1.Font.FontFamily,
richTextBox1.Font.Size - 2);
richTextBox1.BackColor = System.Drawing.SystemColors.Control;
richTextBox1.BorderStyle = System.Windows.Forms.BorderStyle.None;
richTextBox1.ReadOnly = true;
richTextBox1.Text = "C1, C2, C3";
// subscript 1
richTextBox1.Select(1, 1);
richTextBox1.SelectionCharOffset = -3;
richTextBox1.SelectionFont = subscriptFont;
// subscript 2
richTextBox1.Select(5, 1);
richTextBox1.SelectionCharOffset = -3;
richTextBox1.SelectionFont =subscriptFont;
// subscript 3
richTextBox1.Select(9, 1);
richTextBox1.SelectionCharOffset = -3;
richTextBox1.SelectionFont = subscriptFont;
subscriptFont.Dispose();
You could try using a different font that haves subindexes...
You can't. Plain and simple.
(But you could use two labels, positioned and sized accordingly, or use a label that supports complex markup... Or use UTF-8, which allows them...)
But a stock C# Winforms project? Nah.

Categories

Resources