I have created a PictureBox control which can have it's Image property
directly bound to an image field in a database. This works perfectly for
showing the images that are in the database. When I paste a new image into
my control, it shows the new image and updates the image property. Problem
is... It doesn't update the bound field! Any thoughts as to what I've done
wrong? Any help would be greatly appreciated. The code for the Picturebox
and the code that I use to paste the image are below.
Thanks in Advance,
David J. Ricker II
-----------------Start of Picturebox Control
Imports System.Componen tModel
Public Class MyPictureBox
Inherits System.Windows. Forms.PictureBo x
#Region " Component Designer generated code "
Public Sub New(ByVal Container As System.Componen tModel.IContain er)
MyClass.New()
'Required for Windows.Forms Class Composition Designer support
Container.Add(M e)
End Sub
Public Sub New()
MyBase.New()
'This call is required by the Component Designer.
InitializeCompo nent()
'Add any initialization after the InitializeCompo nent() call
End Sub
'Component overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As
Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Disp ose()
End If
End If
MyBase.Dispose( disposing)
End Sub
'Required by the Component Designer
Private components As System.Componen tModel.IContain er
'NOTE: The following procedure is required by the Component Designer
'It can be modified using the Component Designer.
'Do not modify it using the code editor.
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()
End Sub
#End Region
Public Event ImageChanged As EventHandler
Private mImage As Object
<Bindable(True) , Browsable(True) > Public Shadows Property Image() As
Object
Get
Return mImage
End Get
Set(ByVal Value As Object)
If IsDBNull(Value) Then
Dim g As New System.Drawing. Bitmap(1, 1)
g.SetPixel(0, 0, System.Drawing. Color.White)
MyBase.Image = g
ElseIf Value Is Nothing Then
Dim g As New System.Drawing. Bitmap(1, 1)
g.SetPixel(0, 0, System.Drawing. Color.White)
MyBase.Image = g
ElseIf Value.GetType.F ullName = "System.Drawing .Bitmap" Then
MyBase.Image = Value
Dim ms As New System.IO.Memor yStream
CType(Value, Bitmap).Save(ms ,
System.Drawing. Imaging.ImageFo rmat.Jpeg)
Dim bytBLOBData(ms. Length - 1) As Byte
ms.Position = 0
ms.Read(bytBLOB Data, 0, ms.Length)
Value = bytBLOBData
Else
Dim img() As Byte = CType(Value, Byte())
Dim ms As New System.IO.Memor yStream
Dim offset As Integer = 0
ms.Write(img, offset, img.Length - offset)
Dim bmp As Bitmap = New Bitmap(ms)
ms.Close()
MyBase.Image = bmp
End If
mImage = Value
RaiseEvent ImageChanged(Me , New System.EventArg s)
End Set
End Property
End Class
-----------------End of Picturebox Control
-----------------Start of Image Pasting
Private Sub btnPasteImage_C lick(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles btnPasteImage.C lick
Dim data As IDataObject = Clipboard.GetDa taObject
If (data.GetDataPr esent(DataForma ts.Bitmap)) Then
MyPictureBox1.I mage = data.GetData(Da taFormats.Bitma p)
End If
End Sub
-----------------End of Image Pasting 2 2428
Also,
If my image is in a child record of a master/child relationship, and I
change the visible child record and then save, the image saves. If I don't
change the child record I'm looking at first, then the image doesn't save.
Thanks Again,
David J. Ricker II
"David Ricker" <da***@vanamati c.com> wrote in message
news:Og******** ********@TK2MSF TNGP10.phx.gbl. .. I have created a PictureBox control which can have it's Image property directly bound to an image field in a database. This works perfectly for showing the images that are in the database. When I paste a new image
into my control, it shows the new image and updates the image property.
Problem is... It doesn't update the bound field! Any thoughts as to what I've
done wrong? Any help would be greatly appreciated. The code for the
Picturebox and the code that I use to paste the image are below.
Thanks in Advance, David J. Ricker II
-----------------Start of Picturebox Control
Imports System.Componen tModel
Public Class MyPictureBox Inherits System.Windows. Forms.PictureBo x
#Region " Component Designer generated code " Public Sub New(ByVal Container As
System.Componen tModel.IContain er) MyClass.New() 'Required for Windows.Forms Class Composition Designer support Container.Add(M e) End Sub Public Sub New() MyBase.New() 'This call is required by the Component Designer. InitializeCompo nent() 'Add any initialization after the InitializeCompo nent() call End Sub 'Component overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Disp ose() End If End If MyBase.Dispose( disposing) End Sub 'Required by the Component Designer Private components As System.Componen tModel.IContain er 'NOTE: The following procedure is required by the Component
Designer 'It can be modified using the Component Designer. 'Do not modify it using the code editor. <System.Diagnos tics.DebuggerSt epThrough()> Private Sub InitializeCompo nent() End Sub #End Region
Public Event ImageChanged As EventHandler
Private mImage As Object
<Bindable(True) , Browsable(True) > Public Shadows Property Image() As Object Get Return mImage End Get Set(ByVal Value As Object) If IsDBNull(Value) Then Dim g As New System.Drawing. Bitmap(1, 1) g.SetPixel(0, 0, System.Drawing. Color.White) MyBase.Image = g ElseIf Value Is Nothing Then Dim g As New System.Drawing. Bitmap(1, 1) g.SetPixel(0, 0, System.Drawing. Color.White) MyBase.Image = g ElseIf Value.GetType.F ullName = "System.Drawing .Bitmap" Then MyBase.Image = Value Dim ms As New System.IO.Memor yStream CType(Value, Bitmap).Save(ms , System.Drawing. Imaging.ImageFo rmat.Jpeg) Dim bytBLOBData(ms. Length - 1) As Byte ms.Position = 0 ms.Read(bytBLOB Data, 0, ms.Length) Value = bytBLOBData Else Dim img() As Byte = CType(Value, Byte()) Dim ms As New System.IO.Memor yStream Dim offset As Integer = 0 ms.Write(img, offset, img.Length - offset) Dim bmp As Bitmap = New Bitmap(ms) ms.Close() MyBase.Image = bmp End If mImage = Value RaiseEvent ImageChanged(Me , New System.EventArg s) End Set End Property End Class
-----------------End of Picturebox Control
-----------------Start of Image Pasting
Private Sub btnPasteImage_C lick(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles btnPasteImage.C lick Dim data As IDataObject = Clipboard.GetDa taObject If (data.GetDataPr esent(DataForma ts.Bitmap)) Then MyPictureBox1.I mage = data.GetData(Da taFormats.Bitma p) End If End Sub
-----------------End of Image Pasting
I have found a workaround to this problem, however I am still curious if
anyone has any ideas as to why the dataset was not being updated in the
first place. The workaround involved manually setting the image in the
dataset to the image value of the control. I have added the following line
of code after I paste the image into my control:
CType(CType(Me. BindingContext( Dataview1, "DataMember").C urrent,
System.Data.Dat aRowView).Row, dataset1.TableR ow).Image =
Me.MyPictureBox 1.Image
Thanks Again,
David J. Ricker II
"David Ricker" <da***@vanamati c.com> wrote in message
news:O$******** ******@TK2MSFTN GP11.phx.gbl... Also, If my image is in a child record of a master/child relationship, and I change the visible child record and then save, the image saves. If I
don't change the child record I'm looking at first, then the image doesn't save.
Thanks Again, David J. Ricker II
"David Ricker" <da***@vanamati c.com> wrote in message news:Og******** ********@TK2MSF TNGP10.phx.gbl. .. I have created a PictureBox control which can have it's Image property directly bound to an image field in a database. This works perfectly
for showing the images that are in the database. When I paste a new image into my control, it shows the new image and updates the image property. Problem is... It doesn't update the bound field! Any thoughts as to what I've done wrong? Any help would be greatly appreciated. The code for the Picturebox and the code that I use to paste the image are below.
Thanks in Advance, David J. Ricker II
-----------------Start of Picturebox Control
Imports System.Componen tModel
Public Class MyPictureBox Inherits System.Windows. Forms.PictureBo x
#Region " Component Designer generated code " Public Sub New(ByVal Container As System.Componen tModel.IContain er) MyClass.New() 'Required for Windows.Forms Class Composition Designer
support Container.Add(M e) End Sub Public Sub New() MyBase.New() 'This call is required by the Component Designer. InitializeCompo nent() 'Add any initialization after the InitializeCompo nent() call End Sub 'Component overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Disp ose() End If End If MyBase.Dispose( disposing) End Sub 'Required by the Component Designer Private components As System.Componen tModel.IContain er 'NOTE: The following procedure is required by the Component Designer 'It can be modified using the Component Designer. 'Do not modify it using the code editor. <System.Diagnos tics.DebuggerSt epThrough()> Private Sub InitializeCompo nent() End Sub #End Region
Public Event ImageChanged As EventHandler
Private mImage As Object
<Bindable(True) , Browsable(True) > Public Shadows Property Image() As Object Get Return mImage End Get Set(ByVal Value As Object) If IsDBNull(Value) Then Dim g As New System.Drawing. Bitmap(1, 1) g.SetPixel(0, 0, System.Drawing. Color.White) MyBase.Image = g ElseIf Value Is Nothing Then Dim g As New System.Drawing. Bitmap(1, 1) g.SetPixel(0, 0, System.Drawing. Color.White) MyBase.Image = g ElseIf Value.GetType.F ullName = "System.Drawing .Bitmap" Then MyBase.Image = Value Dim ms As New System.IO.Memor yStream CType(Value, Bitmap).Save(ms , System.Drawing. Imaging.ImageFo rmat.Jpeg) Dim bytBLOBData(ms. Length - 1) As Byte ms.Position = 0 ms.Read(bytBLOB Data, 0, ms.Length) Value = bytBLOBData Else Dim img() As Byte = CType(Value, Byte()) Dim ms As New System.IO.Memor yStream Dim offset As Integer = 0 ms.Write(img, offset, img.Length - offset) Dim bmp As Bitmap = New Bitmap(ms) ms.Close() MyBase.Image = bmp End If mImage = Value RaiseEvent ImageChanged(Me , New System.EventArg s) End Set End Property End Class
-----------------End of Picturebox Control
-----------------Start of Image Pasting
Private Sub btnPasteImage_C lick(ByVal sender As System.Object, ByVal e
As System.EventArg s) Handles btnPasteImage.C lick Dim data As IDataObject = Clipboard.GetDa taObject If (data.GetDataPr esent(DataForma ts.Bitmap)) Then MyPictureBox1.I mage = data.GetData(Da taFormats.Bitma p) End If End Sub
-----------------End of Image Pasting
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Stephen Williams |
last post by:
Does Microsoft have a comment the possible bug on the
PictureBox Class. Here is the exchange I had on the
Experts-Exchange regarding this issue:
From Z_Beeblebrox:
Hi,
I believe it is standard windows behavious to continue to
send mouse events to the window in which the mouse was
depressed until the mouse is released. A quick test in VB6
confirms this, but I don't have .Net here to test that,
|
by: BrianW |
last post by:
I am working on a program that has multiple picturebox controls that a user
is allowed to move around which are contained within a panel control for
visual placement. In my mousedown event, I set the picturebox control's
borderstyle to Fixed3D, but upon doing so, I am not able to track the
picturebox control through mousemove events (if you move the mouse off of the
control too quickly, the control no longer receives mouse events). If I...
|
by: clickon |
last post by:
This is driving me nuts, it is such a simply thing to do but i cannot for the
life of me work out how you are suposed to do it. I want to update the data
in DropDownListB based on what is selected in DropDownListA. I am not trying
to do anything fancy with AJAX, i am happy to use Post Backs. If it were two
controls just on the page then i would simply specify a control parameter for
the SelectCommand of the SQLDataSource control which...
|
by: munglet |
last post by:
Is there anyway to get a picturebox to recieve focus?
I ask because I implemented a "delete" button in a picturebox (due to
size constraints), but now due to accessibility reasons I need to be
able to tab to the picturebox via the keyboard. Since the picturebox
doesn't recieve focus the user can't get to the picturebox control. Am
I missing something?
This is using .NET 1.1
|
by: Owen Blacker |
last post by:
I've spent loads of time Googling to try to work this one out and I'm
sure it's something obvious.
I get an InvalidOperationException reading "Databinding methods such as
Eval(), XPath(), and Bind() can only be used in the context of a
databound control" when I start my page. Unless I'm missing something
obvious, this is *not* the same issue as the "2-way databinding
cascading lists" issue in...
| |
by: GoGs |
last post by:
How this vb6 code convert in c# dotnet2
-----
Image1.Visible = False
Image1.Picture = LoadPicture("c:\image008.jpg")
Dim x, y As Single
x = Image1.Width
y = Image1.Height
Do While x Picture1.Width Or y Picture1.Height
x = x / 1.01
|
by: kirk |
last post by:
I have a form with a PictureBox control on it. The .Image property is
set to a PNG file(which shows the picture of the US map) with some
transparency in it. The .BackColor property is set to Transparent.
This so far, works perfect.
I now, would like to put another PNG image(an arrow showing
positioning on the map) over the last PictureBox. The problem i'm
having, the background for this second PictureBox only stays
transparent when...
|
by: AWW |
last post by:
XP VB 2005 running an example from help that creates a picturebox in
code - the picturebox is not created.
If I comment out the "Dim Box as New PictureBox" and create it in
Design mode - the example works.
I have tried Show, Enabled, Visible, and even BackColor.
Why does a help example not work? and why does Design creation work?
Thanks - I hope.
|
by: leshka82 |
last post by:
I have recently designed a Winform Image drag & drop utility. The approach I took was to have a Panel control serve as a destination for multiple file drop. Once the user dragged & dropped the desired files I do a check to ensure that I only process the image files (".jpg", ".png", etc), while any other files are ignored by the program. For every image file being dropped I programmatically create a PictureBox control, do proper resizing of an...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |