MainForm.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #region File Description
  2. //-----------------------------------------------------------------------------
  3. // MainForm.cs
  4. //
  5. // Microsoft XNA Community Game Platform
  6. // Copyright (C) Microsoft Corporation. All rights reserved.
  7. //-----------------------------------------------------------------------------
  8. #endregion
  9. #region Using Statements
  10. using System.Windows.Forms;
  11. #endregion
  12. namespace WinFormsGraphicsDevice
  13. {
  14. // System.Drawing and the XNA Framework both define Color types.
  15. // To avoid conflicts, we define shortcut names for them both.
  16. using GdiColor = System.Drawing.Color;
  17. using XnaColor = Microsoft.Xna.Framework.Color;
  18. /// <summary>
  19. /// Custom form provides the main user interface for the program.
  20. /// In this sample we used the designer to add a splitter pane to the form,
  21. /// which contains a SpriteFontControl and a SpinningTriangleControl.
  22. /// </summary>
  23. public partial class MainForm : Form
  24. {
  25. public MainForm()
  26. {
  27. InitializeComponent();
  28. vertexColor1.SelectedIndex = 1;
  29. vertexColor2.SelectedIndex = 2;
  30. vertexColor3.SelectedIndex = 4;
  31. }
  32. /// <summary>
  33. /// Event handler updates the spinning triangle control when
  34. /// one of the three vertex color combo boxes is altered.
  35. /// </summary>
  36. void vertexColor_SelectedIndexChanged(object sender, System.EventArgs e)
  37. {
  38. // Which vertex was changed?
  39. int vertexIndex;
  40. if (sender == vertexColor1)
  41. vertexIndex = 0;
  42. else if (sender == vertexColor2)
  43. vertexIndex = 1;
  44. else if (sender == vertexColor3)
  45. vertexIndex = 2;
  46. else
  47. return;
  48. // Which color was selected?
  49. ComboBox combo = (ComboBox)sender;
  50. string colorName = combo.SelectedItem.ToString();
  51. GdiColor gdiColor = GdiColor.FromName(colorName);
  52. XnaColor xnaColor = new XnaColor(gdiColor.R, gdiColor.G, gdiColor.B);
  53. // Update the spinning triangle control with the new color.
  54. spinningTriangleControl.Vertices[vertexIndex].Color = xnaColor;
  55. }
  56. }
  57. }