How to change the size of a screen through an event in C# WPF

Asked

Viewed 231 times

2

How is it possible to make a change in the size of a Form(Window) in WPF, by changing its Heigth and Width and thus increasing and decreasing the screen according to the reported values? For example: I have a button (Increase Screen) and when the event refeeds to that button a function takes place

button_click(){
   Form.Width = NovoValor;
   Form.Heigth= NovoValor;
}
  • I believe the right commands are: Form.Left, Form.Top, and so it goes.

  • @Francisco This defines position, not size.

1 answer

1


You also need to define the properties MinWidth and MinHeigth.

private void button_Click(object sender, RoutedEventArgs e)
{
    MinWidth = novaLargura;
    Width = novaLargura;
    MinHeight = novaAltura;
    Height = novaAltura;
}
  • I was just trying with Width and Heigth, did not know it was necessary to inform the Min... too! thanks so much for the help

Browser other questions tagged

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