dcsimg


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

Thread: displaying an IPictureDisp in a VB .NET PictureBox

  1. #1
    Mark Bax Guest

    displaying an IPictureDisp in a VB .NET PictureBox

    Hi,

    In VB .NET, I am using a COM object that exposes a method that returns an
    IPictureDisp (aka StdPicture). In VB6, I could assign this directly to a
    PictureBox's Picture property to display the graphic.

    How can I get a VB .NET PictureBox to display the IPictureDisp returned by
    this COM object. I've tried stuff like:

    Dim Surface1 As GSid.Surface
    Dim pict As stdole.IPictureDisp

    pict = Surface1.DrawEMF 'OK so far ...

    'either of these throws an Invalid Cast error
    Picture1.Image = pict
    Picture1.Image = CType(pict, System.Drawing.Image)

    Any help would be appreciated.

    Mark



  2. #2
    Russell Jones Guest

    Re: displaying an IPictureDisp in a VB .NET PictureBox

    Try this:

    Picture1.Image = Bitmap.FromHbitmap(New System.IntPtr(pict.Handle))

    "Mark Bax" <markb@blaisesoft.com> wrote in message
    news:3d3db010$1@10.1.10.29...
    > Hi,
    >
    > In VB .NET, I am using a COM object that exposes a method that returns an
    > IPictureDisp (aka StdPicture). In VB6, I could assign this directly to a
    > PictureBox's Picture property to display the graphic.
    >
    > How can I get a VB .NET PictureBox to display the IPictureDisp returned by
    > this COM object. I've tried stuff like:
    >
    > Dim Surface1 As GSid.Surface
    > Dim pict As stdole.IPictureDisp
    >
    > pict = Surface1.DrawEMF 'OK so far ...
    >
    > 'either of these throws an Invalid Cast error
    > Picture1.Image = pict
    > Picture1.Image = CType(pict, System.Drawing.Image)
    >
    > Any help would be appreciated.
    >
    > Mark
    >
    >




  3. #3
    Mark Bax Guest

    Re: displaying an IPictureDisp in a VB .NET PictureBox

    Russel,

    But this statement causes an error:
    _COMPlusExceptionCode -532459699, "A generic error occurred in GDI+."

    Any other thoughts? This type of thing was a pretty common practice in VB6;
    can MS not have provided some mechanism to achieve this??

    Thanks,

    Mark

    "Russell Jones" <arj1@nospam.northstate.net> wrote in message
    news:3d3dcc1e@10.1.10.29...
    > Try this:
    >
    > Picture1.Image = Bitmap.FromHbitmap(New System.IntPtr(pict.Handle))
    >
    > "Mark Bax" <markb@blaisesoft.com> wrote in message
    > news:3d3db010$1@10.1.10.29...
    > > Hi,
    > >
    > > In VB .NET, I am using a COM object that exposes a method that returns

    an
    > > IPictureDisp (aka StdPicture). In VB6, I could assign this directly to a
    > > PictureBox's Picture property to display the graphic.
    > >
    > > How can I get a VB .NET PictureBox to display the IPictureDisp returned

    by
    > > this COM object. I've tried stuff like:
    > >
    > > Dim Surface1 As GSid.Surface
    > > Dim pict As stdole.IPictureDisp
    > >
    > > pict = Surface1.DrawEMF 'OK so far ...
    > >
    > > 'either of these throws an Invalid Cast error
    > > Picture1.Image = pict
    > > Picture1.Image = CType(pict, System.Drawing.Image)
    > >
    > > Any help would be appreciated.
    > >
    > > Mark
    > >
    > >

    >
    >




  4. #4
    Russell Jones Guest

    Re: displaying an IPictureDisp in a VB .NET PictureBox

    Mark.

    Sorry, that works when the IPictureDisp object points to a bitmap, but not
    to a metafile.


    "Mark Bax" <markb@blaisesoft.com> wrote in message
    news:3d3de6ae@10.1.10.29...
    > Russel,
    >
    > But this statement causes an error:
    > _COMPlusExceptionCode -532459699, "A generic error occurred in GDI+."
    >
    > Any other thoughts? This type of thing was a pretty common practice in

    VB6;
    > can MS not have provided some mechanism to achieve this??
    >
    > Thanks,
    >
    > Mark
    >
    > "Russell Jones" <arj1@nospam.northstate.net> wrote in message
    > news:3d3dcc1e@10.1.10.29...
    > > Try this:
    > >
    > > Picture1.Image = Bitmap.FromHbitmap(New System.IntPtr(pict.Handle))
    > >
    > > "Mark Bax" <markb@blaisesoft.com> wrote in message
    > > news:3d3db010$1@10.1.10.29...
    > > > Hi,
    > > >
    > > > In VB .NET, I am using a COM object that exposes a method that returns

    > an
    > > > IPictureDisp (aka StdPicture). In VB6, I could assign this directly to

    a
    > > > PictureBox's Picture property to display the graphic.
    > > >
    > > > How can I get a VB .NET PictureBox to display the IPictureDisp

    returned
    > by
    > > > this COM object. I've tried stuff like:
    > > >
    > > > Dim Surface1 As GSid.Surface
    > > > Dim pict As stdole.IPictureDisp
    > > >
    > > > pict = Surface1.DrawEMF 'OK so far ...
    > > >
    > > > 'either of these throws an Invalid Cast error
    > > > Picture1.Image = pict
    > > > Picture1.Image = CType(pict, System.Drawing.Image)
    > > >
    > > > Any help would be appreciated.
    > > >
    > > > Mark
    > > >
    > > >

    > >
    > >

    >
    >




  5. #5
    helpinghand Guest

    Re: displaying an IPictureDisp in a VB .NET PictureBox


    this will do it for you

    picture1.image = Microsoft.VisualBasic.Compatibility.VB6.IPictureDispToImage(pict)
    'one line


    "Mark Bax" <markb@blaisesoft.com> wrote:
    >Hi,
    >
    >In VB .NET, I am using a COM object that exposes a method that returns an
    >IPictureDisp (aka StdPicture). In VB6, I could assign this directly to a
    >PictureBox's Picture property to display the graphic.
    >
    >How can I get a VB .NET PictureBox to display the IPictureDisp returned

    by
    >this COM object. I've tried stuff like:
    >
    > Dim Surface1 As GSid.Surface
    > Dim pict As stdole.IPictureDisp
    >
    > pict = Surface1.DrawEMF 'OK so far ...
    >
    > 'either of these throws an Invalid Cast error
    > Picture1.Image = pict
    > Picture1.Image = CType(pict, System.Drawing.Image)
    >
    >Any help would be appreciated.
    >
    >Mark
    >
    >



  6. #6
    Mark Bax Guest

    Re: displaying an IPictureDisp in a VB .NET PictureBox

    Thanks! that does work - is there any way to achieve this without setting
    VB6 compatibility reference?

    I mean, we are not using any other "VB6 features" in the project, and I'd
    like to lose the reference if possible ...

    Mark

    "helpinghand" <billgates@microsoft.com> wrote in message
    news:3d4709eb$1@10.1.10.29...
    >
    > this will do it for you
    >
    > picture1.image =

    Microsoft.VisualBasic.Compatibility.VB6.IPictureDispToImage(pict)
    > 'one line
    >
    >
    > "Mark Bax" <markb@blaisesoft.com> wrote:
    > >Hi,
    > >
    > >In VB .NET, I am using a COM object that exposes a method that returns an
    > >IPictureDisp (aka StdPicture). In VB6, I could assign this directly to a
    > >PictureBox's Picture property to display the graphic.
    > >
    > >How can I get a VB .NET PictureBox to display the IPictureDisp returned

    > by
    > >this COM object. I've tried stuff like:
    > >
    > > Dim Surface1 As GSid.Surface
    > > Dim pict As stdole.IPictureDisp
    > >
    > > pict = Surface1.DrawEMF 'OK so far ...
    > >
    > > 'either of these throws an Invalid Cast error
    > > Picture1.Image = pict
    > > Picture1.Image = CType(pict, System.Drawing.Image)
    > >
    > >Any help would be appreciated.
    > >
    > >Mark
    > >
    > >

    >




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center