Click here to Skip to main content
15,906,574 members
Home / Discussions / C#
   

C#

 
GeneralRe: Having Multiple Services in a single project Pin
M. J. Jaya Chitra5-Jul-07 2:58
M. J. Jaya Chitra5-Jul-07 2:58 
QuestionDiffrence between NHibernate and LinQ ? Pin
vytheese5-Jul-07 0:11
professionalvytheese5-Jul-07 0:11 
AnswerRe: Diffrence between NHibernate and LinQ ? Pin
Pete O'Hanlon5-Jul-07 0:45
mvePete O'Hanlon5-Jul-07 0:45 
Questionfocus on text boxes Pin
treah5-Jul-07 0:01
treah5-Jul-07 0:01 
AnswerRe: focus on text boxes Pin
ganti.r5-Jul-07 0:15
ganti.r5-Jul-07 0:15 
AnswerRe: focus on text boxes Pin
Martin#5-Jul-07 0:18
Martin#5-Jul-07 0:18 
GeneralRe: focus on text boxes Pin
treah5-Jul-07 20:22
treah5-Jul-07 20:22 
GeneralRe: focus on text boxes Pin
Martin#5-Jul-07 20:53
Martin#5-Jul-07 20:53 
Hello,

I did a little test project to show you the possibilities!
Created an inherited TextBox, like suggested with an additional property:
public class TextBoxSound : System.Windows.Forms.TextBox
{
    private string _soundlocation = "";

    [DefaultValue("")]
    public string SoundLocation
    {
        get
        {
            return _soundlocation;
        }
        set
        {
            if(value!=_soundlocation)
            {
                _soundlocation = value;

                //Here you could fire an event which is handled from the Form.
                //If It is the actuall TextBox it could interrupt the Sound and start the new one.
            }
        }
    }


In the Forms code (where I placed the TextBoxSound instances):
public Form1()
{
    InitializeComponent();

    foreach(Control c in this.Controls) //iterating threw all the Controls on the Form
    {
        TextBoxSound tbSound = c as TextBoxSound;  //casting the Control to TextBoxSound
        if(tbSound!=null)   //If ok
        {
            //Add GotFocus Event Handler
            tbSound.GotFocus+=new EventHandler(tbSound_GotFocus);
        }
    }

}

/// <summary>
/// Evnet Handler for all TextBoxSound instances on the Form
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void tbSound_GotFocus(object sender, EventArgs e)
{
    TextBoxSound tbSound = sender as TextBoxSound;  //casting the sender to TextBoxSound
    if(tbSound!=null)   //If ok, which should allways be the case
    {
        ActTextBoxSound = tbSound;
    }
}

private TextBoxSound _actTextBoxSound = null;
/// <summary>
/// TextBoxSound instance which is actually focused or was Focused Last
/// </summary>
public TextBoxSound ActTextBoxSound
{
    get
    {
        return _actTextBoxSound;
    }
    set
    {
        if(value!=_actTextBoxSound)
        {
            _actTextBoxSound = value;

            //Here you could place fancy code to interrupt the actual played sound or do something else.
        }
    }
}

/// <summary>
/// On button click
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void bPlaySound_Click(object sender, System.EventArgs e)
{
    //You only have to use the ActTextBoxSound property now.
    if(ActTextBoxSound!=null)
    {
        myPlayer.SoundLocation = ActTextBoxSound.SoundLocation;
        myPlayer.Play();
    }
    else
    {
        //Show MessageBox "No TextBox selected"
    }
}


Hope it helps!

All the best,

Martin
Questionobject[] result Pin
Sk8tz4-Jul-07 23:00
professionalSk8tz4-Jul-07 23:00 
AnswerRe: object[] result Pin
originSH4-Jul-07 23:36
originSH4-Jul-07 23:36 
GeneralRe: object[] result Pin
Sk8tz4-Jul-07 23:41
professionalSk8tz4-Jul-07 23:41 
GeneralRe: object[] result Pin
originSH4-Jul-07 23:44
originSH4-Jul-07 23:44 
GeneralRe: object[] result Pin
Sk8tz4-Jul-07 23:47
professionalSk8tz4-Jul-07 23:47 
GeneralRe: object[] result Pin
originSH4-Jul-07 23:52
originSH4-Jul-07 23:52 
QuestionWebClient?? C#2005 Pin
bug_aonz4-Jul-07 22:47
bug_aonz4-Jul-07 22:47 
QuestionRemoving event handlers Pin
archies_san4-Jul-07 22:44
archies_san4-Jul-07 22:44 
AnswerRe: Removing event handlers Pin
Diana Fernandez4-Jul-07 23:19
Diana Fernandez4-Jul-07 23:19 
AnswerRe: Removing event handlers Pin
Martin#4-Jul-07 23:33
Martin#4-Jul-07 23:33 
GeneralRe: Removing event handlers Pin
archies_san5-Jul-07 20:21
archies_san5-Jul-07 20:21 
GeneralRe: Removing event handlers Pin
Martin#5-Jul-07 20:30
Martin#5-Jul-07 20:30 
AnswerRe: Removing event handlers Pin
Bekjong4-Jul-07 23:37
Bekjong4-Jul-07 23:37 
QuestionAnimated gifs Pin
pokabot4-Jul-07 21:48
pokabot4-Jul-07 21:48 
AnswerRe: Animated gifs Pin
Urs Enzler4-Jul-07 22:01
Urs Enzler4-Jul-07 22:01 
QuestionEditorAttribute Pin
urbane.tiger4-Jul-07 21:36
urbane.tiger4-Jul-07 21:36 
QuestionHelp for developing search engine .net Pin
rparsi4-Jul-07 21:12
rparsi4-Jul-07 21:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.