Results 1 to 4 of 4

Thread: (Sender as System.Type)... Help?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2005
    Posts
    31

    (Sender as System.Type)... Help?

    This is what I have:

    Code:
    if (sender is TextBox)
    	(sender as TextBox).BackColor = Color.White;
    else
    	(sender as ListBox).BackColor = Color.White;
    This is what I want:

    Code:
    System.Type t = (sender is TextBox) ? TextBox:ListBox;
    (sender as t).BackColor = Color.White;
    But that doesn't work. Any ideas?

    Dan

  2. #2
    Addicted Member
    Join Date
    Jan 2005
    Location
    Montréal
    Posts
    160

    Re: (Sender as System.Type)... Help?

    bout this?

    Code:
    ((System.Windows.Forms.Control)sender).BackColor = Color.Blue;
    There are no stupid questions, but a whole bunch of dumb sayings !

    Save time on database code, try DataLG !

  3. #3
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Code:
    ((Control)sender).BackColor = (sender is TextBox)?((TextBox)sender).BackColor=Color.Black :((ListBox)sender).BackColor=Color.Red;	
    
    //Or 
    
    Color c = (sender is TextBox)?((TextBox)sender).BackColor=Color.Black :((ListBox)sender).BackColor=Color.Red;

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Feb 2005
    Posts
    31

    Resolved Re: (Sender as System.Type)... Help?

    Quote Originally Posted by sixfeetsix
    Code:
    ((System.Windows.Forms.Control)sender).BackColor = Color.Blue;
    Perfect, just what I needed. Thanks.

    Dan

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