Results 1 to 8 of 8

Thread: Keeping an image persistent in a User Control

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2017
    Posts
    554

    Keeping an image persistent in a User Control

    My user control contains an image loaded through a public property I added to the control called Picture1 at design time.

    Here's the code from the user control:

    Code:
      '
      '
    Private mPicture1 As StdPicture    
      '
      '
      '
    Public Property Get Picture1() As StdPicture
     Set Picture1 = mPicture1
    End Property
    
    Public Property Set Picture1(ByVal RHS As StdPicture)
     Set mPicture1 = RHS
        
     Set MaskPicture = mPicture1
     Set Picture = mPicture1
        
     PropertyChanged "Picture1"
    End Property
    
    Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
     If Ambient.UserMode Then
       BackStyle = 0                   ' = Transparent.
       MaskColor = vbRed
       Set MaskPicture = Picture
     End If
    
     With PropBag
       Set Picture1 = .ReadProperty("Picture1", Nothing)
     End With
    End Sub
    
    Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
     With PropBag
       .WriteProperty "MaskColor", MaskColor, vbButtonFace
       .WriteProperty "Picture1", Picture1, Nothing
     End With
    End Sub
    During the course of the running program the user can click on the control to rotate the image. User can do this as many times as he wishes each time rotating the image by 90 degrees from the previous angle. I need to keep the rotated image at the current rotation each time the program is loaded so if user rotated the image by 180 then when the program is loaded up again that image should appear at the same location and the same angle of rotation. Right now I am asking for only about the rotation. I will deal with the location later unless someone knows how I can do this also.

    Is there a way in the user control to keep the image persistent from one time to another.

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Keeping an image persistent in a User Control

    Instead, I'd recommend caching the rotation and reading it in ReadProperties, then apply the rotation. Same for positions. You just add extra properties and read them as needed, i.e.,

    Private mRotation As Long ' values of 0, 90, 180, 270
    Private mLocationX As Single
    Private mLocationY As Single
    etc

    Then you would save them in your WriteProperties event & read them in ReadProperties
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Keeping an image persistent in a User Control

    Quote Originally Posted by LaVolpe View Post
    Then you would save them in your WriteProperties event & read them in ReadProperties
    I think he is asking about persisting run time changes between runs. The design time PropertyBag won't help, at run time it is writable but won't be magically persisted back into the EXE.

  4. #4
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Keeping an image persistent in a User Control

    There's a lot of other chaos there that probably should be cleaned up early before the monster egg hatches and threatens the entire house of cards.

    Why have a Picture1 property and the extraneous object reference mPicture1? Just make a Picture property that uses UserControl.Picture as its backing store.

    I think people get confused about namespaces. In a UserControl you have the UserControl object and the Me object. If you define a member on Me it takes precedence over UserControl in the module-level namespace. So if you define a Picture property (a member of the class and therefore of Me) you must reference UserControl.Picture with full qualification if you want to touch UserControl.Picture.

    No big deal though. It has worked this way for 20 years.

  5. #5
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: Keeping an image persistent in a User Control

    Yep, will need to use a config file or reg entry or something of the sort to save and reload settings.

  6. #6
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Keeping an image persistent in a User Control

    I thought he had 5000 puzzle pieces or something. Starting to sound like a job for a random file at least if not a database.

  7. #7
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: Keeping an image persistent in a User Control

    Yes if there are a lot of them then a db would be a reasonable choice as may a random file.
    From the OP I assumed it was just talking about 1 which would be fine in a config or reg entry but more than a small handful calls for something more.

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2017
    Posts
    554

    Re: Keeping an image persistent in a User Control

    I guess I had the wrong idea about using that approach as it doesn't really do what I thought it would do so I finally just created a text file to store the information. Now when user runs the app nothing is shown until he presses a button that says Load Game. A dialogue box pops up and lists all the games that have been saved. He selects the one he wants and the program reads in that file, parses it and pulls out the image links, X, Y and rotate values then loads up additional user controls and creates new controls with the image, moves them to their correct Left and Top and then rotates them. The user now sees his game exactly as he last saw it when it was saved

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width