Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I think by understanding this example you can do what you're attending to do :</p> <p>I have a main form called <code>Form1</code> I want to show User Choices in this form . and also I added a new form called <code>Preferences</code> so user will be able to choose date Format and Keyboard Layout : </p> <p>my radio buttons are named like this :</p> <pre><code>RB_D_1 RB_D_2 . . . </code></pre> <p>after user clicks on <code>Submit Changes</code> we'll check which radioButton is selected and store it's <code>Text</code> property (ex <code>RB_D_1.text</code> is "dd/MM/yyyy" ) to a <code>Public String Variable</code> called <code>DateFormat</code> here we go :</p> <pre><code> public string DataFormat, KeyboardFormat; private void CMDSubmit_Click(object sender, EventArgs e) { if (RB_D_1.Checked) DataFormat = RB_D_1.Text; else if (RB_D_2.Checked) DataFormat = RB_D_2.Text; else if (RB_D_3.Checked) DataFormat = RB_D_3.Text; else if (RB_D_4.Checked) DataFormat = RB_D_4.Text; else DataFormat = "MM/DD/YYYY"; // default format //-------------------------------- if (RB_L_1.Checked) KeyboardFormat = RB_L_1.Text; else if (RB_L_2.Checked) KeyboardFormat = RB_L_2.Text; else if (RB_L_3.Checked) KeyboardFormat = RB_L_3.Text; else if (RB_L_4.Checked) KeyboardFormat = RB_L_4.Text; else KeyboardFormat = "QWERTY"; // default format this.Close(); } </code></pre> <p>now we have saved user choices in two string variables so we can reach them from our <code>Form1</code></p> <p>in <code>Form1</code> whenever user clicks on <code>Setting</code> we'll make an object from our <code>Preferences</code> form and Show it to user after closing the Preferences form , we'll check those two string Variables which we already talked about and decide what to do with those results :</p> <p>for example I stored those results into another two string variables and Showed Them in <code>TextBoxes</code></p> <pre><code> private void CMDSettings_Click(object sender, EventArgs e) { // showing the Preferences form to user Preferences pref = new Preferences(); pref.ShowDialog(); // getting results from Preferences Form dateFormat = pref.DataFormat; keyboardFormat = pref.KeyboardFormat; // Showing the Result in TextBoxes textBox1.Text = dateFormat ; textBox2.Text = keyboardFormat; } </code></pre> <p><strong>UPDATE 2 :</strong></p> <p>change <code>DateStamp()</code> like this :</p> <pre><code>private void DateStamp() { if (dateFormat.ToUpper() == "DD/MM/YYYY") { int CaretPosition = richTextBoxPrintCtrl1.SelectionStart; string TextBefore = richTextBoxPrintCtrl1.Text.Substring(0, CaretPosition); string textAfter = richTextBoxPrintCtrl1.Text.Substring(CaretPosition); string currentDate = DateTime.Now.ToString("dd-MM-yyyy"); richTextBoxPrintCtrl1.SelectedText = currentDate; } else if (dateFormat.ToUpper() == "MM/DD/YYYY") { int CaretPosition = richTextBoxPrintCtrl1.SelectionStart; string TextBefore = richTextBoxPrintCtrl1.Text.Substring(0, CaretPosition); string textAfter = richTextBoxPrintCtrl1.Text.Substring(CaretPosition); string currentDate = DateTime.Now.ToString("MM-dd-yyyy"); richTextBoxPrintCtrl1.SelectedText = currentDate; } else if (dateFormat.ToUpper() == "YYYY/DD/MM") { int CaretPosition = richTextBoxPrintCtrl1.SelectionStart; string TextBefore = richTextBoxPrintCtrl1.Text.Substring(0, CaretPosition); string textAfter = richTextBoxPrintCtrl1.Text.Substring(CaretPosition); string currentDate = DateTime.Now.ToString("yyyy-dd-MM"); richTextBoxPrintCtrl1.SelectedText = currentDate; } else if (dateFormat.ToUpper() == "YYYY/MM/DD") { int CaretPosition = richTextBoxPrintCtrl1.SelectionStart; string TextBefore = richTextBoxPrintCtrl1.Text.Substring(0, CaretPosition); string textAfter = richTextBoxPrintCtrl1.Text.Substring(CaretPosition); string currentDate = DateTime.Now.ToString("yyyy-MM-dd"); richTextBoxPrintCtrl1.SelectedText = currentDate; } } </code></pre> <p><strong>UPDATE 3 :</strong></p> <p>for remembering user choices do this :</p> <p>add this function to <code>Preferences</code></p> <pre><code> public void UpdateUserChoice(string date,string keyboard) { if (date == RB_D_1.Text) RB_D_1.Checked = true; else if (date == RB_D_2.Text) RB_D_2.Checked = true; else if (date == RB_D_3.Text) RB_D_3.Checked = true; else if (date == RB_D_4.Text) RB_D_4.Checked = true; //--------------------------- if (keyboard == RB_L_1.Text) RB_L_1.Checked = true; else if (keyboard == RB_L_2.Text) RB_L_2.Checked = true; else if (keyboard == RB_L_3.Text) RB_L_3.Checked = true; else if (keyboard == RB_L_4.Text) RB_L_4.Checked = true; } </code></pre> <p>and change the old way of showing to user like this : </p> <pre><code> private void CMDSettings_Click(object sender, EventArgs e) { Preferences pref = new Preferences(); pref.UpdateUserChoice(dateFormat, keyboardFormat); pref.ShowDialog(); dateFormat = pref.DataFormat; keyboardFormat = pref.KeyboardFormat; textBox2.Text = keyboardFormat; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload