三、Grid控件;练习

未使用Grid编程:

代码:

   Title="留言板" Height="240" Width="400">
    <Grid >
        <TextBlock x:Name="TextBlock" Text="请输入你的姓名并留言:" HorizontalAlignment="Left" Margin="10,10,0,0" Height=" 25" Width=" 140" TextWrapping="Wrap" VerticalAlignment="Top"/>
        <ComboBox x:Name="comboBox" HorizontalAlignment="Right"  Margin="0,10,10,0" VerticalAlignment="Top" Height=" 25" Width="210"/>
        <TextBox x:Name="textBox" HorizontalAlignment="Left" Height="121" Width="343" Margin="10,40,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top"/>
        <Button x:Name="button" Content="提交" HorizontalAlignment="Right"  Margin="0,0,96,10" VerticalAlignment="Bottom" Height=" 25" Width="80"/>
        <Button x:Name="button1" Content="清除" HorizontalAlignment="Right" Margin="0,0,10,10" VerticalAlignment="Bottom" Height=" 25" Width="80"/>
    </Grid>

界面:

拉伸后:

拉伸后,界面个控件位置发生改变,

由于HorizontalAlignment="Right"参数的设置,是各控件顺着设定的边沿移动

使用Grid布局

代码:

        Title="留言板" Height="240" Width="400">
    <Grid >
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" MinWidth="120"/>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="80"/>
            <ColumnDefinition Width="4"/>
            <ColumnDefinition Width="80"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="25"/>
            <RowDefinition Height="4"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="4"/>
            <RowDefinition Height="25"/>
        </Grid.RowDefinitions>
        <TextBlock x:Name="TextBlock" Text="请输入你的姓名并留言:" VerticalAlignment="Center"  Grid.Row="0" Grid.Column="0"/>
        <ComboBox x:Name="comboBox" VerticalAlignment="Center"  Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="4"/>
        <TextBox x:Name="textBox" Grid.Row="2" Grid.Column="0" Grid.ColumnSpan=" 5" BorderBrush="Black" />
        <Button x:Name="button" Content="提交" Grid.Row="4" Grid.Column="2"/>
        <Button x:Name="button1" Content="清除" Grid.Row="4" Grid.Column="4"/>
    </Grid>

界面:

 

拉伸后:



总结:可以通过对Grid的设置,实现控件不随窗口变化而改变,或者随窗口变化而改变的特征,主要是对绝对值,比例值,自动值的设置



——————————————————————————————————————————————————————————————————————————————————————————————本人刚入手wpf,哪里有不对的,请在评论中指出,谢谢!!!微笑———————————————————————————————




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值