• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 352
  • Last Modified:

Open the File Open from Properties

Hi,

I have a PropertyGrid in my form. I have a Image property there, like standard Image property we have in our IDE for forms, PictureBox etc.

I am needing to invoke/open the file(image) browser from my code during runtime. How can I do that?

thank you.
0
jr_barros_jr
Asked:
jr_barros_jr
  • 9
  • 9
  • 4
  • +1
1 Solution
 
Meir RivkinFull stack Software EngineerCommented:
if u have the file path, just use Process.Start("YOUR_FILE_PATH").
if u rather open the image with specific applciation, fro example mspaint, try this:
Process.Start("mspaint","YOUR_FILE_PATH").
0
 
jr_barros_jrAuthor Commented:
I do not think that your solutions apply to me. Perhaps, It is my fault. I will explain better.

I want to provide the user two different options to open an image. One is from 3 dots button from Image property and the second one is from a Button in my form. When the user click in my button, a file dialog is opened. Besides that, when the user click in 3 dots button from Image property another fiel dialog is opened, but this one is not from my code.

To avoid 2 diffrents file dialog, I would like to invoke/call 3 dots button from Image property from my button event code.

How can I do that?
0
 
deicidedxCommented:
Can you post some code or some screen shots please ? I really can;t figure out what do you need !!
Thanks
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
jr_barros_jrAuthor Commented:
I am attaching the the image that I hope could help to understand my problem.
The "red drawings" represents my "Open Image Button" and my source code. the "orange drawings" represents "3 Dots Image button" that I want to invoke/call using code during runtime instead of use "OpenFileDialog".

ExpEx.png
0
 
deicidedxCommented:
But those are not different dialogs. Its the same dialog box !!! Only different paths ....
0
 
magicdlfCommented:
Take a close look at upper right corner. What he want is when he clicks the "..." button, a customized open file dialog popups.
0
 
magicdlfCommented:
The point is which event in propertygrid will be triggered when he clicks the "..."?
0
 
jr_barros_jrAuthor Commented:
Dear deicidedx,

I know how to use a open file dialog (as you can see, my Open button show a open file dialog, please, see attached picture some messages above - red drawings on right hand side).

I want to trig/start the "..." button event by code during runtime.

I do NOT want to learn how to open a file dialog.
0
 
deicidedxCommented:
I'm not very sure but i think its not possible to overwrite the event triggered when the 3 dots button is clicked. but you can add a custom property to the property grid and handle its events as you like.
0
 
magicdlfCommented:
hi jr_barros_jr,
you might be interested in looking at this one: http://www.codeproject.com/KB/vb/Propertygrid_Editor.aspx
This question is interesting, I am going to build a solution myself. Hopefully I will be quicker than you. : )
0
 
jr_barros_jrAuthor Commented:
Dear deicidedx,

About "you can add a custom property to the property grid and handle its events as you like" I am already doing that until I will find a solution.

Thank you.
0
 
magicdlfCommented:
Hi,
Actually this one is helping:
http://dotnetfacts.blogspot.com/2008/05/how-to-take-control-over-collection.html
I am attaching my working code now.
0
 
magicdlfCommented:
http://social.msdn.microsoft.com/forums/en-US/winformsdesigner/thread/14381722-6783-424c-b063-a1d85c42b5c2

Here are my working code:

        class myclass
        {
            private int _id;
            private string _path;
            [Browsable(true)]
            public int Id
            {
                get { return _id; }
                set { _id = value; }
            }
            [Editor(typeof(FilteredFileNameEditor), typeof(System.Drawing.Design.UITypeEditor))]
            public string Path
            {
                get { return _path; }
                set { _path = value; }
            }
        }
 
        internal class FilteredFileNameEditor : UITypeEditor
        {
            private OpenFileDialog ofd = new OpenFileDialog();
            public override UITypeEditorEditStyle GetEditStyle(
             ITypeDescriptorContext context)
            {
                return UITypeEditorEditStyle.Modal;
            }
            public override object EditValue(
             ITypeDescriptorContext context,
             IServiceProvider provider,
             object value)
            {
                //ofd.FileName = value.ToString();
                ofd.Filter = "Text File|*.txt|All Files|*.*";
                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    return ofd.FileName;
                }
                return base.EditValue(context, provider, value);
            }
        }

Hope this will help. Happy coding. : ) I also learned a lot from this topic.
 
Regards,
magicdlf
0
 
jr_barros_jrAuthor Commented:
Dear magicdlf,

First of all, thank you so much for your answer. It is interesting your approach. Instead of call '...' button you are proposing to '...' call my function.

Do you know how can I call the original "EditValue" function from my code?

How fo set the input parameters? Any clue?

Thank you.
0
 
magicdlfCommented:
Can you please let me see what you have? To be honest, I don't understand why do you want to call the "EditValue" function.
0
 
jr_barros_jrAuthor Commented:
I would like to use the "..." button dialog box. I would like to avoid to create mine. Thus, I will have always the "most updated" image dialgo box which follows FrameWork and I do NOT need to change my code to reflect that.

Could I explain myself?
0
 
magicdlfCommented:
Change this to your dialog box didn't help?
private OpenFileDialog ofd = new OpenFileDialog();
0
 
magicdlfCommented:
Just apply the code, in the EditValue function, you can do anything you want to popup the dialogs. What kind of dialog do you have?
0
 
jr_barros_jrAuthor Commented:
I know that I have apply the code in EditValue function. But I would like to avoid that.

My dialog is Image Browser, but create it is not a problem. The problem is keep all my application update after a new "Image Open Window" is released. I would like to avoid that.
0
 
magicdlfCommented:
So what do you want? You can also focus to your Image Browser, make a EventHandler to notify it, and retrieve the data back and set for EditValue. I am afraid I can't provide more suggestions unless I can see your Image Browser
0
 
jr_barros_jrAuthor Commented:
Dear magicdlf,

I do appreciate your help and your answer. It's a solution. Do not worry. I am just trying to fit it better in my scenario/applications.

0
 
jr_barros_jrAuthor Commented:
Thank you.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 9
  • 9
  • 4
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now