Doubt - Winforms on the subject on the second screen

Asked

Viewed 226 times

2

Form1 created panel with black background and label property:

  • Autosize = False
  • Dock = Fill
  • Font size(Size) = 20
  • And 2 buttons to forward or back letters

Form2 only has a black form and a property label:

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

Follow code as I show 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);

The biggest problem is the monitor resolution, I tested several monitors here and they are all different. The letters are not the same as Form1, example:

In Form1:

Everybody wants to be cool, and everybody gets screwed on the job. Yeah hard to be cool all the time. We get to be cool the bigger part of the time, but then you do something stupid and that’s it: everything you did good is immediately forgotten and you become just the one who made the big bullshit. Then you need a couple more months being exclusively legal for everyone forget the bullshit. And when they forget, you do another, of course.

On Form2(monitor):

Everybody wants to be cool, and everybody gets screwed on the job. Yeah be difficult to be
cool all the time. We can be cool the biggest part of the time, but
then you do something stupid and that’s it: everything you’ve done good is immediately
forgotten and you become just the one who made the big bullshit. There you
needs a couple more months being exclusively legal for everyone
forget nonsense. And when they forget, you do 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):

inserir a descrição da imagem aqui

And the monitor:

https://s1.postimg.org/5gyzn0lc6n/20171109_212331.jpg

1 answer

3


I made a code to adjust the label font automatically by the size of the Form, see if it works and then comment on 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 (label) in the ratio 4:3 just change some 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.

Upshot:

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

Form Pequeno

Form Grande

Tela Cheia (1920x1080)

  • can even leave in the form, just change panel2 for this

  • 1

    secondary screen does not matter. Missed something

Browser other questions tagged

You are not signed in. Login or sign up in order to post.