Results 1 to 9 of 9

Thread: change listbox's bgcolor

  1. #1

    Thread Starter
    Member frix199's Avatar
    Join Date
    Dec 2005
    Location
    Thessaloniki, Greece iamthebest: True
    Posts
    59

    change listbox's bgcolor

    hey!

    i have this code in form2 :

    VB Code:
    1. Dim main As New Form1
    2. main.win.BackColor = main.win.BackColor.Black 'win is a listbox control

    but it doesnt works and i dont know why

    (when i try me.win.BackColor = me.win.BackColor.Black in the form1 it works)

    Thanks!


    Human beings are a disease, a cancer of this planet, you are a plague, and we are the cure.

  2. #2
    Fanatic Member MetalKid's Avatar
    Join Date
    Aug 2005
    Location
    Green Bay, Wisconsin
    Posts
    534

    Re: change listbox's bgcolor

    main.win.BackColor = System.Drawing.Color.Black

  3. #3

    Thread Starter
    Member frix199's Avatar
    Join Date
    Dec 2005
    Location
    Thessaloniki, Greece iamthebest: True
    Posts
    59

    Re: change listbox's bgcolor

    still wont work....


    Human beings are a disease, a cancer of this planet, you are a plague, and we are the cure.

  4. #4
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,521

    Re: change listbox's bgcolor

    I think the issue is that you are creating a new instance of form1.

    I am assuming that form1 opened form2 then an event occurs on form2 that cause the listbox on form1 to change colors.

    There are a few ways to do this.
    If the list box needs to change colors instantly you need to pass a reference of form1 to form2.
    if the listbox doesn't need to change until after form2 closes you can have some sort of flag.

    If I assume correctly tell me what needs to happen and if you need an example I will give you one. Or if I assumed wrong. Tell me exactly what you are trying to do.

  5. #5

    Thread Starter
    Member frix199's Avatar
    Join Date
    Dec 2005
    Location
    Thessaloniki, Greece iamthebest: True
    Posts
    59

    Re: change listbox's bgcolor

    i open the form2 with ShowDialog(), and i want to change the color of the listbox in form1.
    it doesn't matter if it changes imediately or after form2 is closed...

    thanks!


    Human beings are a disease, a cancer of this planet, you are a plague, and we are the cure.

  6. #6
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,521

    Re: change listbox's bgcolor

    On form2 create a color property. Then after the dilog closes set the listbox to that color

    VB Code:
    1. 'on Form2
    2. ' both the private variable and the propertery are declared at the class level
    3. Private _listBoxColor as Color = Color.White
    4.  
    5. Public Property ListBoxColor
    6.   Get
    7.       Return _ListBoxColor
    8.   End Get
    9.   Set(value As Color)
    10.       _ListBOxColor = Value
    11.   End Set
    12. End Property
    13.  
    14.  
    15.    'then where you have
    16.    'main.win.BackColor = main.win.BackColor.Black 'win is a listbox control
    17.    _ListBoxColor = Color.Black
    18.  
    19.  
    20. 'Form1 Class
    21.  frm2.ShowDialog
    22.  win.BackColor = frm2.ListBoxColor

  7. #7

    Thread Starter
    Member frix199's Avatar
    Join Date
    Dec 2005
    Location
    Thessaloniki, Greece iamthebest: True
    Posts
    59

    Re: change listbox's bgcolor

    this is what error i get:

    'Set' parameter must have the same type as the containing property.


    Human beings are a disease, a cancer of this planet, you are a plague, and we are the cure.

  8. #8
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,521

    Re: change listbox's bgcolor

    Upps sorry.
    declare the property like this
    VB Code:
    1. Public Property ListBoxColor [B]As Color[/B]
    2. 'everything else the same

  9. #9

    Thread Starter
    Member frix199's Avatar
    Join Date
    Dec 2005
    Location
    Thessaloniki, Greece iamthebest: True
    Posts
    59

    Re: change listbox's bgcolor

    i found another way, but yours also helped

    thanks!

    (HAHA im gonna rate you )


    Human beings are a disease, a cancer of this planet, you are a plague, and we are the cure.

Posting Permissions

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



Click Here to Expand Forum to Full Width