0

I have this little code to use AddArc() method in a label, but when I execute the code the label disappears. I believe it is the numbers I have used, I followed instructions from the Windows documentation and it had these parameters there too.

GraphicsPath gp = new GraphicsPath();

Rectangle rec = new Rectangle(20, 20, 50, 100);
gp.AddArc(rec, 0 , 180);

label2.Region = new Region(gp);
label2.Invalidate();

I used another code to make the correct way or curve in a text

protected override void OnPaint(PaintEventArgs e)
        {
            
            base.OnPaint(e);
            
            var center = new Point(Width / 2, Height / 2);
            var radius = Math.Min(Width, Height) / 3;
            var text = "Hello";//txtUp.Text;

                var font = new Font(FontFamily.GenericSansSerif, 24, FontStyle.Bold);
                for (var i = 0; i < text.Length; ++i)
                {
                    var c = new String(text[i], 1);


                    var size = e.Graphics.MeasureString(c, font);
                    var charRadius = radius + size.Height;

                    var angle = (((float)i / text.Length) - 2);

                    var x = (int)(center.X + Math.Cos(angle) * charRadius);
                    var y = (int)(center.Y + Math.Sin(angle) * charRadius);


                    e.Graphics.TranslateTransform(x, y);

                    e.Graphics.RotateTransform((float)(90 + 360 * angle / (2 * Math.PI)));
                    e.Graphics.DrawString(c, font, Brushes.Red, 0, 0);

                    e.Graphics.ResetTransform();

                    e.Graphics.DrawArc(new Pen(Brushes.Transparent, 2.0f), center.X - radius, center.Y - radius, radius * 2, radius * 2, 0, 360);
                }
        }

but it wont show in front of a panel is it possible.

This is what it looks like:

enter image description here

Is it possible to move that text in front of the green circle?

  • It's difficult to be sure what you wanted to achieve, but I would guess you wanted `(0, 0, 50, 100)` and `(rec, 0, -180)`. – GSerg Jul 09 '22 at 18:05
  • @GSerg I want to make a label that has shape like this ( –  Jul 09 '22 at 18:06
  • @GSerg i achieved it with some other method but its not in use because i want the text to change and to be in front of an image –  Jul 09 '22 at 18:06
  • @GSerg i added that other code that makes the proper half circle text in shape like this `(` –  Jul 09 '22 at 18:09
  • Why do you think assigning an arc region to the label will bend the text in the shape of the arc? It will only crop the label in the shape of that arc. The text will remain horizontal, just cropped on the sides, in the form of an arc. As if an arc overlay is placed over a page, partially covering it. – GSerg Jul 09 '22 at 18:13
  • 1
    Does this answer your question? [Drawing a string that follows a path using GDI+](https://stackoverflow.com/questions/11785217/drawing-a-string-that-follows-a-path-using-gdi) – GSerg Jul 09 '22 at 18:16
  • @GSerg this is my first time working with it and someone here told me that but i found that other solution now i need it in front of the green circle –  Jul 09 '22 at 18:23
  • 1
    Are you asking how to move that `OnPaint` text now? Well you have in it `var center =` and `var radius =`, so change those to be the center and the radius of your green circle. – GSerg Jul 09 '22 at 18:24

0 Answers0