how add a [property] as dialogbox
-
I need to create a property for my custom control visible in visual studio property grid. But if i click on in it open a openfiledialog to serch a path as BackgroundImage for a picturebox. How can i do? I've tryed with [Browsable(true)] but it doesn't work.
-
I need to create a property for my custom control visible in visual studio property grid. But if i click on in it open a openfiledialog to serch a path as BackgroundImage for a picturebox. How can i do? I've tryed with [Browsable(true)] but it doesn't work.
Use a filtered UI Type Editor:
...
// Reference: System.Design.dll
using System.Drawing.Design;
using System.Windows.Forms.Design;...
internal class MyFileNameEditor : FileNameEditor
{
protected override void InitializeDialog(OpenFileDialog openFileDialog)
{
base.InitializeDialog (openFileDialog);
openFileDialog.Filter = "JPEG Files (*.jpg)|*.jpg|All Files (*.*)|*.*";
}
}...
[EditorAttribute(typeof(MyFileNameEditor), typeof(UITypeEditor))]
public string PictureBoxBackgroundImage
{
get { return m_bgImagePath; }
set
{
m_bgImagePath = value;
Image bgImage = Image.FromFile(m_bgImagePath);
// should do some Image creation error checking here
this.thePictureBox.BackgroundImage = bgImage;
}
}-- I've killed again, haven't I?
-
Use a filtered UI Type Editor:
...
// Reference: System.Design.dll
using System.Drawing.Design;
using System.Windows.Forms.Design;...
internal class MyFileNameEditor : FileNameEditor
{
protected override void InitializeDialog(OpenFileDialog openFileDialog)
{
base.InitializeDialog (openFileDialog);
openFileDialog.Filter = "JPEG Files (*.jpg)|*.jpg|All Files (*.*)|*.*";
}
}...
[EditorAttribute(typeof(MyFileNameEditor), typeof(UITypeEditor))]
public string PictureBoxBackgroundImage
{
get { return m_bgImagePath; }
set
{
m_bgImagePath = value;
Image bgImage = Image.FromFile(m_bgImagePath);
// should do some Image creation error checking here
this.thePictureBox.BackgroundImage = bgImage;
}
}-- I've killed again, haven't I?