문제

I'm wondering if that's possible: I got a c# application with something like a display consisting of about 11000 circles drawn on the Form.

What I want to achieve is to be able to draw text on that display, but not using the "real" pixels, but using the circles (rectangles) drawn on the form as pixels.

Edit 1:

When drawing text in c#, you would i.e. use something like Graphics.DrawString(...), giving the method a rectangle (so coordinates) in which the text should be drawn in. That text then is drawn in that rectangle using the screen pixels. What I want to do is draw text as well but not using the screen pixels but my custom pixels of which my display consists.

Edit 2

Method used to draw the circles on the Form; Circles is a list consisting of Circle objects, where circleRectangle returns the coordinates in which the circle should be drawn and Filled tells the method if the circle should be filled or not.

    public void DrawCircles(Graphics g)
    {

        graphics = g;
        graphics.SmoothingMode =System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
        Pen pen = new Pen(Color.Black, penthickness);
        SolidBrush brush = new SolidBrush(Color.White);
        for (int j = 0; j < Circles.Count;j++ )
        {
            graphics.DrawEllipse(pen, Circles[j].CircleRectangle);
            if (Circles[j].Filled)
                brush.Color = fillColor;
            else
                brush.Color = Color.White;
            graphics.FillEllipse(brush, Circles[j].CircleRectangle);

        }

    }

Is this possible and if yes, how would I do that?

도움이 되었습니까?

해결책

You could write on an invisible BitMap with the DrawText method and then scan the bitmap's pixels and turn the corresponding circles on.

Did that last week with the cells of DataGridView. Real easy.

Here is some code:

    public void drawText(string text, Font drawFont)
    {
        Bitmap bmp = new Bitmap(canvasWidth, canvasHeight);
        Graphics G = Graphics.FromImage(bmp);
        SolidBrush brush = new SolidBrush(paintColor);
        Point point = new Point( yourOriginX, yourOriginY );

        G.DrawString(text, drawFont, brush, point);

        for (int x = 0; x < canvasWidth; x++)
            for (int y = 0; y < canvasHeight; y++)
            {
                Color pix = bmp.GetPixel(x, y);
                    setCell(x, y, pix);     //< -- set your custom pixels here!
            }
        bmp.Dispose();
        brush.Dispose();
        G.Dispose();
    }

Edit: You would use your dimensions and your origin for the DrawString, of course

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top