Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9037067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T09:09:31+00:00 2026-06-16T09:09:31+00:00

jQuery can select the Child of something, or Parent, or next tag. Does C#

  • 0

jQuery can select the Child of something, or Parent, or next tag. Does C# have something similar to this behavior. For example, I have a horizontal StackPanel that has a Label, a TextBox, and a Button.

Can I target the Label to change color if the TextBox is currently selected without using if else statements referring to the name of the Label? Some function like “this label” in this StackPanel that this TextBox is in.

Example: Whenever a text box is selected, the label next to it changes to yellow background.

enter image description here

I’m not sure how to write this in C# so I will try to explain with regular text.

if (this) textbox is selected
    get the label next to it
    change the label background to a color

else
    remove the color if it is not selected

The Method() will trigger based on the currently selected TextBox.

A function like this can have the same code but be able to target different Labels once the focus changes to a different TextBox. Is this possible?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T09:09:32+00:00Added an answer on June 16, 2026 at 9:09 am

    Yes, You can; you should handle events. for example in this case you handle ‘TextBox.GotFocus` event.

    void tb_GotFocus(object sender, GotFocusEventArgs e)
    {
         // here you can get the StackPanel as the parent of the textBox and 
         // search for the Lable
         TextBox tb=(TextBox)sender;
         StackPanel sp=tb.Parent as StackPanel;
    
         // and ...
    }
    

    If you want to omplete this example let me know.

    Edit
    This is a working Example:

    Use this Window to show the results:

    Window win = new Window();
            StackPanel stack = new StackPanel { Orientation = Orientation.Vertical };
            stack.Children.Add(new CustomControl());
            stack.Children.Add(new CustomControl());
            stack.Children.Add(new CustomControl());
            stack.Children.Add(new CustomControl());
            win.Content = stack;
    win.ShowDialog();
    

    Here, is the CustomControl class:

    public class CustomControl : Border
    {
        Label theLabel = new Label {Content="LableText" };
        TextBox theTextbox = new TextBox {MinWidth=100 };
    
        public CustomControl()
        {
            StackPanel sp = new StackPanel { Orientation=Orientation.Horizontal};
            this.Child = sp;
            sp.Children.Add(theLabel);
            sp.Children.Add(theTextbox);
    
            theTextbox.GotFocus += new RoutedEventHandler(tb_GotFocus);
            theTextbox.LostFocus += new RoutedEventHandler(tb_LostFocus);
        }
    
    
        void tb_GotFocus(object sender, RoutedEventArgs e)
        {
            theLabel.Background = Brushes.Yellow;
        }
        void tb_LostFocus(object sender, RoutedEventArgs e)
        {
            theLabel.Background = Brushes.Transparent;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

how can i select the current link via jquery if I have a div
I have jNiceIT plugin for Jquery. How can i disable the select dropdown styled
How to use jquery selectors to select parent only but exclude child HTML <div
How can I use jQuery to select all p tags that have at least
How i can select all child in a parent div with deference child level
To select a child node in jQuery one can use children() but also find().
i was wondering if jquery can be used to manipulate my select html element
I want to use JQuery to replace an entire <tr> . I can select
How can I select elements (using jQuery) that do not contain any elements? For
How can I select the contents of the whole page using jQuery for later

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.