Solved

form custom shape from png

Posted on 2006-11-12
6
263 Views
Last Modified: 2010-08-05
hi,
vb2005

im trying to have a form have a custom shape from a .png image. is this possible?
thanks
0
Comment
Question by:newyuppie
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 10

Expert Comment

by:Kinger247
ID: 17925693
Yes you can, I know you like links :) so :

http://www.freevbcode.com/ShowCode.asp?ID=6146

In the example it uses an simpson.png (not included !). But I just ran with an image on my machine with a mostly white background.
It skinned to the image nicely.
0
 
LVL 13

Author Comment

by:newyuppie
ID: 17925764
hi kinger, congrats on the 50000 points.

code does indeed work and it skins nicely. only problem i see is that its a bit on the slow side. for instance, im using a form set as a splashscreen, and using this code, it shows *after* the main form loads, so its taking a while to draw. on another sad note, it flickers for 1 second before drawing and its very noticeable.
does that happen in your computer too?

NY
0
 
LVL 10

Accepted Solution

by:
Kinger247 earned 500 total points
ID: 17925982
Thanks, didn't notice but I'm very pleased.

Ok, the problem is bad. But there is a solution. The process is looping through all items in the image matrix, so thats the slow part.
So what I would do, it run the code again with the new Form1_Load code below
What this does is on the first run, it creates a text file c:\test.txt with the coordinates from the image.
Then it loads these coordinates from the text file into a rectangles array and uses that to create the region.
So save these coordinates in a local file (included in your app). And call these coordinates instead.

The below code includes writing the coordinates to a texfile and retrieving them. Obviously you will only need to do this once to get the data in the text file, then copy it to an internal project file and use that in future runs to create the form region.


    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'If setting the background image at design-time, remove the next 2 lines:
        Dim Background As New Bitmap("c:\piccy.bmp")
        Me.BackgroundImage = Background
        Me.Width = Me.BackgroundImage.Width
        Me.Height = Me.BackgroundImage.Height
        Me.FormBorderStyle = FormBorderStyle.None

        '//-- Create a rectangles array from the forms region
        Dim rec() As RectangleF = MakeRegion(Me.BackgroundImage).GetRegionScans(New Drawing2D.Matrix)

        '//-- Save to text file.
        Dim strRecCoord As String
        Dim objStreamWriter As System.IO.StreamWriter
        objStreamWriter = New System.IO.StreamWriter("C:\Test.txt")

        For i As Integer = 0 To rec.GetUpperBound(0) - 1
            strRecCoord = rec(i).X & ":" & rec(i).Y & ":" & rec(i).Width & ":" & rec(i).Height & "|"
            objStreamWriter.Write(strRecCoord)
        Next

        objStreamWriter.Close()

        '//-- Read from text file.
        Dim objStreamReader As New System.IO.StreamReader("C:\Test.txt")
        Dim Rect() As String = objStreamReader.ReadToEnd.Split("|")
        objStreamReader.Close()

        '//-- Split for rect
        Dim RectRegion(Rect.GetUpperBound(0)) As RectangleF
        For i As Integer = 0 To Rect.GetUpperBound(0) - 1
            RectRegion(i).X = Rect(i).Split(":")(0)
            RectRegion(i).Y = Rect(i).Split(":")(1)
            RectRegion(i).Width = Rect(i).Split(":")(2)
            RectRegion(i).Height = Rect(i).Split(":")(3)
        Next

        '//-- Set the region
        Dim gp As New System.Drawing.Drawing2D.GraphicsPath
        gp.AddRectangles(RectRegion)
        Me.Region = New Region(gp)
        gp.Dispose()
    End Sub
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 13

Author Comment

by:newyuppie
ID: 17926806
very savvy indeed!
it does seem to work fine, let me perform some tests ill get back to you
NY
0
 
LVL 13

Author Comment

by:newyuppie
ID: 17955935
sorry to have taken some days, i was off. great answer!
NY
0
 
LVL 10

Expert Comment

by:Kinger247
ID: 17956087
no problem, yes thought I hadn't seen any comments from you for a couple of days ..
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question