Doubt - Winforms about respect on second screen

2

Form1 created panel with black background and label with property:

  • AutoSize = False
  • Dock = Fill
  • Font size (Size) = 20
  • E 2 buttons for forward or backward lettering

Form2 only has black form and a label with property:

  • AutoSize = False
  • Dock = Fill
  • Font size (Size) = 40

Follow the code as I show it on the second screen (monitor):

telaSecundaria = new SegundaTela();
Screen[] telas = Screen.AllScreens;
Rectangle bounds = telas[1].Bounds; // pode ser outro índice.
telaSecundaria.SetBounds(bounds.X, bounds.Y, bounds.Width, bounds.Height);
telaSecundaria.StartPosition = FormStartPosition.Manual;
telaSecundaria.Show();
telaSecundaria?.ChangeLabel(label.Text);

Biggest problem is the monitor resolution, I did test multiple monitors here and they are all different. The letters are not the same as Form1, for example:

No Form1:

  

Everyone wants to be cool, and everyone gets their hands on the job. IS   Hard to be cool the whole time. We can be cool the bigger   part of the time, but then do something stupid and done: everything you did   of good is immediately forgotten and you become only the one who did   the big bullshit. Then you need another two months being   exclusively legal for everyone to forget the bullshit. And when   they forget, you make another, of course.

On Form2 (monitor):

  

Everyone wants to be cool, and everyone gets their hands on the job. IS   difficult to be
           legal the whole time. We can be cool the bigger   part of the time, but
   there is a bullshit and that's it: everything you've done   of good is immediately
     forgotten and you become only the one who did   the big bullshit. There you
      needs another two months being   exclusively legal for everyone
     forget the bullshit And when   they forget, you make another, of course.

How can I correct the positions of each word? Here on the monitor and the client screen is ok. The problem is different monitor (different resolution). I want Form2 to be the same as Form1.

Follow the photo (client):

Andfromthemonitor:

link

    
asked by anonymous 09.11.2017 / 23:49

1 answer

3

I made a code to adjust the font of the label automatically by the size of the Form, see if it works and then comment the code explaining everything

  Timer tSize = new Timer() { Interval = 300, Enabled = false };
  private void Form1_Load(object sender, EventArgs e)
    {
        label1.Text = @"Todo mundo quer ser legal, e todo mundo se ferra na empreitada. É difícil ser legal o tempo inteiro. A gente consegue ser legal a maior parte do tempo, mas aí faz uma besteira e pronto: tudo o que você fez de bom é imediatamente esquecido e você se torna apenas aquele que fez a grande besteira. Aí você precisa de mais uns dois meses sendo exclusivamente legal para todo mundo esquecer da besteira. E quando eles esquecem, você faz outra, claro."; 

        tSize.Tick +=  (s,arg) => {
             ((Timer)s).Enabled = false;
             SetLabelSize();
        };
    }


    private void Form1_Resize(object sender, EventArgs e)
    {
        tSize.Enabled = false;
        tSize.Enabled = true;
    }
    private void label1_TextChanged(object sender, EventArgs e)
    {
        tSize.Enabled = false;
        tSize.Enabled = true;
    }
    private void SetLabelSize()
    {
        this.SuspendLayout();
        label1.Dock = DockStyle.Top;
        label1.AutoSize = true;
        label1.MaximumSize = new Size(this.Width, 0);
        label1.Font = new Font("Consolas", 12);
        float size = label1.Font.Size;
        int limite = this.Height - 30;
        while (label1.Height < limite- label1.Font.Height)
        {
            size += 0.1f;
            label1.Font = new Font("Consolas", size);
        }

        this.ResumeLayout(false);
    }

Edit:

As requested, to keep the screen in the ratio 4: 3 just change a few lines in the code.

Remove: label1.MaximumSize = new Size(this.Width, 0);

and put:

label1.MaximumSize = new Size(this.Height + this.Height /4 , 0);
panel2.Padding = new System.Windows.Forms.Padding((panel2.Width - label1.Width) / 2, 0, 0, 0);

Where panel2 is where the label is inserted. That is, it is the Parent of the label.

Result:

  

I put the label with a background of another color to differentiate it from the form.

    
10.11.2017 / 01:16