Reset picturebox to default image - vb.net

I have a picturebox. I set the default image to a picture with some word. So it embed in the textbox. So I load this picturebox using code. The when I click on Reset button, I will dispose the image that been hold. So how to set back the default image after I dispose it?

Have you tried something like the following code?
pictureBox1.Image = pictureBox1.InitialImage

Related

Draw Image to Picture Box using AutoScroll but keep a Header Visible

I have a Picturebox which I draw a view to (Gantt View in this case) and it works OK - i.e., the view is drawn and the AutoScroll property allows the image in the PictureBox to be smoothly scrolled.
My problem is, the header of the image (e.g., the date headers in this case) scroll off the top of the display when I scroll down the image.
What I can't work out is how to fix a header to the top. I thought about simply drawing a header into another Picturebox, but then I am not sure how to sync the header with the left-right scrolling of the main PictureBox
Can someone suggest the best approach to handling this, or do I need to revert to doing a direct draw and handle the scrolling myself?
I am using VB with VS 2015.
Many thanks
Phil
Updated - I am now using an off-screen Bitmap, but can someone look at the code below and let me know if there is a faster/better way to do this? It all works, but still learning and so always looking to do things the best way
Public Sub MoveViewPoint(G As Graphics)
' G passed in from controls Paint
G.Clear(Color.WhiteSmoke)
' _Plan is off-screen bitmap of image
' _HeaderHeight is height of the Header area in _Plan
Dim Header_src_rect As New Rectangle(_HScroll.Value, 0, _Plan.Width, _HeaderHeight)
Dim Header_dst_rect As New Rectangle(0, 0, _Plan.Width, _HeaderHeight)
G.DrawImage(_Plan, Header_dst_rect, Header_src_rect, GraphicsUnit.Pixel)
Dim src_rect As New Rectangle(_HScroll.Value, _HeaderHeight + 1 + _VScroll.Value, _Plan.Width, _Plan.Height)
Dim dst_rect As New Rectangle(0, _HeaderHeight + 1, _Plan.Width, _Plan.Height)
G.DrawImage(_Plan, dst_rect, src_rect, GraphicsUnit.Pixel)
_HScroll.LargeChange = G.ClipBounds.Width * 0.9
_VScroll.LargeChange = G.ClipBounds.Height * 0.9
End Sub
I would do all your drawing to an off-screen bitmap using the GDI graphics system. You can draw your headers and the rest of the chart as 2 distinct stages in the same bitmap. You would have to handle the scrolling yourself by watching the MouseMove event and checking the buttons status.

Opacity of Panel over Awesomium WebControl

I've got a normal Winforms Panel, but under it, I've sent a (Awesomium) WebControl form to the back, and was wondering if it's possible to make the panel transparent to reveal the colors of the webpage basically, but simple solutions such as
Panel1.BackColor = FromARGB(0,0,0,0) (Or any other color)
make the backcolor the same as the Form's backcolor (Goes right through the WebControl). Is there any workaround? My original intent was to see if the panel could display the color under of the webpage, rather than the Form's backcolor.
Look, you have not explained your problem properly, so I can't tell exactly what problem you are getting.
Panel's color is by default transparent but for your convenience you can set the background as transparent.
Here is the code:
Panel1.BackColor = Color.Transparent
Or, if your form's backcolor is a plain color, you can try the following:
Panel1.BackColor = Form1.BackColor
Hope it works perfectly!

VB.NET Winforms: Overlay two transparent images

