הערה
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות להיכנס או לשנות מדריכי כתובות.
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות לשנות מדריכי כתובות.
Question
Tuesday, April 22, 2014 3:31 PM
Hi All.
I need a code for dropping shadow effect around the images from different positions and directions.
Like a normal shadow.
Any Links ,ideas, or code will be appreciated.
Thanks.
All replies (18)
Wednesday, April 23, 2014 5:42 AM ✅Answered
HI All
Thanks all of you for reply. But still i don't have the correct answer.
I repeat what i want, is Shadow,like shadow,inside the picurebox, and not a simple rectangle.
Exactly like the WPF Shadow effect in Picture from A. Morton,but programmatically in vb.I will let the question open also today maybe someone have the right idea.
Like the Left image, but if it is like right one will be also welcome.
Or like next foto
Note my images are jpg and not png.
Thanks.
You realize that what you want could be found by doing research on your own part until you have enough information and practiced with code in order to do what you want. Rather than having anybody else do it all for you and provide you the code.
As this is really a forum about issues with vb.net code of which you've provided no code that you have an issue with. At some point I feel there should be an expectation that a question poster should at least provide information relevant to the research they've attempted and some kind of code that appears to be along the path they want to go to that they are having issues with.
I've noticed in various threads of yours that you post basically a requirement and want others to provide the code that meets your requirement. Which is not what this forum is about.
Hello. I'm old and retired. I like to program if you could call what I do programming. However I'd like to code for you! If you've got the dime then I've got the time. Call me, landline, @ BR-549.
Wednesday, April 23, 2014 9:23 AM ✅Answered
Hallo Mr. Monkeyboy
I am sorry if i provide so much work for all of you.
All what you say i already know it.
What you thing i am doing all time ?.
More than 2 weeks i am searching the net and i don't find what i wont untill now.
That's the way i am asking this forum.
I never required from you to answer my question.
If you dont know the answer just simple ignore this and all is ok.
Any way THANKS even for this reply.
Finaly Thanks all of you for this suport. As you say, i have to work now
and i close this question.
THANKS Again.
Toni
Tuesday, April 22, 2014 3:50 PM
Depends what you mean, if you mean an existing image, then AFAIK you can forget it using a program language. You need expensive tools.
If it is to create new shadows on new image object then take a look at the page from Bob
http://bobpowell.net/dropshadowtext.aspx
Success
Cor
Tuesday, April 22, 2014 3:58 PM
I need a simple shadow like windows forms, but inside the picture box, around the image like a rectangle.
Tuesday, April 22, 2014 7:07 PM | 1 vote
Hi All.
I need a code for dropping shadow effect around the images from different positions and directions.
Like a normal shadow.
Any Links ,ideas, or code will be appreciated.
Thanks.
I would suspect you may be able to figure out how to do something similar to what you want using code on this thread which was answered by IronRazerz. Although it doesn't appear to answer the question of drop shadow I would think you could research how to draw a drop shadow using graphics and use some of the code in the link to help you do what you want to do.
Custom Picturebox Border (Using Custom Image)
You may be able to find something about using graphics to draw a drop shadow using the search engine at the below link or maybe not.
I'm too lazy to try to write code that will do what you want to do for you. :)
Hello. I'm old and retired. I like to program if you could call what I do programming. However I'd like to code for you! If you've got the dime then I've got the time. Call me, landline, @ BR-549.
Tuesday, April 22, 2014 7:34 PM | 1 vote
This example will draw an oval border around the control as shown around the picture.
Imports System.Drawing.Drawing2D Private Sub Form5_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
'draw the picturebox border
DrawControlBorder(Picturebox1, e.Graphics, Color.Black, Color.White, Color.Gray)
End Sub
Public Sub DrawControlBorder(theControl As Control, g As Graphics, colorGradient1 As Color, colorGradient2 As Color, colorBorder As Color)
'draws TV like ellipse around the control onto g
Dim bordersize As Integer = 20 'theControl.Width / 3.5
Dim path As GraphicsPath = New GraphicsPath()
path.AddEllipse(New Rectangle(theControl.Left - bordersize / 2, theControl.Top - bordersize * 2, theControl.Width + bordersize, theControl.Height + bordersize * 4))
bordersize = bordersize / 2
With g
.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
.Clip = New Region(path) 'region
'horz gradient fill
Dim rect As New Rectangle(theControl.Left - bordersize * 4, theControl.Top - bordersize, theControl.Width + bordersize * 8, theControl.Height + bordersize * 2)
Using linGrBrush As New LinearGradientBrush(rect, colorgradient1, colorgradient2, -90)
.FillEllipse(linGrBrush, rect)
End Using
'border
.DrawEllipse(New Pen(colorBorder, 4), rect)
End With
End Sub
Tuesday, April 22, 2014 7:54 PM | 1 vote
If you are open to a bit(!) of a learning curve, you could use a WPF project instead of a Windows Forms project. WPF has lots of effects you can use, including adding a drop-shadow.
--
Andrew
Tuesday, April 22, 2014 7:59 PM | 2 votes
I need a simple shadow like windows forms, but inside the picture box, around the image like a rectangle.
Hi,
You can use the AddImageWithShadow sub shown in the code example below. In the form load event i add the image to the picturebox using the sub. You set the parameters to the Image you want to use, The position of the shadow around the image, The thickness of the shadow, The color of the shadow, and last the PictureBox you want to assign the image to. However, you may want to modify it so you only need to set the options you want to be variable.
There are many ways you can do this so, this is just one way.
Public Class Form1
Public Enum ShadowPosition As Integer
TopLeft = 0
TopRight = 1
BottomLeft = 2
BottomRight = 3
End Enum
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
PictureBox1.BackColor = Color.Transparent
PictureBox1.SizeMode = PictureBoxSizeMode.Zoom
AddImageWithShadow(Image.FromFile("C:\TestFolder\MyImage.png"), ShadowPosition.BottomRight, 3, Color.FromArgb(128, 0, 0, 0), PictureBox1)
End Sub
''' <summary>
''' Draws the picturebox image with a shadow.
''' </summary>
''' <param name="img">The image to add to the picturebox with a shadow.</param>
''' <param name="area">The position of the shadow.</param>
''' <param name="thickness">The thickness of the shadow.</param>
''' <param name="clr">The color of the shadow.</param>
''' <param name="PicBox">The picturebox to assign the image to.</param>
Private Sub AddImageWithShadow(ByVal img As Image, ByVal area As ShadowPosition, ByVal thickness As Integer, ByVal clr As Color, ByVal PicBox As PictureBox)
Using bm As New Bitmap(img.Width + thickness, img.Height + thickness)
Using gr As Graphics = Graphics.FromImage(bm)
Dim ix, iy As Integer
Dim rect As New Rectangle(thickness, thickness, img.Width, img.Height)
If area = ShadowPosition.TopLeft Or area = ShadowPosition.TopRight Then
iy = thickness
rect.Y = 0
End If
If area = ShadowPosition.TopLeft Or area = ShadowPosition.BottomLeft Then
ix = thickness
rect.X = 0
End If
gr.FillRectangle(New SolidBrush(clr), rect)
gr.DrawImage(img, ix, iy)
End Using
If PicBox.Image IsNot Nothing Then PicBox.Image.Dispose()
PicBox.Image = New Bitmap(bm)
End Using
End Sub
End Class
Tuesday, April 22, 2014 8:17 PM | 1 vote
Here is one that just does a shadow by offsetting the control with a rectangle.
Private Sub Form5_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
Dim bordersize As Integer = 4
Dim rect As New Rectangle(Picturebox1.Left + bordersize, Picturebox1.Top + bordersize, Picturebox1.Width, Picturebox1.Height)
e.Graphics.FillRectangle(Brushes.SteelBlue, rect)
End Sub
Tuesday, April 22, 2014 8:18 PM
Oouh, nice one Razerz.
Tuesday, April 22, 2014 9:49 PM
Oouh, nice one Razerz.
Yeah it is but so is yours. :)
Hello. I'm old and retired. I like to program if you could call what I do programming. However I'd like to code for you! If you've got the dime then I've got the time. Call me, landline, @ BR-549.
Tuesday, April 22, 2014 10:13 PM
Oouh, nice one Razerz.
Yeah it is but so is yours. :)
Hello. I'm old and retired. I like to program if you could call what I do programming. However I'd like to code for you! If you've got the dime then I've got the time. Call me, landline, @ BR-549.
Yes, i agree. All the examples have there advantages and disadvantages. It all depends on how the OP has the sizemode set and if they are using transparent png images or the backcolor of the picturebox set to transparent. :)
Wednesday, April 23, 2014 2:26 AM
HI All
Thanks all of you for reply. But still i don't have the correct answer.
I repeat what i want, is Shadow,like shadow,inside the picurebox, and not a simple rectangle.
Exactly like the WPF Shadow effect in Picture from A. Morton,but programmatically in vb.
I will let the question open also today maybe someone have the right idea.
Like the Left image, but if it is like right one will be also welcome.
Or like next foto
Note my images are jpg and not png.
Thanks.
Wednesday, April 23, 2014 3:33 AM
Thanks all of you for reply. But still i don't have the correct answer.
I repeat what i want, is Shadow,like shadow,inside the picurebox, and not a simple rectangle.
Exactly like the WPF Shadow effect in Picture from A. Morton,but programmatically in vb.
You haven't included a background, but I assume that the shading is from solid to transparent. You can do the first example with a gradient brush. Create the brush with the same color with different transparencies and a simple linear gradient. Orient the gradient to the edge that you are drawing and draw the edge.
http://msdn.microsoft.com/en-us/library/system.drawing.drawing2d.lineargradientbrush(v=vs.110).aspx
The second example is much more complex, and requires a full image processing, including edge detection. See here for an example:
http://mathematica.stackexchange.com/questions/43186/how-can-i-add-drop-shadows-and-specular-highlights-to-2d-graphics
Don't try drawing in a picture box. Prepare your image as a bitmap. Pictureboxes are for displaying an image, not for drawing it.
Wednesday, April 23, 2014 3:49 AM
Thanks for reply.
It looks like good idea,i will work on linear gradient but i don't know how, it will be nice if you post me a example link or a code.
Thanks
Wednesday, April 23, 2014 6:31 AM
It looks like good idea,i will work on linear gradient but i don't know how, it will be nice if you post me a example link or a code.
The main index at the link provided above includes this item: Using the LinearGradientBrush
There is also an example at the class definition in the MSDN library.
Wednesday, April 23, 2014 9:23 AM
I will Check this Acamar
Thanks
Wednesday, April 23, 2014 4:58 PM
Hallo Toni,
You did not ask to answer, however, mr. Monkeyboy did.
He was telling his opinion. Probably not for you but to all others visiting this forum.
This is a community forum you know, not the paid help desk from Microsoft.
Success
Cor