开发者

How Can I Implement the Grid-like Control Using C# 2010 Express

开发者 https://www.devze.com 2023-01-26 00:52 出处:网络
I need a control开发者_如何学编程 like this: This is from the Microsoft Word: Insert => Symbols.

I need a control开发者_如何学编程 like this:

How Can I Implement the Grid-like Control Using C# 2010 Express

This is from the Microsoft Word: Insert => Symbols.

  1. This dialog has a grid-like control with a list of Unicode Characters;
  2. You can select any character;
  3. The selected character's Unicode is displayed;
  4. User cannot edit the character;

Besides, I need to extend it's feature: 1. User can delete the cell with the selected character; 2. User can add a list of characters (from a file or whatever).

I'm asking what built-in controls I should use to implement this specific control.

Thanks.

Peter


I was able to create a simple mock up using the standard DataGridView control.

How Can I Implement the Grid-like Control Using C# 2010 Express

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);
        }               
    }            
}


In WinForms, you can add fixed-size Label controls to a FlowLayoutPanel at runtime.

Note that this will not scale well; do not make thousands of Label controls.
If you want large numbers of characters, you can make a single screenfull of labels, then add a ScrollBar control and handle the Scroll event to change the label captions.

0

精彩评论

暂无评论...
验证码 换一张
取 消