| |

VerySource

 Forgot password?
 Register
Search
View: 753|Reply: 5

Why can't self-made controls store image properties?

[Copy link]

2

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-1-16 14:20:01
| Show all posts |Read mode
Create a control, put two image controls image1 and image2 on it

Use the wizard to build the attributes pic0 and pic1, and map them to the picture attributes of image1 and image2, respectively. The following code is automatically generated. At design time, the attributes of pic0 and pic1 (bmp picture) are formulated. Nothing, after opening and saving, the picture also disappears. The automatically generated code is as follows. The master can help me to see what went wrong?

Option Explicit

'note! Do not delete or modify the following commented lines!
'MappingInfo = Image1, Image1, -1, Picture
Public Property Get Pic0 () As Picture
    Set Pic0 = Image1.Picture
End Property

Public Property Set Pic0 (ByVal New_Pic0 As Picture)
    Set Image1.Picture = New_Pic0
    PropertyChanged "Pic0"
End Property

'note! Do not delete or modify the following commented lines!
'MappingInfo = Image2, Image2, -1, Picture
Public Property Get Pic1 () As Picture
    Set Pic1 = Image2.Picture
End Property

Public Property Set Pic1 (ByVal New_Pic1 As Picture)
    Set Image2.Picture = New_Pic1
    PropertyChanged "Pic1"
End Property

'Load attribute values ​​from memory
Private Sub UserControl_ReadProperties (PropBag As PropertyBag)

    Set Picture = PropBag.ReadProperty ("Pic0", Nothing)
    Set Picture = PropBag.ReadProperty ("Pic1", Nothing)
End Sub

'Write attribute value to memory
Private Sub UserControl_WriteProperties (PropBag As PropertyBag)

    Call PropBag.WriteProperty ("Pic0", Picture, Nothing)
    Call PropBag.WriteProperty ("Pic1", Picture, Nothing)
End Sub
Reply

Use magic Report

0

Threads

11

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

Post time: 2020-1-24 20:00:01
| Show all posts
Modify the following code:
Private Sub UserControl_ReadProperties (PropBag As PropertyBag)

    Set Image1.Picture = PropBag.ReadProperty ("Pic0", Nothing)
    Set Image2.Picture = PropBag.ReadProperty ("Pic1", Nothing)
End Sub

'Write attribute value to memory
Private Sub UserControl_WriteProperties (PropBag As PropertyBag)

    Call PropBag.WriteProperty ("Pic0", Image1.Picture, Nothing)
    Call PropBag.WriteProperty ("Pic1", Image2.Picture, Nothing)
End Sub
Reply

Use magic Report

0

Threads

11

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

Post time: 2020-1-26 10:09:01
| Show all posts
Rewrite the following code:

Private Sub UserControl_ReadProperties (PropBag As PropertyBag)

    Set Image1.Picture = PropBag.ReadProperty ("Pic0", Nothing)
    Set Image2.Picture = PropBag.ReadProperty ("Pic1", Nothing)
End Sub

'Write attribute value to memory
Private Sub UserControl_WriteProperties (PropBag As PropertyBag)

    Call PropBag.WriteProperty ("Pic0", Image1.Picture, Nothing)
    Call PropBag.WriteProperty ("Pic1", Image2.Picture, Nothing)
End Sub
Reply

Use magic Report

2

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 Cote D'Ivoire

 Author| Post time: 2020-2-5 06:00:01
| Show all posts
I have mapped the attributes to image1 and image2, why isn't the correct code automatically generated?
Reply

Use magic Report

0

Threads

34

Posts

17.00

Credits

Newbie

Rank: 1

Credits
17.00

 China

Post time: 2020-2-7 13:15:01
| Show all posts
Option Explicit

'note! Do not delete or modify the following commented lines!
'MappingInfo = Image1, Image1, -1, Picture
Public Property Get Pic0 () As Picture
Set Pic0 = Image1.Picture
End Property

Public Property Set Pic0 (ByVal New_Pic0 As Picture)
Set Image1.Picture = New_Pic0
PropertyChanged "Pic0"
End Property

'note! Do not delete or modify the following commented lines!
'MappingInfo = Image2, Image2, -1, Picture
Public Property Get Pic1 () As Picture
Set Pic1 = Image2.Picture
End Property

Public Property Set Pic1 (ByVal New_Pic1 As Picture)
Set Image2.Picture = New_Pic1
PropertyChanged "Pic1"
End Property

'Load attribute values ​​from memory
Private Sub UserControl_ReadProperties (PropBag As PropertyBag)

Set Picture = PropBag.ReadProperty ("Pic0", Nothing)
Set Picture = PropBag.ReadProperty ("Pic1", Nothing)
End Sub

'Write attribute value to memory
Private Sub UserControl_WriteProperties (PropBag As PropertyBag)

Call PropBag.WriteProperty ("Pic0", Pic0, Nothing)
Call PropBag.WriteProperty ("Pic1", Pic1, Nothing)
End Sub
Reply

Use magic Report

0

Threads

11

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

Post time: 2020-2-16 15:45:01
| Show all posts
The control wizard is just an auxiliary tool. It does save us a lot of time in writing repetitive code, but in fact there are still many shortcomings. Many times we need to manually rewrite the code it generates. Don't rely too much on it.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list