Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. extended picturebox

extended picturebox

Scheduled Pinned Locked Moved Visual Basic
graphicsquestionhelpannouncement
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • 2 Offline
    2 Offline
    2hdass
    wrote on last edited by
    #1

    Hi, i have been trying to create my own version of the picture box, i did this by first creating a user control and then using the keyword inherits System.Windows.Forms.PictureBox What i really want to do is that i wanna be able to create a button that is 50% transparent when mouse is no over it, and it will become opaque when the mouse hovers over it. I made it a picturebox because it will load a gif image from the resx file. I have overrided the OnPaint function so that it will display the image in the control, the layout is as following. I put this control on top of another PictureBox, and when I run it, it gives me a while box instead of displaying the image. I debugged it and find that the displaying of the image is fine until this onPaint is over, (i.e. when the pointer steps out of this method, and that the PictureBox underneath is displayed, this control will turn into a white box) How can i fix this?!:confused::confused: Thx Code: Protected Overrides Sub OnPaint(ByVal pe As PaintEventArgs) MyBase.OnPaint(pe) Dim g As Graphics = Me.CreateGraphics() g.Clear(Me.BackColor) '-------------------call image from resources --------- Dim myAssembly As System.Reflection.Assembly myAssembly = Me.GetType.Assembly ' Creates the ResourceManager. Dim myManager As New _ System.Resources.ResourceManager("PictureResizer.Images", _ myAssembly) Dim myImage As System.Drawing.Image myImage = CType(myManager.GetObject("flipccw"), _ System.Drawing.Image) '---------------------------------------------- Dim bitmap As Bitmap = New Bitmap(myImage) Dim clrMatrix As ColorMatrix = _ New ColorMatrix(New Single()() _ {New Single() {1, 0, 0, 0, 0}, _ New Single() {0, 1, 0, 0, 0}, _ New Single() {0, 0, 1, 0, 0}, _ New Single() {0, 0, 0, 0.5F, 0}, _ New Single() {0, 0, 0, 0, 1}}) Dim imgAttributes As ImageAttributes = New ImageAttributes() imgAttributes.SetColorMatrix(clrMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap) g.DrawImage(bitmap, New Rectangle(0, 0, Me.Width, Me.Height), _ 0, 0, bitmap.Width, bitmap.Height, _ GraphicsUnit.Pi

    D 1 Reply Last reply
    0
    • 2 2hdass

      Hi, i have been trying to create my own version of the picture box, i did this by first creating a user control and then using the keyword inherits System.Windows.Forms.PictureBox What i really want to do is that i wanna be able to create a button that is 50% transparent when mouse is no over it, and it will become opaque when the mouse hovers over it. I made it a picturebox because it will load a gif image from the resx file. I have overrided the OnPaint function so that it will display the image in the control, the layout is as following. I put this control on top of another PictureBox, and when I run it, it gives me a while box instead of displaying the image. I debugged it and find that the displaying of the image is fine until this onPaint is over, (i.e. when the pointer steps out of this method, and that the PictureBox underneath is displayed, this control will turn into a white box) How can i fix this?!:confused::confused: Thx Code: Protected Overrides Sub OnPaint(ByVal pe As PaintEventArgs) MyBase.OnPaint(pe) Dim g As Graphics = Me.CreateGraphics() g.Clear(Me.BackColor) '-------------------call image from resources --------- Dim myAssembly As System.Reflection.Assembly myAssembly = Me.GetType.Assembly ' Creates the ResourceManager. Dim myManager As New _ System.Resources.ResourceManager("PictureResizer.Images", _ myAssembly) Dim myImage As System.Drawing.Image myImage = CType(myManager.GetObject("flipccw"), _ System.Drawing.Image) '---------------------------------------------- Dim bitmap As Bitmap = New Bitmap(myImage) Dim clrMatrix As ColorMatrix = _ New ColorMatrix(New Single()() _ {New Single() {1, 0, 0, 0, 0}, _ New Single() {0, 1, 0, 0, 0}, _ New Single() {0, 0, 1, 0, 0}, _ New Single() {0, 0, 0, 0.5F, 0}, _ New Single() {0, 0, 0, 0, 1}}) Dim imgAttributes As ImageAttributes = New ImageAttributes() imgAttributes.SetColorMatrix(clrMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap) g.DrawImage(bitmap, New Rectangle(0, 0, Me.Width, Me.Height), _ 0, 0, bitmap.Width, bitmap.Height, _ GraphicsUnit.Pi

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      First, you don't need a UserControl. All you have to do is create a class file and inherit from PictureBox. Which is what you actually did in the first place. All you did was change the inheritance from UserControl to PictureBox. Next, it looks like all you're doing is replacing the PictureBox's painting code. To do that, get rid of the OnPaint function and move that code to the Paint event instead. You also won't need to call MyBase.OnPaint(). The OnPaint method is used to raise the Paint event, where the actualy painting occurs.

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups