?
Solved

form custom shape from png

Posted on 2006-11-12
6
Medium Priority
?
265 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 2000 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Industry Leaders: 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!

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

765 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