简体   繁体   中英

Winforms Transformation

The current application am developing has lot of drawings. The Origin of the drawing start from Left,Bottom instead of Top,Left . Drawings works perfectly except " DrawingString ".

Graphics g;  
g.TranslateTransform(0, Height);  
g.ScaleTransform(1, -1);

//All drawings  

g.DrawString("1", new Font("Segoei UI", 9), Brushes.Green, new Point(x, y));

The result I get is upside down Text [![enter image description here][1]][1] I wanted to draw only the text normal and rest of the drawings should always start from the bottom left?

EDIT

    private void panel1_Paint(object sender,PaintEventArgs e)
    {
        var g = e.Graphics;
        var height = panel1.Height;
        g.TranslateTransform(0,height);
        g.ScaleTransform(1,-1);
        g.DrawRectangle(new Pen(Brushes.Black,1),new Rectangle(10,10,100,100));
        g.DrawString("Test",new Font("Segoei UI",9),Brushes.Green,new Point(10,110));
    }

RESULT
在此处输入图片说明

I want only the text to be flipped. Keeping the drawing as it is

Flip it over again.

See the example below. The text Sunday appears normally. Then we transpose the graphics object's matrix and write Monday , so Monday appears laterally inverted on the Y-axis, and finally we flip over the Y-axis yet again so it restores itself to its original state before writing Tuesday , which appears normally.

在此处输入图片说明

private void Form1_Paint(object sender, PaintEventArgs e)
{
    var graphics = e.Graphics; // this.CreateGraphics();
    var font = new Font("Georgia", 12.0F);
    var brush = new SolidBrush(Color.Black);

    var pointF = new PointF(20F, 20F);
    graphics.DrawString("Sunday", font, brush, pointF);

    graphics.ScaleTransform(1F, -1F);
    pointF = new PointF(10F, -210F);
    graphics.DrawString("Monday", font, brush, pointF);

    graphics.ScaleTransform(1, -1);
    pointF = new PointF(200F, 200F);
    graphics.DrawString("Tuesday", font, brush, pointF);

    brush.Dispose();
    font.Dispose();
}

Do that in your code, making sure to calculate the value of the Y-axis where you want your text to appear.

g.ScaleTransform(1,-1);
g.DrawRectangle(new Pen(Brushes.Black,1),new Rectangle(10,10,100,100));

g.ScaleTransform(1,-1);
g.DrawString("Test",new Font("Segoei UI",9),Brushes.Green,new Point(10, -110));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM