Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# VB.NET WinForm
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))
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 1-Nov-12 21:22pm
Edited 1-Nov-12 22:31pm
v2

1 solution

Rate this: bad
good
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)
     g.Dispose()
     Return img
 End Function
I got this AppendBorder function from site http://vbcity.com/forums/t/163882.aspx
 
Happy Coding!
Smile | :)
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 565
1 Kornfeld Eliyahu Peter 409
2 Maciej Los 369
3 DamithSL 196
4 OriginalGriff 188
0 OriginalGriff 6,353
1 DamithSL 4,854
2 Maciej Los 4,466
3 Kornfeld Eliyahu Peter 4,058
4 Sergey Alexandrovich Kryukov 3,897


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 2 Nov 2012
Copyright © CodeProject, 1999-2014
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