XtraReport show image in picturebox one time only - vb.net

I've created an xtrareport that contains picturebox and i set the image through xrPictureBox1.ImageUrl in XrPictureBox1_BeforePrint event.
when i open the report for the first time, the images showing properly, but when reload report and reopen it again the images not showing.
I'm using version 17.2.
please help!
Regards.
Private Sub XrPictureBox1_BeforePrint(sender As Object, e As PrintEventArgs) Handles XrPictureBox1.BeforePrint
XrPictureBox1.ImageUrl = HttpContext.Current.Server.MapPath("~/TaskFiles/" & XrTableCell9.Text)
End Sub

Related

Changing a label's image on click

Whilst trying to change a label's set image to a new image stored in resources it appears blank rather than showing the correct new image.
I've tried storing the images in resource and then call them on a button click in the form. This just changes the home1.png image to a blank image and doesn't show home2.png
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim Resources As Object = My.Resources.ResourceManager
Label1.Image = My.Resources.ResourceManager.GetObject("home1.png")
End Sub
For ease of explanation i have two images
home1.png
home2.png
home1.png is the loading image when the app is loaded it's what will be displayed. When you click the button on the app label1 image should change to use the home2.png file stored in resources. The code i have appears to show a blank image.
I have checked to make sure file names are correct and they are.

Dynamically changing image in picture box not working

I've been trying to figure this out off-and-on for weeks.
In my VB 2010 Forms application, I have a number of picture boxes which are populated with images from other picture boxes using the drag-and-drop method. That's no problem, it works fine. The picture boxes are all in a groupbox container.
The problem is trying to swap images between two picture boxes on a drag-and drop operation. In other words pBox1 has image.x and pBox2 has image.y. Drag the image from pBox2 to pBox1, and drop it; pBox1 will then have image.y from pBox2 and pBox2 will have image.x from pBox1.
With this example, here's the code I have so far:
Private Sub pBox2_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles pBox1.MouseDown
strImageSource = "pBox2" 'strImageSource is a global string variable
[other stuff]
end sub
^ This saves the name of the source picture box to a global string.
Private Sub pBox1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles pBox1.DragDrop
For Each Control as PictureBox in GroupBox1.Controls.OfType(of PictureBox)()
if Control.Name = strImageSource then
Control.Image = pBox1.Image
end if
next
dim imgTarget as Image = CType((e.Data.GetData(DataFormats.Bitmap)), Bitmap)
pBox1.image = imgTarget
End Sub
^ This searches for the picture box as named by the strImageSource ("pBox2") and copies the contents of pBox1 into it, and then drops the image that was in pBox2 into pBox1.
I hope this makes sense.
This correctly places the image from pBox2 into pBox1, but it does not switch the image from pBox1 into pBox2. pBox2 is just blank. However, debugging shows that the image in pBox2 is not nothing; it does contain a bitmap. It's just not visible.
Now, just as a test, I added a line to the For Each section that would change the background color of the picture box:
For Each Control as PictureBox in GroupBox1.Controls.OfType(of PictureBox)()
if Control.Name = strImageSource then
Control.Image = pBox1.Image
Control.BackColor = color.red
end if
next
And the back color does change. This tells me that the For Each section is working -- it's finding the control and changing the back color. It's just not showing the image.
Is there something I am overlooking?
Thanks!
Instead of using strImageSource, use a global variable defined as a Picturebox
Private tmpPictureBox As PictureBox
Then store that picturebox reference so you can set its image on DragDrop
Private Sub pBox2_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles pBox1.MouseDown
'store the picturebox reference
tmpPictureBox = sender
[other stuff]
end sub
Private Sub pBox1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles pBox1.DragDrop
'set the first image to the second
tmpPictureBox.Image = sender.image
'set the second image to the first
pBox1.image = CType((e.Data.GetData(DataFormats.Bitmap)), Bitmap)
End Sub
You should call Control.Refresh() on the PictureBox controls in order to update the images.
OK, this was stupid.
I was doing everything right with one really boneheaded exception. In another part of the code, inexplicably, I was clearing the picture boxes of content after the image was replaced. It may have been a remnant of something I was trying to do unrelated to this problem, and I just never corrected it.
My apologies for that, and thanks for all the responses.

Loading images from a folder [VB.NET]

I'm currently experiencing a problem with my program. I want to create a photo gallery for my girlfriend which she can install on her computer. I want to import images from a folder on Form load and display them in a PictureBox.
When I load the Form I get a big red 'X' that fills the box. Looks like the drawing.bitmap ErrorImage. What could be the problem? Any help is greatly appreciated. Thank you.
Private Sub Pigge_Gallary_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim directory As New IO.DirectoryInfo("C:\Pics\Bears")
If directory.Exists Then
Dim jpgFiles() As IO.FileInfo = directory.GetFiles("*.jpg")
For Each jpgFile As IO.FileInfo In jpgFiles
If jpgFile.Exists Then
Dim image = Drawing.Image.FromFile(jpgFile.FullName)
Using image
PicPig.Image = image
End Using
End If
Next
End If
End Sub
Once you exit the Using block, you're losing the image reference.
Try changing
PicPig.Image = image
to
PicPig.Image = image.clone
or just set it to the image from the file:
PicPig.Image = Drawing.Image.FromFile(jpgFile.FullName)
Also, because you're doing it in a For loop, it's just going to replace the picturebox image as it loops. When it finishes the loop, the picturebox will only be displaying the last image.

VB NET image as button

I'm going to change the image of button_original to button_clicked's image.
how do I change the image(button) when I click them ?
Should I need to use picture box anything else ?
In vb.NET, if you're using an image on a button, to change it, you can change the property Image of the button in the Button_Click() event.
Private Sub Button_Click(sender As Object, e As EventArgs) Handles Button.Click
Button.Image = ... <- your image
End Sub

Mdiparent ,child forms

I have mdiparent and many child forms
im calling a child form as below
Private Sub tsmQuotation_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsmQuotation.Click
If Application.OpenForms().OfType(Of Quotation).Any Then
Quotation.WindowState = FormWindowState.Normal
Quotation.Focus()
Else
Quotation.MdiParent = Me
Quotation.Show()
End If
End Sub
my first doubt is: when i declare this Quotation.MdiParent = Me...it takes more time to open the form than without this line. How can i reduce the time to open form..or am I doing anything wrong ?
2nd doubt is: I have place a picturebox in mdiparent's center. and i have sent picturebox to back but then too when i open any child form I see the picturebox above the quotaion .I want to show picture box at back not above any child forms.
Thanks in advance!!!
Without Quotation.MdiParent = Me, the form displayed would not be an MdiChild. It would instead be displaying as a normal form by itself. Try dragging it around the screen and you'll see that it is not confined to the MdiParent form.
See if this loads it any faster, though:
Private Sub tsmQuotation_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsmQuotation.Click
If Application.OpenForms().OfType(Of Quotation).Any Then
Dim Q As Quotation = Application.OpenForms().OfType(Of Quotation).First
Q.WindowState = FormWindowState.Normal
Q.Activate()
Else
Dim Q As New Quotation
Q.MdiParent = Me
Q.Show()
End If
End Sub
For the second issue, select the MdiParent form and set the BackgroundImage() and BackgroundImageLayout() properties. The image will NOT display on the form at design-time, but it will be there when you run the application.