Add User Control Image Property
Add User Control Image Property
Add User Control Image Property
Add User Control Image Property
Add User Control Image Property
Add User Control Image Property Add User Control Image Property Add User Control Image Property Add User Control Image Property Add User Control Image Property Add User Control Image Property Add User Control Image Property Add User Control Image Property
Add User Control Image Property Add User Control Image Property
Add User Control Image Property
Go Back  Xtreme Visual Basic Talk > > > Add User Control Image Property


Reply
 
Thread Tools Display Modes
  #1  
Old 01-26-2014, 07:46 PM
VB_Alien VB_Alien is offline
Senior Contributor
 
Join Date: Apr 2004
Posts: 854
Default Add User Control Image Property


I'm making a control that requires an image and a background
image property. A user control only has a background image
property.

I tried adding a public Image property to the control and i'm
trying to draw the image to the control like this:

Code:
 Public Property Image As Image
        Get
            Return _Image
        End Get

        Set(value As Image)
            _Image = value

            Dim MyBitmap As Bitmap = New Bitmap(_Image)
            Dim g As Graphics = Me.CreateGraphics

            g.DrawImage(MyBitmap, 0, 0, _Image.Width, _Image.Height)

            Me.Invalidate()
        End Set
    End Property
Could you tell me if i am doing this right?
Is it possible to add an image property to a control that
doesn't have one?

I've got another way to go about doing this but it would
require me using a picturebox on top of the user control
and i'd rather use just one control, if possible.
Reply With Quote
  #2  
Old 01-27-2014, 11:29 AM
VB_Alien VB_Alien is offline
Senior Contributor
 
Join Date: Apr 2004
Posts: 854
Default

For now, i got my image property to work by
using the same code in the paint event of the
user control.

Code:
  If Image Is Nothing Then
        Else
            Dim g As Graphics = Me.CreateGraphics
            g.DrawImage(Image, 0, 0, _Image.Width, _Image.Height)
        End If
Instead of creating a bitmap from my image property, i'm
just using the image property itself as the source image.
Reply With Quote
  #3  
Old 01-27-2014, 12:02 PM
Gruff's Avatar
GruffAdd User Control Image Property Gruff is offline
Bald Mountain Survivor

Retired Moderator
* Expert *
 
Join Date: Aug 2003
Location: Oregon, USA - deceased
Posts: 6,440
Default

If you do not draw from some paint event then the image will not persist.
__________________
Burn the land and boil the sea
You can't take the sky from me


~T
Reply With Quote
  #4  
Old 01-27-2014, 03:00 PM
VB_Alien VB_Alien is offline
Senior Contributor
 
Join Date: Apr 2004
Posts: 854
Default

That is what i found out. The image would appear when i loaded
an image while still in design mode but as soon as i moved the control,
the image disappeared.

That's when i decide to load the image from the control paint event.

Now, it's working.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Add User Control Image Property
Add User Control Image Property
Add User Control Image Property Add User Control Image Property
Add User Control Image Property
Add User Control Image Property
Add User Control Image Property Add User Control Image Property Add User Control Image Property Add User Control Image Property Add User Control Image Property Add User Control Image Property Add User Control Image Property
Add User Control Image Property
Add User Control Image Property
 
Add User Control Image Property
Add User Control Image Property
 
-->