Question

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

Was it helpful?

Solution

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;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top