Solved

form custom shape from png

Posted on 2006-11-12
6
255 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
  • 3
  • 3
6 Comments
 
LVL 10

Expert Comment

by:Kinger247
Comment Utility
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
Comment Utility
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
Comment Utility
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 13

Author Comment

by:newyuppie
Comment Utility
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
Comment Utility
sorry to have taken some days, i was off. great answer!
NY
0
 
LVL 10

Expert Comment

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

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

772 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now