zoukankan      html  css  js  c++  java
  • wpf 计算器布局练习

    先看一下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>

    看下生成的结果:


    虽然还差了点,但是继续努力吧。。。继续学习。。

  • 相关阅读:
    【转载】深入浅出VA函数
    oracle数据库怎么创建数据库实例
    2.4 OpenEuler中C语言中的函数调用测试(选做)
    OpenEuler 中C与汇编的混合编程(选做)
    程序运行
    改进ls的实现(课下作业)
    学习笔记12
    实验四 Web服务器1socket编程
    实验四 Web服务器2
    学习6
  • 原文地址:https://www.cnblogs.com/aukle/p/3235428.html
Copyright © 2011-2022 走看看