加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

如何在checkedListBox C#中的同一行上填充两个字符串?

发布时间:2020-12-15 23:40:54 所属栏目:百科 来源:网络整理
导读:我有多个看起来像这样的字符串:“MyApp.exe”和其他像这样:“0x1234567A”. 当然,尺寸各不相同. 我想将它们排列在checkedListBox中的一行上. 我使用以下代码: processes_checkedListBox.Items.Add(element[1] + element[2],false); 元素[1]具有“MyApp.ex
我有多个看起来像这样的字符串:“MyApp.exe”和其他像这样:“0x1234567A”.

当然,尺寸各不相同.

我想将它们排列在checkedListBox中的一行上.

我使用以下代码:

processes_checkedListBox.Items.Add(element[1] + element[2],false);

元素[1]具有“MyApp.exe”和元素[2]“0x1234567A”.

因此,如果我应用该代码,结果就是这样的,显然:

MyApp.exe0x1234567A
MyOtherApp.exe0x1234567B

我试过这个:

processes_checkedListBox.Items.Add(element[1] + element[2].PadLeft(5,' '),false);

这个案例的结果如下:

MyApp.exe     0x1234567A
MyOtherApp.exe     0x1234567B

如果我将填充应用于左侧,则结果与第一个相同.
同样,如果我在第一个元素的右侧应用填充.
字体是默认的checkedListBox,没有任何改变,
填充是40个空格,我插入5以上就是一个例子.

理想的结果当然应该是:

MyApp.exe        0x1234567A
MyOtherApp.exe   0x1234567B

我不知道怎么做,有什么建议吗?
(.NET 4.5 Framework和MVS 2015 – Windows窗体应用程序)

稍后编辑

private void Display_Processes_Button_Click(object sender,EventArgs e)
    {
        processes_checkedListBox.Items.Clear();

        string test = File.ReadAllText("test.txt");
        string[] testArray = test.Split('n');

        for (int i = 3; i < testArray.Length-1; ++i)
        {
            string[] element = testArray[i].Split('|');
            element[1] = element[1].Trim();
            element[2] = element[2].Trim();

            processes_checkedListBox.Items.Add(string.Format("{0,-20} {1,-20}",element[1],element[2]),false);
        }
    }

这是我的实际代码,我正在从包含以下内容的文件中读取信息:

+----------------------------------------+-----------+
|             Process Name               | PID       |
+----------------------------------------+-----------+
| securityAccessModule.exe               | 0x127F003A|
| CMD.EXE                                | 0x77430012|
| ps.exe                                 | 0x77010062|
+----------------------------------------+-----------+

虽然我已经尝试过您的解决方案,但我仍然无法使其工作.我在控制台看到它工作正常.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读