0

Consider a form with a TextBox and a Button. When you click that button you should get the Font properties dialog at run-time.

During designer you can click the button off to the right of the property in the PropertyGrid and get the editor window to manipulate the Font for this TextBox. During run-time, if you add a PropertyGrid to the form and point it to the TextBox you can also get the editor window.

How can I get this editor window at run-time through say, a button click without having a PropertyGrid on the form?

Though I've gotten the PropertyDescriptor and the UITypeEditor from this descriptor, I don't know what to call to get the instances of ITypeDescriptorContext and IServiceProvider when calling UITypeEditor.EditValue.

EDIT - Since I asked this problem of a control that has an easy solution, I've asked another question related to this topic: How to open the properties dialog for a Complex Property without a PropertyGrid at runtime

4

1 回答 1

1

You can use FontDialog to show the standard font dialog box:

new FontDialog().ShowDialog();

To read/write fonts:

var dlg = new FontDialog();
dlg.Font = textBox1.Font;
if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
    textBox1.Font = dlg.Font;
}
于 2012-11-29T13:30:27.493 回答