Solved

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

Posted on 1998-09-01
12
364 Views
Last Modified: 2008-03-17
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
0
Comment
Question by:HATCHET
  • 7
  • 3
  • 2
12 Comments
 
LVL 14

Expert Comment

by:waty
ID: 1432312
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
 
LVL 3

Author Comment

by:HATCHET
ID: 1432313
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
 
LVL 14

Expert Comment

by:waty
ID: 1432314
I think, it returns you the path of the picture, you have to use loadpicture(path) for your picturebox
0
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.

 
LVL 3

Author Comment

by:HATCHET
ID: 1432315
waty,

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

thx,

HATCHET
0
 
LVL 3

Author Comment

by:HATCHET
ID: 1432316
Adjusted points to 125
0
 
LVL 2

Expert Comment

by:marti
ID: 1432317
HATCHET, you have to use either PictureLocation or Picture, not both.
0
 
LVL 3

Author Comment

by:HATCHET
ID: 1432318
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
 
LVL 2

Accepted Solution

by:
marti earned 120 total points
ID: 1432319
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
 
LVL 3

Author Comment

by:HATCHET
ID: 1432320
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
 
LVL 2

Expert Comment

by:marti
ID: 1432321
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
 
LVL 3

Author Comment

by:HATCHET
ID: 1432322
Thanks again, marti.  I'll use the Common Dialog Controls on a Properties Page.

HATCHET
0
 
LVL 3

Author Comment

by:HATCHET
ID: 2083283
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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

838 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question