Results 1 to 18 of 18

Thread: Sentering an image without background?

  1. #1
    New Member
    Join Date
    Aug 12
    Posts
    10

    Red face Sentering an image without background?

    Hi, I am new to vb, and all kind of coding really...

    But I just came up with a nice idea for a software I want to create. Does anyone know how I can make a software where people can choose a picture, and the software will open that picture, and keep it centered on the screen and keeping the software invisible? So everything you can see on screen after opening the picture is the picture itself, not the software, which should only be running the picture in the background.

    Thanks for any help!

  2. #2
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 12
    Posts
    5,512

    Re: Sentering an image without background?

    Add a picturebox to the form and dock to container. Set form borders to None. Job done.

  3. #3
    New Member
    Join Date
    Aug 12
    Posts
    10

    Re: Sentering an image without background?

    Thanks so much man! Haha, I had no idea it would be that easy ^^ Gonna try it out now

  4. #4
    New Member
    Join Date
    Aug 12
    Posts
    10

    Re: Sentering an image without background?

    Well, there is still a background...When I set the borders to none, the borders disappear but the background of the form is till there. How can I remove this?

  5. #5
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 12
    Posts
    5,512

    Re: Sentering an image without background?

    Add a picturebox to the form and dock to container.
    Name:  1.png
Views: 32
Size:  6.1 KB

    The form background cannot be seen. Obviously if there's no image in the picture box you can see the picture box background but you can simply set the Form to Invisible while that's the case with Form.Opacity = 0. If the pictures vary in size you'll have set the form and picture box sizes accordingly.

  6. #6
    New Member
    Join Date
    Aug 12
    Posts
    10

    Re: Sentering an image without background?

    Aahaa! There we go, thanks

    But I can still see the background of the image...its probably because vb cant read png files like picture view softwares... ? The thing is that I made a picture in photoshop with a transperrent background and saved it as a png file, so that we are not supose to see the background...does this not work with vb?

  7. #7
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 12
    Posts
    5,512

    Re: Sentering an image without background?

    Oh, right. Don't think it's possible with a Windows Forms program. May well be with WPF though. I'll have another look at it tomorrow.

  8. #8
    New Member
    Join Date
    Aug 12
    Posts
    10

    Re: Sentering an image without background?

    Alright, awesome : )

  9. #9
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 12
    Posts
    5,512

    Re: Sentering an image without background?

    Don't know where my brain was yesterday. I knew how to do this all along! Set the form TransparencyKey to the BackColor of the Form and the PictureBox (obviously they need to be the same). Et voila ...

    Name:  2.png
Views: 28
Size:  28.5 KB

  10. #10
    Frenzied Member boops boops's Avatar
    Join Date
    Nov 08
    Location
    Holland/France
    Posts
    1,980

    Re: Sentering an image without background?

    Hi Knetten,
    It's fairly easy to do what you want in Windows Forms as long as the image's background is a single, solid color. The main steps are to set the following properties of your startup form:
    1. BackgroundImage = your image
    2. BackColor = the image background color
    3. TransparencyKey = the image background color
    4. FormBorderStyle = None
    5. Topmost = True
    6. StartPosition = CenterScreen
    7. (optionally) ShowInTaskBar = False
    8. (optionally) you can fade the image in or out by setting the form's Opacity.

    People often use shaped forms like that as a splash screen to show on starting up a program. However, the method above has a drawback: there can only be one "transparent" color. That means you can't have smoothed (antialiased) edges, or colors of varying transparency against the desktop. WPF is much more versatile in that respect. I suggest you look at my "shaped form" entry in this forum's Code Bank (link in my signature below). It gives step-by-step instructions for making a simple hybrid WinForms-WPF solution. The image is draggable rather than centered, but that would be easy to change.

    BB

  11. #11
    New Member
    Join Date
    Aug 12
    Posts
    10

    Re: Sentering an image without background?

    Thanks guys! But is there a way to make the software "not interactive"? When I click on the image, the program "opens"...is there a way to make it not react?

  12. #12
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 12
    Posts
    5,512

    Re: Sentering an image without background?

    Not sure what you mean. It can only 'react' if you have written code for the relevant events.

  13. #13
    New Member
    Join Date
    Aug 12
    Posts
    10

    Re: Sentering an image without background?

    Allright, the thing is...I am making a program which runs a picture of a scope i created in photoshop. The scope will be placed in the center of the screen, and run in the background of a fps game. The scope makes it easyer to aim But, in fps games, your mouse automatically ends up in the middle of the screen too. So what you really do, is pressing the image of the crosshair, instead of shooting in game. So when i press the crosshair, the windows task bar shows up.

  14. #14
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 12
    Posts
    5,512

    Re: Sentering an image without background?


  15. #15
    New Member
    Join Date
    Aug 12
    Posts
    10

    Re: Sentering an image without background?

    Should I just paste all that in the form 1 code? When I did, this error shows up 3 times in the error list: Error 1 'Command1' is not declared. It may be inaccessible due to its protection level. C:\Users\Kennet\Documents\Visual Studio 2010\Projects\AimImprover 1.0\AimImprover 1.0\Form1.vb 14 12 AimImprover 1.0

  16. #16
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 12
    Posts
    5,512

    Re: Sentering an image without background?

    Um ... I did say 'adapt'!

    Command1 is obviously a button so I suggest that you move the 'Hide' code from there to the PictureBox click event and change the names accordingly. Move the 'Show' code somewhere that will activate when the application finishes (or the game).

  17. #17
    New Member
    Join Date
    Aug 12
    Posts
    10

    Re: Sentering an image without background?

    Oh my God I feel so stupid...I cant even understand that :S
    Maybe its easier for you to help me if I just send you the code I allready have, and you can directly say , or paste what codes I should : P Sorry for the trouble :S Coding have never been my strong side...
    Heres the code that was in the picture box b4 I did anything to it:

    Public Class Form1

    Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click

    End Sub

    End Class

  18. #18
    New Member
    Join Date
    Aug 12
    Posts
    10

    Re: Sentering an image without background?

    Anyone? : )

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •