本文整理汇总了C#中System.Windows.Forms.TableLayoutPanel.FindForm方法的典型用法代码示例。如果您正苦于以下问题:C# TableLayoutPanel.FindForm方法的具体用法?C# TableLayoutPanel.FindForm怎么用?C# TableLayoutPanel.FindForm使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.TableLayoutPanel
的用法示例。
在下文中一共展示了TableLayoutPanel.FindForm方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ChoiceView
/// <summary>
/// Construct a view with the given options
/// </summary>
public ChoiceView(IEnumerable<string> optionsStrings)
: base()
{
var options = optionsStrings.ToIArray();
// we'll use this tooltip to display mouseover shortcuts for the buttons
var tooltip = this.RegisterDisposable(new ToolTip());
// a panel to hold all controls created by the view
var panel = this.RegisterDisposable(new Panel() { Dock = DockStyle.Fill });
// a table to hold the buttons (TODO change this to use the GUIUtils convenience methods for creating tables)
var table = new TableLayoutPanel() { Dock = DockStyle.Fill, RowCount = 1, ColumnCount = options.Count };
// a list of the click-handler functions for each button
var handlerList = new List<KeyPressEventHandler>();
// this variable will later be filled in with the current form
Form form = null;
// create each button
for (int i = 0; i < table.ColumnCount; i++)
{
// divide the width equally between all buttons
table.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 1.0f / table.ColumnCount));
// create a button for the option
var button = GUIUtils.CreateFlatButton(
options[i],
// when the button is clicked, set this view's result to the text of the button and finish
b => { this.SetResult(b.Text); this.Finish(); },
tooltip,
// the mouseover text depends on the current index
i < HOME_ROW.Length ? "Shortcut: " + HOME_ROW[i] : "No shortcut"
);
button.Font = GUIUtils.Constants.DISPLAY_FONT;
// register a keypad shortcut
if (i < HOME_ROW.Length)
{
char keyChar = HOME_ROW[i];
handlerList.Add((sender, args) =>
{
// when the key for the button is pressed, fire a button click event
if (args.KeyChar == keyChar)
button.PerformClick();
});
}
// ensures that the buttons don't steal the form's key-presses!
// unfortunately, both of these "solutions" seem to cause other issues, so they're staying commented out
//button.KeyPress += (sender, args) => handlerList.ForEach(h => h(form ?? sender, args));
//button.GotFocus += (sender, args) => button.FindForm().Focus();
button.KeyPress += handlerList.LastItem();
// add the button to the table
table.Controls.Add(button, i, 0);
}
/*
* This is just here so that we can register the keypad shortcuts at the form level.
* There's no form available when the view is being constructed, but when it's being displayed
* we can find one with the FindForm() method. The paint event won't be fired until that point
*/
table.Paint += (sender, args) =>
{
// don't do anything if we've already found a form or can't find one
if (form != null || (form = table.FindForm()) == null)
return;
// register our key press handlers with the form
foreach (var handler in handlerList)
form.KeyPress += handler;
};
// when the view finishes, we need to un-register the key press handlers so they don't affect future views
this.DoOnFinishing(() =>
{
if (form != null)
foreach (var handler in handlerList)
form.KeyPress -= handler;
});
// add the button table to the panel
panel.Controls.Add(table);
// create a label to display the view's text, if there is any
var label = this.RegisterDisposable(new Label() { Dock = DockStyle.Top, TextAlign = System.Drawing.ContentAlignment.MiddleCenter, Font = GUIUtils.Constants.DISPLAY_FONT });
// when the view deploys, install its controls
this.DoOnDeploy(c =>
{
// if we have text to display, set up the label. We can't do this before deploying because
// the text property can be changed between calling the view constructor and deploying the
// view
if (!string.IsNullOrEmpty(this.Text))
{
//.........这里部分代码省略.........