zoukankan      html  css  js  c++  java
  • string 转 label,button等空间类型

    写代码过程中,遇到问题,要定义一个string ,用for循环增量string的序号,对应前台的不同label,由于string类型无法直接转换成label类型。如何转换呢?

    for (int i = 1; i <= numleft; i++)
                            {
                                string str = "label" + i + "";
                                string but = "button_" + i + "";
                                Button bu = grid.FindName(but) as Button;
                                bu.Content = "4535353";
                                string st = "label" +( 20 + i) + "";
                                Label time = grid.FindName(st) as Label;
                                time.Content = "45534";
                                Label la= grid.FindName(str) as Label;
                               la.Content = "" + i + ".rtret" + i + "";
                            }

    可以看到,我前台的label命名规则是label1,label2,label3......,要逐个对每个label进行Content赋值;由于label.name是string型,如何组个增量呢,具体的就看代码的实现了。前提是这些label要在同一个grid下面,具体的看前台代码:

    <Grid  Name="grid">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="20*" />
                <ColumnDefinition Width="761*" />
                <ColumnDefinition Width="19*" />
            </Grid.ColumnDefinitions>
            <!--<Image Name="image1" Stretch="Fill" Source="/Resources/Resources1/1.png" Grid.ColumnSpan="2" />-->
            <Label Height="28" Margin="0,24,0,0" Name="label1" VerticalAlignment="Top" HorizontalAlignment="Left" Width="227" FocusVisualStyle="{x:Null}" Foreground="Brown" FontSize="16px" Grid.ColumnSpan="2"></Label>
            <Label Height="28" HorizontalAlignment="Left" Margin="0,69.001,0,0" Name="label2" VerticalAlignment="Top" Width="227" FocusVisualStyle="{x:Null}" Foreground="Brown" FontSize="16px" Grid.ColumnSpan="2"></Label>
            <Label Height="28" HorizontalAlignment="Left" Margin="0,112,0,0" Name="label3" VerticalAlignment="Top" Width="227" FocusVisualStyle="{x:Null}" Foreground="Brown" FontSize="16px" Grid.ColumnSpan="2"></Label>
            <Label Height="28" HorizontalAlignment="Left" Margin="0,153,0,0" Name="label4" VerticalAlignment="Top" Width="227" FocusVisualStyle="{x:Null}" Foreground="Brown" FontSize="16px" Grid.ColumnSpan="2"></Label>
            <Label Height="28" HorizontalAlignment="Left" Margin="0,196,0,0" Name="label5" VerticalAlignment="Top" Width="227" FocusVisualStyle="{x:Null}" Foreground="Brown" FontSize="16px" Grid.ColumnSpan="2"></Label>
            <Label HorizontalAlignment="Left" Margin="0,242.717,0,229.283" Name="label6" Width="227" FocusVisualStyle="{x:Null}" Foreground="Brown" FontSize="16px" Grid.ColumnSpan="2"></Label>
            <Label HorizontalAlignment="Left" Margin="0,0,0,190" Name="label7" Width="227" FocusVisualStyle="{x:Null}" Height="28" VerticalAlignment="Bottom" Foreground="Brown" FontSize="16px" Grid.ColumnSpan="2"></Label>
            <Label HorizontalAlignment="Left" Margin="0,0,0,144" Name="label8" Width="227" Height="28" VerticalAlignment="Bottom" FocusVisualStyle="{x:Null}" Foreground="Brown" FontSize="16px" Grid.ColumnSpan="2"></Label>
            <Label Height="28" HorizontalAlignment="Left" Margin="0,0,0,103" Name="label9" VerticalAlignment="Bottom" Width="227" FocusVisualStyle="{x:Null}" Foreground="Brown" FontSize="16px" Grid.ColumnSpan="2"></Label>
            <Label Height="26.716" HorizontalAlignment="Left" Margin="0,0,0,60.568" Name="label10" VerticalAlignment="Bottom" Width="227" FocusVisualStyle="{x:Null}" Foreground="Brown" FontSize="16px" Grid.ColumnSpan="2"></Label>
            <Label Height="28" Margin="0,24,153,0" Name="label11" VerticalAlignment="Top" FocusVisualStyle="{x:Null}" Grid.Column="1" Foreground="Brown" FontSize="16px" HorizontalAlignment="Right" Width="215"></Label>
            <Label Height="28" Margin="0,69,153,0" Name="label12" VerticalAlignment="Top" FocusVisualStyle="{x:Null}" Grid.Column="1" Foreground="Brown" FontSize="16px" HorizontalAlignment="Right" Width="215"></Label>
            <Label Height="28" Margin="0,112,153,0" Name="label13" VerticalAlignment="Top" FocusVisualStyle="{x:Null}" Grid.Column="1" Foreground="Brown" FontSize="16px" HorizontalAlignment="Right" Width="215"></Label>
            <Label Height="28" Margin="0,153,153,0" Name="label14" VerticalAlignment="Top" FocusVisualStyle="{x:Null}" Grid.Column="1" Foreground="Brown" FontSize="16px" HorizontalAlignment="Right" Width="215"></Label>
            <Label Height="28" Margin="0,197.717,153,0" Name="label15" VerticalAlignment="Top" FocusVisualStyle="{x:Null}" Grid.Column="1" Foreground="Brown" FontSize="16px" HorizontalAlignment="Right" Width="215"></Label>
            <Label Margin="0,242.717,153,229.283" Name="label16" FocusVisualStyle="{x:Null}" Grid.Column="1" Foreground="Brown" FontSize="16px" HorizontalAlignment="Right" Width="215"></Label>
         
    
  • 相关阅读:
    Laravel 初始化
    ant design pro 左上角 logo 修改
    请求到服务端后是怎么处理的
    Websocket 知识点
    王道数据结构 (7) KMP 算法
    王道数据结构 (6) 简单的模式匹配算法
    王道数据结构 (4) 单链表 删除节点
    王道数据结构 (3) 单链表 插入节点
    王道数据结构 (2) 单链表 尾插法
    王道数据结构 (1) 单链表 头插法
  • 原文地址:https://www.cnblogs.com/wandd/p/2704051.html
Copyright © 2011-2022 走看看