I am attempting to overlay two transparent images within a winform, but it keeps rendering the form's background image behind the top transparent image, as opposed to the second image...
My basic set up is I have two panels and in each panel is a picturebox. Each image in the picture boxes have some transparent areas. I've set the BackColor of the panels to color.transparent.
When I make one panel overlay the other I'm seeing the form's backcolor come through as opposed to the underlaying image.
Am I missing a property that I can set?
You only need one picture box. The overlay can be done with graphics.
Imports System.Drawing
Dim OverlayImage As New Bitmap("Some Path", True)
Dim BackImage As New Bitmap("Some Path", True)
g As Graphics = Graphics.FromImage(BackImage)
g.DrawImage(OverlayImage, 0, 0)
pictureBox1.Image = BackImage
If you want to have the timer move the overlayed image, then first, make a variable Dim posX As Integer = 0
then use g.DrawImage(OverlayImage, posX, 0) Now when your timer ticks, increment posX by 10
Here's a complete function to overlay two images (adapted from Blue0500's answer):
''' <summary> Return a new image with one superimposed over the other. </summary>
Function OverlayImgs(ByVal BackgroundImg As System.Drawing.Bitmap, ByVal OverlayImg As System.Drawing.Bitmap, Position As System.Drawing.Point) As System.Drawing.Bitmap
Dim g = System.Drawing.Graphics.FromImage(BackgroundImg)
g.DrawImage(OverlayImg, Position)
Return BackgroundImg
End Function
Usage:
lblTest.Image = OverlayImgs(Img1, Img2, New Point(16, 16))
You don't need a PictureBox for this unless you are using it for the canvas. You can draw all images to a Rectangle structure and move them around. Personally I would create a class object that has a Rectangle, Image and other properties and hold them in a collection. Then you simply draw the class objects by there properties including location. If there images contain transparencies they will overlay for you. This also gives you a method to check for collisions via the Rectangle.IntersectsWith function.

I've increased the size of image in picture box but now I want to take it back to its original size

I am working with vb.net and want to increase the size of image when the cursor is over that image, but the image should come back to its original size when the cursor leaves that image area.
I've used the following code to increase the size of image:
Private Sub PictureBox1_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox1.MouseHover
PictureBox1.Size = New Size(300, 250)
End Sub
I've used the default size class but, it gives some different dimensions.
Please guide me by the code that brings the image into its original size that I've been declared into the picture box properties.
You should probably be hooking in to the MouseEnter and MouseLeave events. Links for MSDN reference
Here's the code that will resize the PictureBox to the dimensions of the image:
PictureBox1.Size = PictureBox1.Image.Size
Assuming that the original size of the PictureBox was the image size, then that'll work just fine.
As kaveman suggested, MouseEnter and MouseLeave would be much better events to put the code in ;-)
In order to restore the custom size you've set it to, you'll need some code like this: (make sure its somewhere which won't go out of scope, like in the form, outside of methods)
You'll need a variable to store the original size:
Dim OriginalSize as Size
Then, before changing the size when the user moves the mouse over the image, store the size in the variable: (put this in the MouseEnter event)
OriginalSize = PictureBox1.Size
PictureBox1.Size = New Size(300, 250)
Restoring that size is a simple matter of putting that variable back into the picturebox size: (this goes in the MouseLeave event)
PictureBox1.Size = OriginalSize
=)

picturebox image clearing

i created a drawing apllication in my solution by this code.by this i can draw images in a picturebox and can to save. when i click the clearbutton the image on the picturebox is cleared but the problem is after clearing the image i can't draw any thing in the picturebox without the form's reload
dim mousepath as new system.drawing.drawing2d.graphicspath()
in pageload
picturebox1.image=new bitmap(picturebox1.clientsize.height,picturebox1.clientsize.width)
picturebox1_paint(...)
myusercolor=(sysytem.drawing.color.black)
myalpha=100
using g as graphics=graphics.fromimage(picturebox1.image)
g.clear(color.white)
dim currentpen as pen=new pen(color.fromargb(myalpha,myusercolor),mypenwidth) g.drawpath(currentpen,mousepath)
in mousedown
if e.button=mousebutton.left then
mousepath.startfigure()
end if
in mousemove
if e.button=mousebutton.left then
mousepath.addline(e.x,e.y,e.x,e.y)
end if
picturebox1.invalidate
clearbutton_click
picturebox1.image.dispose()
picturebox1.image=nothing
PROBLEM:
if anyone knows the solution for this problem please help me.it's very important for me.thank you
when you clear, you set picturebox1.image=nothing, but then your Graphics object comes from that image. That's why it won't work. You have to set a new Bitmap when you clear like the first time :
picturebox1.image=new bitmap(picturebox1.clientsize.height,picturebox1.clientsize.width)
mousepath.Reset();