TextRenderer.DrawText with scroll

aronmatthew

Active member
Joined
Aug 5, 2019
Messages
41
Programming Experience
Beginner
It seems that adding label control or text render is not working using translate transform. However the drawing its self works with scroll without text or label.
 
It seems that adding label control or text render is not working using translate transform. However the drawing its self works with scroll without text or label.
C#:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace debug
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();


            SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            SetStyle(ControlStyles.UserPaint, true);
            SetStyle(ControlStyles.ResizeRedraw, true);

            AutoScroll = true;
            Paint += new System.Windows.Forms.PaintEventHandler(paint);
            Width = 100;
            Height = 200;
         

        }
        private void paint(object sender, System.Windows.Forms.PaintEventArgs e)
        {
          
            using (Font font = new Font("Times New Roman", 15, FontStyle.Regular, GraphicsUnit.Pixel))
            {
              
                Point p;
                Point p1 = default(Point);
                int i = 0;
                for (i = 0; i < 50; i++)
                {
                    if(i==0)
                    p = new Point(
                        0,0);
                    else
                        p = new Point(
                      0, p1.Y+15);

                    TextRenderer.DrawText(e.Graphics, i.ToString(), font, p, Color.Black);
                    p1 = new Point(p.X,p.Y);
                }
                AutoScrollMinSize = new Size(20, i*15);
            }

            e.Graphics.TranslateTransform(this.AutoScrollPosition.X, this.AutoScrollPosition.Y);


        }


    }
}
 

Attachments

  • Untitled.png
    Untitled.png
    1.5 KB · Views: 3
Last edited by a moderator:
I've noticed in your last couple of threads that you seem to want to provide as little information as possible. We don't know anything about your project other than what you tell us so you need to tell us EVERYTHING that's relevant. Please Provide a FULL and CLEAR explanation of the problem. Explain exactly what you're trying to achieve, how you're trying to achieve it, what happens when you try and how that differs from your expectations. The more you leave it to us to assume or work it out for ourselves, the more likely we'll either get it wrong or just not bother trying to help.
 
Back
Top Bottom