Click here to Skip to main content
15,895,011 members
Home / Discussions / C#
   

C#

 
AnswerRe: c# how to Temporary pause button click event until mousedoubleclick on new form-listbox shown? Pin
OriginalGriff18-Apr-18 23:50
mveOriginalGriff18-Apr-18 23:50 
AnswerRe: c# how to Temporary pause button click event until mousedoubleclick on new form-listbox shown? Pin
BillWoodruff20-Apr-18 3:59
professionalBillWoodruff20-Apr-18 3:59 
If you create a new instance of Form2 inside the 'for loop on Form1 ... where the user makes some choice through direct action ... unless you somehow pass the result of the user action back to Form1 ... then there is no point showing Form2.

I suggest:

1. create one instance of Form2 in Form1

2. create a public delegate (use 'Action) in Form2 that is invoked in the ListBox SelectedValueChanged event handler.

3. in Form1 insert your code for the Action into the instance of Form2.

4. in the for loop on Form1 show Form2 using ShowDialog

Form1
using System;
using System.Windows.Forms;

namespace Test
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        Form2 f2 = new Form2();
        string listBoxChoice;

        private void Form1_Load(object sender, EventArgs e)
        {
            f2.SendListBoxChoice += SendListBoxChoice;
        }

        private void SendListBoxChoice(string choice)
        {
            listBoxChoice = choice;
        }

        private void testButton_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < 2; i++)
            {
                listBoxChoice = "";

                f2.ShowDialog(this);

                if (listBoxChoice != "")
                {
                    // do something with the choice

                    switch (listBoxChoice)
                    {
                        case "1":
                            break;
                    }
                }
            }
        }
    }
}
Form2
using System;
using System.Windows.Forms;

namespace Test
{
    public partial class Form2 : Form
    {
        public Action<string> SendListBoxChoice;

        public Form2()
        {
            InitializeComponent();
        }

        private void listBox1_SelectedValueChanged(object sender, EventArgs e)
        {
            if (SendListBoxChoice != null)
            {
                SendListBoxChoice(listBox1.SelectedItem.ToString());
            }
        }
    }
}

«... thank the gods that they have made you superior to those events which they have not placed within your own control, rendered you accountable for that only which is within you own control For what, then, have they made you responsible? For that which is alone in your own power—a right use of things as they appear.» Discourses of Epictetus Book I:12

Questionplease hellp me how to write a code in c# which is send warning message before specific time thanks Pin
ahmedoze18-Apr-18 16:09
ahmedoze18-Apr-18 16:09 
AnswerRe: please hellp me how to write a code in c# which is send warning message before specific time thanks Pin
OriginalGriff18-Apr-18 19:50
mveOriginalGriff18-Apr-18 19:50 
QuestionRe: please hellp me how to write a code in c# which is send warning message before specific time thanks Pin
Eddy Vluggen18-Apr-18 22:50
professionalEddy Vluggen18-Apr-18 22:50 
AnswerRe: please hellp me how to write a code in c# which is send warning message before specific time thanks Pin
Richard MacCutchan19-Apr-18 0:57
mveRichard MacCutchan19-Apr-18 0:57 
AnswerRe: please hellp me how to write a code in c# which is send warning message before specific time thanks Pin
Pete O'Hanlon18-Apr-18 23:16
mvePete O'Hanlon18-Apr-18 23:16 
AnswerRe: please hellp me how to write a code in c# which is send warning message before specific time thanks Pin
Kandula Santosh21-Apr-18 8:15
Kandula Santosh21-Apr-18 8:15 
QuestionProcess.start is slow compared to Powershell Start-Process Pin
Neal Conrardy18-Apr-18 8:47
Neal Conrardy18-Apr-18 8:47 
AnswerRe: Process.start is slow compared to Powershell Start-Process Pin
Dave Kreskowiak18-Apr-18 17:20
mveDave Kreskowiak18-Apr-18 17:20 
GeneralRe: Process.start is slow compared to Powershell Start-Process Pin
Neal Conrardy19-Apr-18 5:15
Neal Conrardy19-Apr-18 5:15 
AnswerRe: Process.start is slow compared to Powershell Start-Process Pin
Eddy Vluggen18-Apr-18 22:55
professionalEddy Vluggen18-Apr-18 22:55 
QuestionSend data toServer with two parameters Pin
Carmen_Mundi18-Apr-18 8:44
Carmen_Mundi18-Apr-18 8:44 
QuestionRe: Send data toServer with two parameters Pin
Richard MacCutchan18-Apr-18 21:55
mveRichard MacCutchan18-Apr-18 21:55 
AnswerRe: Send data toServer with two parameters Pin
Carmen_Mundi19-Apr-18 5:55
Carmen_Mundi19-Apr-18 5:55 
GeneralRe: Send data toServer with two parameters Pin
Richard MacCutchan19-Apr-18 6:13
mveRichard MacCutchan19-Apr-18 6:13 
GeneralRe: Send data toServer with two parameters Pin
Carmen_Mundi19-Apr-18 7:37
Carmen_Mundi19-Apr-18 7:37 
GeneralRe: Send data toServer with two parameters Pin
Richard MacCutchan19-Apr-18 21:53
mveRichard MacCutchan19-Apr-18 21:53 
QuestionReading a specific portion of a text file Pin
Member 1377871518-Apr-18 4:42
Member 1377871518-Apr-18 4:42 
AnswerRe: Reading a specific portion of a text file Pin
OriginalGriff18-Apr-18 4:59
mveOriginalGriff18-Apr-18 4:59 
GeneralRe: Reading a specific portion of a text file Pin
Member 1377871518-Apr-18 7:34
Member 1377871518-Apr-18 7:34 
GeneralRe: Reading a specific portion of a text file Pin
OriginalGriff18-Apr-18 8:16
mveOriginalGriff18-Apr-18 8:16 
GeneralRe: Reading a specific portion of a text file Pin
Member 1377871518-Apr-18 11:29
Member 1377871518-Apr-18 11:29 
AnswerRe: Reading a specific portion of a text file Pin
Gerry Schmitz18-Apr-18 5:54
mveGerry Schmitz18-Apr-18 5:54 
QuestionManagementScope, did it get deprecated or something? Pin
Robert Oujesky18-Apr-18 4:38
Robert Oujesky18-Apr-18 4:38 

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.