ActiveX Control Creation - "Open File Dialog Box" in properties settings ?

Hello,

I'm a fairly experienced Visual Basic 5.0 programmer that is just getting the hang of ActiveX Control Creation.  I've figured out that to set the color property of your control that you can declare your Let/Get property statements "As OLE_COLOR" and when you've made your OCX / ActiveX and are using it at design time, all you have to do is click on the ChangeColor perperty you made and you have a nice, neat color picker there for you to select a color visually, instead of having to put in the HEX code for the color.

My question is : if you want to pop up a "File Open Dialog Box" so that the user can set a file location of say a picture for the control you're creating, they can click on the property of the .OCX / ActiveX and it will bring up the "File Open Dialog Box" just like when you click on the "Picture" property of a PictureBox and it will let you
locate the picture file you wish to display in the PictureBox, how do you declare that ?  Is there an "As" statement that you just implement similar to the "As OLE_COLOR" that will give you that ?  I've not been able to locate it if there is.

Please Help...

Thanks,

HATCHET
LVL 3
HATCHETAsked:
Who is Participating?
 
martiConnect With a Mentor Commented:
This should work:

Private msPictureLocation as String

Public Property Get PictureFile() As String
  PictureFile = msPictureLocation
End Property

Public Property Let PictureFile(ByVal NewLocation As String)
  msPictureLocation = NewLocation
  picPicture.Picture = LoadPicture(msPictureLocation)
  PropertyChanged "PictureFile"
End Property

0
 
watyCommented:
You declare it as PICTURE :
Public Property Get toto() As Picture
   Set toto = m_toto
End Property

Public Property Set toto(ByVal New_toto As Picture)
   Set m_toto = New_toto
   PropertyChanged "toto"
End Property


0
 
HATCHETAuthor Commented:
waty,

I took your idea of declaring it as a Picture, but it didn't work.  Here's what I tried:


Public Property Get PictureLocation() As Picture

  PictureLocation = picPicture.Picture

End Property

Public Property Let PictureLocation(ByVal NewPic As Picture)

  picPicture.Picture = NewPic
  PropertyChanged "PictureLocation"

End Property


Here the property name is PictureLocation and the PictureBox object in the ActiveX control that I'm trying to set the property for is picPicture.  When I run the code, it will either give me a compile error "Invalid use of property", and/or will not show up in the Properties Windows so that you can set it at Design Time.  I don't think that declaring it as "Picture" is the answer, or I missed something.

=(

0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
watyCommented:
I think, it returns you the path of the picture, you have to use loadpicture(path) for your picturebox
0
 
HATCHETAuthor Commented:
waty,

I don't understand what you're getting at.  Could you maybe provide a sample snipit of code to illustrate?

thx,

HATCHET
0
 
HATCHETAuthor Commented:
Adjusted points to 125
0
 
martiCommented:
HATCHET, you have to use either PictureLocation or Picture, not both.
0
 
HATCHETAuthor Commented:
marti,

I took your advice and tried to define the property I'm trying to get to work as "PictureLocation" and put in the following code:


Public Property Get PictureFile() As PictureLocation
  PictureFile = picPicture.PictureLocation
End Property

Public Property Let PictureFile(ByVal NewLocation As PictureLocation)
  picPicture.PictureLocation = NewLocation
  PropertyChanged "PictureFile"
End Property


It didn't work.  It gave me the error :  

Compile error:
User-defined type not defined

Can you clerify a bit maybe, or correct my code here If I'm doing something wrong ?

Thank you,

HATCHET
0
 
HATCHETAuthor Commented:
marti,

Your code DID work in that it displays the picture now whereas before it did not.  What I really wanted to was the ability to click on the little button in the Properties window with the caption "..." and have the Open File Dialog Box apear so that you could pick the file and not have to manually put the file in as a string.

If you could lemme know how to do that, that would be great and I'd add some points for the extra work.  Because your question did not FULLY answer my question, I'd be willing to give you 100 points if you just left it as is because you did give me an answer that I can work with.  Lemme know what you can do and I'll award the points accordingly.

Thanks again for the help!    =)

HATCHET
0
 
martiCommented:
Well, the easiest way is to use property page for that control. On that page you could add a botton and there you may call a Dialog so that the picture location could be specified.
0
 
HATCHETAuthor Commented:
Thanks again, marti.  I'll use the Common Dialog Controls on a Properties Page.

HATCHET
0
 
HATCHETAuthor Commented:
THE ANSWER IS... to declare the Get and Let statements as "StdPicture".  That will give you the picture open dialog when you click on that property.

HATCHET
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.