Solved

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

Posted on 1998-09-01
12
369 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
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

Industry Leaders: 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!

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

751 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