Click here to Skip to main content
15,898,010 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have used this code for Get image of my Control.

VB
Dim bmp As New Bitmap(c.Width, c.Height)
scc.DrawToBitmap(bmp, New Rectangle(c.ClientRectangle.X, scc.ClientRectangle.Y, c.ClientRectangle.Width, c.ClientRectangle.Height))
bmp.Save("E:\Cur.bmp")


Control's Borderstyle is Single

But it give image with
Left & top borders some time
and somtime with no borders


I want all borders in image of my control
any help...
Posted
Updated 1-Nov-12 21:31pm
v2

1 solution

Hi all,
I got Solution.
I like to share with you all, hope it will be helpful to them who are facing this kind of problem.

It was really strange that in one form that code was simply runs fine & in other form it was not working properly, It was showing only left & top border of control so, Finally I have to do some process like below.

I have do it in tow steps,

step 1.
get Image of control without Border.
step 2.
Add border in that image externally.
VB
c.BorderStyle = BorderStyle.None ' Set control's border style none
Dim bmp As New Bitmap(c.ClientSize.Width, c.ClientSize.Height) 
scc.DrawToBitmap(bmp, New Rectangle(0, 0, c.ClientSize.Width, c.ClientSize.Height)) 'Get image of Control (e.g here my control is 'c')
bmp = AppendBorder(bmp, 1) 'Set border Of Image. (you can set it in any color)
bmp.Save("E:\Cur.bmp", System.Drawing.Imaging.ImageFormat.Bmp)

VB
Private Function AppendBorder(ByVal original As Image, ByVal borderWidth As Integer) As Image
     Dim borderColor As Color = Color.Gray ' select color for border of image
     Dim mypen As New Pen(borderColor, borderWidth * 2)
     Dim newSize As Size = New Size(original.Width + borderWidth * 2, original.Height + borderWidth * 2)

     Dim img As Bitmap = New Bitmap(newSize.Width, newSize.Height)
     Dim g As Graphics = Graphics.FromImage(img)

     g.DrawImage(original, New Point(borderWidth, borderWidth))
     g.DrawRectangle(mypen, 0, 0, newSize.Width, newSize.Height)
     g.Dispose()
     Return img
 End Function

I got this AppendBorder function from site http://vbcity.com/forums/t/163882.aspx

Happy Coding!
:)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900