Click here to Skip to main content
13,147,037 members (59,481 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I have used this code for Get image of my Control.

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))

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 1-Nov-12 20:22pm
Updated 1-Nov-12 21:31pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.
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)

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)
     Return img
 End Function

I got this AppendBorder function from site

Happy Coding!

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.170915.1 | Last Updated 2 Nov 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100