黑马程序员-wpf 计算器布局练习

13 篇文章 0 订阅
4 篇文章 0 订阅
---------------------- ASP.Net+Unity开发.Net培训、期待与您交流! ----------------------

先看一下windows自带计算机的布局:


大概布局能看出,有菜单栏(menu),有显示框(textbox),然后剩下的6行5列的布局

先看下代码:

            <StackPanel>
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition></RowDefinition>
                    </Grid.RowDefinitions>
                    <TextBox Name="xianshi" Text="显示框" Height="50" Margin="5,5,5,5"></TextBox>
                </Grid>
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition></RowDefinition>
                        <RowDefinition></RowDefinition>
                        <RowDefinition></RowDefinition>
                        <RowDefinition></RowDefinition>
                        <RowDefinition></RowDefinition>
                        <RowDefinition></RowDefinition>
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition></ColumnDefinition>
                        <ColumnDefinition></ColumnDefinition>
                        <ColumnDefinition></ColumnDefinition>
                        <ColumnDefinition></ColumnDefinition>
                        <ColumnDefinition></ColumnDefinition>
                    </Grid.ColumnDefinitions>
                    <Button Grid.Row="0" Grid.Column="0" Content="MC" Margin="5"></Button>
                    <Button Grid.Row="0" Grid.Column="1" Content="MR" Margin="5"></Button>
                    <Button Grid.Row="0" Grid.Column="2" Content="MS" Margin="5"></Button>
                    <Button Grid.Row="0" Grid.Column="3" Content="M+" Margin="5"></Button>
                    <Button Grid.Row="0" Grid.Column="4" Content="M-" Margin="5"></Button>

                    <Button Grid.Row="1" Grid.Column="0" Content="←" Margin="5"></Button>
                    <Button Grid.Row="1" Grid.Column="1" Content="CE" Margin="5"></Button>
                    <Button Grid.Row="1" Grid.Column="2" Content="C" Margin="5"></Button>
                    <Button Grid.Row="1" Grid.Column="3" Content="±" Margin="5"></Button>
                    <Button Grid.Row="1" Grid.Column="4" Content="√" Margin="5"></Button>

                    <Button Grid.Row="2" Grid.Column="0" Content="7" Margin="5"></Button>
                    <Button Grid.Row="2" Grid.Column="1" Content="8" Margin="5"></Button>
                    <Button Grid.Row="2" Grid.Column="2" Content="9" Margin="5"></Button>
                    <Button Grid.Row="2" Grid.Column="3" Content="/" Margin="5"></Button>
                    <Button Grid.Row="2" Grid.Column="4" Content="%" Margin="5"></Button>

                    <Button Grid.Row="3" Grid.Column="0" Content="4" Margin="5"></Button>
                    <Button Grid.Row="3" Grid.Column="1" Content="5" Margin="5"></Button>
                    <Button Grid.Row="3" Grid.Column="2" Content="6" Margin="5"></Button>
                    <Button Grid.Row="3" Grid.Column="3" Content="*" Margin="5"></Button>
                    <Button Grid.Row="3" Grid.Column="4" Content="1/x" Margin="5"></Button>

                    <Button Grid.Row="4" Grid.Column="0" Content="1" Margin="5"></Button>
                    <Button Grid.Row="4" Grid.Column="1" Content="2" Margin="5"></Button>
                    <Button Grid.Row="4" Grid.Column="2" Content="3" Margin="5"></Button>
                    <Button Grid.Row="4" Grid.Column="3" Content="-" Margin="5"></Button>
                    <Button Grid.Row="4" Grid.Column="4" Content="=" Grid.RowSpan="2" Margin="5"></Button>

                    <Button Grid.Row="5" Grid.Column="0" Content="0" Grid.ColumnSpan="2" Margin="5"></Button>

                    <Button Grid.Row="5" Grid.Column="2" Content="." Margin="5"></Button>
                    <Button Grid.Row="5" Grid.Column="3" Content="+" Margin="5"></Button>
                    
                </Grid>
            </StackPanel>
        </DockPanel>

看下生成的结果:


虽然还差了点,但是继续努力吧。。。继续学习。。争取早日把wpf拿下,跟杨老师的视频学这么长时间了,视频看的不少了,但是效果还是有些不理想啊,有些明白有些则会忘掉。。。苦恼ing。。。

---------------------- ASP.Net+Unity开发.Net培训、期待与您交流! ----------------------详细请查看: www.itheima.com
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值