Home > DeveloperSection > Forums > WPF APPLICATION
Jaya J
Jaya J

Total Post:9

Points:63
Posted on    March-24-2015 10:24 PM

 .NET C# 
Ratings:


 1 Reply(s)
 636  View(s)
Rate this:
I want to change my TEXTBOX,LABEL,BUTTON SIZES dynamically based on screen resolutions. i.e, screen resolution of system may vary based on computer sizes.when i'm using my wpf application on different systems the sizes of TEXTBOX,LABEL, etc also change based on screen resolution.

Tell me the code for this problem.Please help me.


Mayank Tripathi
Mayank Tripathi

Total Post:397

Points:3117
Posted on    March-25-2015 4:46 AM

Hi Jaya , i have created a sample form as per your problem

 

 

 

MainWindow.xaml

 

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525" MinHeight="350">
    <Grid>
        <Grid Height="Auto" Margin="2" Width="Auto">
          
            <Grid.RowDefinitions>
                <RowDefinition Height="50"/>
                <RowDefinition Height="1*"/>
                <RowDefinition Height="50"/>
                <RowDefinition Height="1*"/>
                <RowDefinition Height="1*"/>
            </Grid.RowDefinitions>
          
            <TextBlock Text="First Name" HorizontalAlignment="Stretch" VerticalAlignment="Center" Grid.Row="0"/>
            <Border BorderBrush="DarkGray" BorderThickness="1" Grid.Row="1" Margin="5" CornerRadius="5">
                <TextBox  HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="Auto" Height="Auto"/>
            </Border>
          
            <TextBlock Text="Last Name" HorizontalAlignment="Stretch" VerticalAlignment="Center" Grid.Row="2"/>
            <Border BorderBrush="DarkGray" BorderThickness="1" Grid.Row="3"  Margin="5" CornerRadius="5">
            <TextBox  HorizontalAlignment="Stretch" VerticalAlignment="Stretch"  Width="Auto" Height="Auto"/>
            </Border >
            <Button Grid.Row="4"  Content="Button" HorizontalAlignment="Stretch" Width="Auto" Height="Auto" Margin="10" FontSize="30">
               
            </Button>
        </Grid>
 
    </Grid>
</Window>

 

MainWindow.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
 
namespace WpfApplication1
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }
    }
}
 

 

Hope this will help u solve your problem!!


Regards

Mayank


Don't want to miss updates? Please click the below button!

Follow MindStick