Guest User

Untitled

a guest
Jun 22nd, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. namespace WindowsApplication1
  2. {
  3. public partial class Form1 : Form
  4. {
  5. public Form1()
  6. {
  7. InitializeComponent();
  8. }
  9.  
  10.  
  11. private void draw_Click(object sender, EventArgs e)
  12. {
  13. tableLayoutPanel1.Controls.Clear();
  14. string[] results = { "Heads", "Tails" };
  15. int nCoins = Convert.ToInt32(coins.Value);
  16. Random random = new Random();
  17. for(int i = 0; i < nCoins; i++) {
  18. ComboBox coin = new ComboBox();
  19. coin.Items.AddRange(results);
  20. coin.SelectedIndex = random.Next(0, 2);
  21. tableLayoutPanel1.Controls.Add(coin, 0, i);
  22. }
  23. }
  24. }
  25. }
  26.  
  27. coin.DropDownStyle = ComboBoxStyle.DropDownList;
  28.  
  29. coin.CanFocus = false;
  30.  
  31. coin.TopLevelControl.Focus();
  32.  
  33. using System;
  34. using System.Windows.Forms;
  35.  
  36. namespace WindowsFormsApplication1
  37. {
  38. public partial class Form1 : Form
  39. {
  40. public Form1()
  41. {
  42. InitializeComponent();
  43. button1.Click += new EventHandler(button1_Click);
  44. }
  45.  
  46. private void button1_Click(object sender, EventArgs e)
  47. {
  48. tableLayoutPanel1.Controls.Clear();
  49. string[] results = { "Heads", "Tails" };
  50. int nCoins = Convert.ToInt32(coins.Value);
  51. Random random = new Random();
  52. for (int i = 0; i < nCoins; i++)
  53. {
  54. ComboBox coin = new ComboBox();
  55. coin.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
  56. coin.Items.AddRange(results);
  57. coin.SelectedIndex = random.Next(0, 2);
  58. tableLayoutPanel1.Controls.Add(coin, 0, i);
  59. }
  60. }
  61.  
  62. private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
  63. {
  64. this.ActiveControl = null;
  65. }
  66.  
  67. }
  68. }
  69.  
  70. public class CustomComboBox : ComboBox
  71. {
  72. private const int WM_SIZE = 0x0005;
  73.  
  74. protected override void WndProc(ref Message m)
  75. {
  76. base.WndProc(ref m);
  77.  
  78. // A fix for ComboBoxStyle.DropDown mode.
  79. if (DropDownStyle == ComboBoxStyle.DropDown
  80. && (m.Msg & WM_SIZE) == WM_SIZE)
  81. {
  82. Select(0, 0);
  83. }
  84. }
  85. }
Add Comment
Please, Sign In to add comment