Giving Control a Transparent Background

Discussion in 'Programming & Scripting' started by Nothinbeter2do, Jan 2, 2009 with 12 replies and 207 views.

  1. Nothinbeter2do

    Nothinbeter2do Banned

    Messages:
    2,425
    Ratings:
    526
    How can you give control a transparent background?


    The code I'm using:
    Code:
    Public Class Form1
    
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    SetStyle(ControlStyles.SupportsTransparentBackColor, True)
    Me.BackColor = Color.Transparent
    End Sub
    End Class
    When the application starts up, it doesn't affect anything. How can I do this?
     
  2. Luxurious Meat

    Luxurious Meat Getting There

    Messages:
    615
    Ratings:
    120
    Like this?
    [​IMG]

    Set the forms 'TransparencyKey' to "Control", and leave it's 'BackColor' as "Control".
     
    • Like Like x 1
  3. OP
    Nothinbeter2do

    Nothinbeter2do Banned

    Messages:
    2,425
    Ratings:
    526
    Thanks. Also, how do I load a string from My.Resources?

    I'm using this code
    Code:
    Public Class Form1
    
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    If My.Resources.YourGamertag.Value = "" Then
    Form2.Show()
    End If
    End Sub
    End Class
    But I get the error:
    Code:
    'Value' is not a member of 'String'.
     
  4. Michael Allison

    Michael Allison Enthusiast

    Messages:
    232
    Ratings:
    13
    Just remove the ".Value", assuming your resource is a string. O.o

    And never put it there again... LOL.
     
    • Like Like x 1
  5. OP
    Nothinbeter2do

    Nothinbeter2do Banned

    Messages:
    2,425
    Ratings:
    526
    Thanks. But now when I try to save to it I get the error:
    Code:
    Property 'String' is 'ReadOnly'.
    Im using the code:
    Code:
    My.Resources.String = TextBox1.Text
     
  6. Luxurious Meat

    Luxurious Meat Getting There

    Messages:
    615
    Ratings:
    120
    Remove the ".Value" so it's just:
    Code:
    If My.Resources.YourGamertag= "" Then
    Form2.Show()
    End If
     
  7. OP
    Nothinbeter2do

    Nothinbeter2do Banned

    Messages:
    2,425
    Ratings:
    526
    Thanks. But that was already answered. Could you answer my other question?
     
  8. Ibdc

    Ibdc Retired Retired

    Messages:
    5,100
    Ratings:
    2,072
    • Like Like x 1
  9. Luxurious Meat

    Luxurious Meat Getting There

    Messages:
    615
    Ratings:
    120
    The "My.Resources" members are all read only, and cannot be changed at runtime. Use the "My.Settings" namespace, if you wish to be able to change them at runtime.
     
    • Like Like x 1
  10. OP
    Nothinbeter2do

    Nothinbeter2do Banned

    Messages:
    2,425
    Ratings:
    526
    Thanks. If I have any more questions, I'll post them here.
     
  11. Michael Allison

    Michael Allison Enthusiast

    Messages:
    232
    Ratings:
    13
    Sorry, I didn't understand you were trying to write to the value.

    Yeah, Ibdc is right... however, if your application installs, you can always save them in a settings file in its directory. That would be just as effective, and less time taking, considering you can store many values in that one text file as opposed to writing a bunch of separate registry keys.
     
  12. Ibdc

    Ibdc Retired Retired

    Messages:
    5,100
    Ratings:
    2,072
    Well really he's making something that has to do with a person's gamertag, so I didn't see the sense in writing to a file just to store one, maybe two strings.
     
  13. Michael Allison

    Michael Allison Enthusiast

    Messages:
    232
    Ratings:
    13
    Yeah, but you never know, it could evolve into a larger project, and preventing a future question is never a bad idea... anyway, sorry, I think I'm just posting to use up the caffeine. :biggrin: