Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用C 2010 Express实现类似网格的控件_C#_Controls - Fatal编程技术网

C# 如何使用C 2010 Express实现类似网格的控件

C# 如何使用C 2010 Express实现类似网格的控件,c#,controls,C#,Controls,我需要这样一个控件: 这来自Microsoft Word:Insert=>符号 此对话框有一个类似网格的控件,带有Unicode字符列表; 您可以选择任何字符; 将显示选定字符的Unicode; 用户不能编辑字符; 此外,我需要扩展它的功能: 1.用户可以删除选中字符的单元格; 2.用户可以添加文件中的字符列表或其他内容 我在问我应该使用什么内置控件来实现这个特定控件 谢谢 Peter在WinForms中,您可以在运行时将固定大小的标签控件添加到FlowLayoutPanel 请注意,这不会很好

我需要这样一个控件:

这来自Microsoft Word:Insert=>符号

此对话框有一个类似网格的控件,带有Unicode字符列表; 您可以选择任何字符; 将显示选定字符的Unicode; 用户不能编辑字符; 此外,我需要扩展它的功能: 1.用户可以删除选中字符的单元格; 2.用户可以添加文件中的字符列表或其他内容

我在问我应该使用什么内置控件来实现这个特定控件

谢谢


Peter

在WinForms中,您可以在运行时将固定大小的标签控件添加到FlowLayoutPanel

请注意,这不会很好地扩展;不要制作数千个标签控件。
如果需要大量字符,可以在一个屏幕上显示标签,然后添加滚动条控件并处理滚动事件以更改标签标题。

我可以使用标准控件创建一个简单的模型


WinForms?WPF?ASP.Net?Silverlight?谢谢你的回复。我实际上是在尝试DataGridView,它看起来不错。第一个问题是:如果要删除其中一个字符,则该字符之后的所有字符都需要移动;第二个问题是:如果控件的宽度更改,则很难增加列数,因为它是一个二维控件FlowLayoutPanel,在这种情况下效果会更好,但由于其他问题,FlowLayoutPanel不是最佳选择。无论如何,我将再次尝试您的建议。使用DataGridView的UI外观和事件处理似乎是最佳选择:-我使用DataGridView实现。到目前为止,看起来还不错。我有个问题:如何不显示空白单元格?假设只有20个字符,但一行必须有16个字符,因此第二行只能有4个字符。但我不知道如何不显示额外的12个空白单元格。谢谢。我也试着使用FlowLayoutPanel,但是有很多东西我必须自己实现:比如箭头键移动、选择。。。。
private void InitilizeDataGridView(DataGridView view)
{
    var defaultCellStyle = new DataGridViewCellStyle();

    defaultCellStyle.ForeColor = SystemColors.ControlText;
    defaultCellStyle.WrapMode = DataGridViewTriState.False;
    defaultCellStyle.SelectionBackColor = SystemColors.Highlight;
    defaultCellStyle.BackColor = System.Drawing.SystemColors.Window;
    defaultCellStyle.SelectionForeColor = SystemColors.HighlightText;
    defaultCellStyle.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
    defaultCellStyle.Font = new Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((0)));

    view.DefaultCellStyle = defaultCellStyle;

    view.MultiSelect = false;
    view.RowHeadersVisible = false;
    view.AllowUserToAddRows = false;
    view.ColumnHeadersVisible = false;
    view.AllowUserToResizeRows = false;
    view.AllowUserToDeleteRows = false;
    view.AllowUserToOrderColumns = true;
    view.AllowUserToResizeColumns = false;

    view.BackgroundColor = SystemColors.Control;

    for(var i = 0; i < 16; i++)
    {              
        view.Columns.Add(new DataGridViewTextBoxColumn { AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill, Resizable = DataGridViewTriState.False });
    }

    DataGridViewRow row = null;

    for (int index = 32, cell = 0; index < 255; index++, cell++)
    {
        if(cell % 16 == 0)
        {
            if(row != null)
            {
                view.Rows.Add(row);
            }

            row = new DataGridViewRow { Height = 40 };
            row.CreateCells(view);

            cell = 0;
        }

        if (row != null)
        {
            row.Cells[cell].Value = Char.ConvertFromUtf32(index);
        }               
    }            
}