|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.ComponentModel; |
| 4 | +using System.Data; |
| 5 | +using System.Drawing; |
| 6 | +using System.Linq; |
| 7 | +using System.Text; |
| 8 | +using System.Threading.Tasks; |
| 9 | +using System.Windows.Forms; |
| 10 | +using NativeDarkMode_Lib; |
| 11 | +using NativeDarkMode_Lib.Utils; |
| 12 | + |
| 13 | +namespace NativeDarkMode_NET |
| 14 | +{ |
| 15 | + public partial class Form1 : Form |
| 16 | + { |
| 17 | + public Form1() |
| 18 | + { |
| 19 | + InitializeComponent(); |
| 20 | + PopulateControls(); |
| 21 | + |
| 22 | + Converter.DarkModeEnable(this); |
| 23 | + |
| 24 | + trackBar1_Scroll(this, null); |
| 25 | + } |
| 26 | + |
| 27 | + |
| 28 | + |
| 29 | + #region Data Population and Event Handlers |
| 30 | + private void PopulateControls() |
| 31 | + { |
| 32 | + // This method's content is unchanged |
| 33 | + // Tab 1: Basic Controls |
| 34 | + this.textBox1.Text = "This is a sample text."; |
| 35 | + this.maskedTextBox1.Text = "12345"; |
| 36 | + this.checkBox1.Checked = true; |
| 37 | + this.radioButton2.Checked = true; |
| 38 | + |
| 39 | + // Tab 2: List Controls |
| 40 | + string[] listItems = { "Apple", "Banana", "Cherry", "Date", "Elderberry" }; |
| 41 | + this.listBox1.Items.AddRange(listItems); |
| 42 | + this.checkedListBox1.Items.AddRange(listItems); |
| 43 | + this.comboBox1.Items.AddRange(listItems); |
| 44 | + this.listBox1.SelectedIndex = 0; |
| 45 | + this.checkedListBox1.SetItemChecked(1, true); |
| 46 | + this.comboBox1.SelectedIndex = 2; |
| 47 | + |
| 48 | + // ListView Population |
| 49 | + this.listView1.View = View.Details; |
| 50 | + this.listView1.Columns.Add("Product", 120); |
| 51 | + this.listView1.Columns.Add("Price", 70); |
| 52 | + this.listView1.Columns.Add("In Stock", 70); |
| 53 | + string[] row1 = { "Laptop", "1200", "50" }; |
| 54 | + string[] row2 = { "Mouse", "25", "200" }; |
| 55 | + string[] row3 = { "Keyboard", "75", "150" }; |
| 56 | + this.listView1.Items.Add(new ListViewItem(row1)); |
| 57 | + this.listView1.Items.Add(new ListViewItem(row2)); |
| 58 | + this.listView1.Items.Add(new ListViewItem(row3)); |
| 59 | + |
| 60 | + |
| 61 | + |
| 62 | + // Tab 3: Data Controls |
| 63 | + // DataGridView Population |
| 64 | + DataTable dt = new DataTable(); |
| 65 | + dt.Columns.Add("ID", typeof(int)); |
| 66 | + dt.Columns.Add("FirstName", typeof(string)); |
| 67 | + dt.Columns.Add("LastName", typeof(string)); |
| 68 | + dt.Columns.Add("IsMember", typeof(bool)); |
| 69 | + dt.Rows.Add(1, "John", "Doe", true); |
| 70 | + dt.Rows.Add(2, "Jane", "Smith", false); |
| 71 | + dt.Rows.Add(3, "Peter", "Jones", true); |
| 72 | + this.dataGridView1.DataSource = dt; |
| 73 | + |
| 74 | + // TreeView Population |
| 75 | + TreeNode rootNode = new TreeNode("Categories"); |
| 76 | + TreeNode electronicsNode = new TreeNode("Electronics"); |
| 77 | + electronicsNode.Nodes.Add("Laptops"); |
| 78 | + electronicsNode.Nodes.Add("Smartphones"); |
| 79 | + TreeNode booksNode = new TreeNode("Books"); |
| 80 | + booksNode.Nodes.Add("Fiction"); |
| 81 | + booksNode.Nodes.Add("Non-Fiction"); |
| 82 | + rootNode.Nodes.Add(electronicsNode); |
| 83 | + rootNode.Nodes.Add(booksNode); |
| 84 | + this.treeView1.Nodes.Add(rootNode); |
| 85 | + this.treeView1.ExpandAll(); |
| 86 | + |
| 87 | + // Tab 5: Other Controls |
| 88 | + Bitmap bmp = new Bitmap(100, 100); |
| 89 | + using (Graphics g = Graphics.FromImage(bmp)) |
| 90 | + { |
| 91 | + g.Clear(Color.FromArgb(50, 50, 50)); |
| 92 | + g.DrawString("Hi!", new Font("Arial", 24), Brushes.Silver, new PointF(20, 30)); |
| 93 | + } |
| 94 | + this.pictureBox1.Image = bmp; |
| 95 | + this.trackBar1.Value = 50; |
| 96 | + this.progressBar1.Value = 50; |
| 97 | + this.dateTimePicker1.Value = DateTime.Now; |
| 98 | + this.monthCalendar1.SelectionStart = DateTime.Now.AddDays(3); |
| 99 | + this.webBrowser1.DocumentText = "<html><body style='background-color:#212121; color:silver;'><h1>Hello, World!</h1><p>This is a WebBrowser control.</p></body></html>"; |
| 100 | + this.richTextBox1.Text = "This is a RichTextBox. You can apply formatting like "; |
| 101 | + int startIndex = this.richTextBox1.Text.Length; |
| 102 | + this.richTextBox1.AppendText("bold"); |
| 103 | + this.richTextBox1.Select(startIndex, 4); |
| 104 | + this.richTextBox1.SelectionFont = new Font(this.richTextBox1.Font, FontStyle.Bold); |
| 105 | + this.richTextBox1.SelectionColor = Color.LightSkyBlue; |
| 106 | + this.richTextBox1.AppendText(" and "); |
| 107 | + startIndex = this.richTextBox1.Text.Length; |
| 108 | + this.richTextBox1.AppendText("italic"); |
| 109 | + this.richTextBox1.Select(startIndex, 6); |
| 110 | + this.richTextBox1.SelectionFont = new Font(this.richTextBox1.Font, FontStyle.Italic); |
| 111 | + this.richTextBox1.SelectionColor = Color.LightGreen; |
| 112 | + this.richTextBox1.AppendText("."); |
| 113 | + } |
| 114 | + |
| 115 | + private void btnShowMessageBox_Click(object sender, EventArgs e) |
| 116 | + { |
| 117 | + DarkMessageBox.Show(this, "This is a simple message box.", "Message Box Title", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); |
| 118 | + } |
| 119 | + private void btnOpenFileDialog_Click(object sender, EventArgs e) |
| 120 | + { |
| 121 | + using (OpenFileDialog ofd = new OpenFileDialog()) |
| 122 | + { |
| 123 | + ofd.Title = "Open File Dialog"; |
| 124 | + ofd.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"; |
| 125 | + if (ofd.ShowDialog() == DialogResult.OK) |
| 126 | + { |
| 127 | + MessageBox.Show($"File selected: {ofd.FileName}"); |
| 128 | + } |
| 129 | + } |
| 130 | + } |
| 131 | + private void btnSaveFileDialog_Click(object sender, EventArgs e) |
| 132 | + { |
| 133 | + using (SaveFileDialog sfd = new SaveFileDialog()) |
| 134 | + { |
| 135 | + sfd.Title = "Save File Dialog"; |
| 136 | + sfd.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"; |
| 137 | + if (sfd.ShowDialog() == DialogResult.OK) |
| 138 | + { |
| 139 | + MessageBox.Show($"File will be saved to: {sfd.FileName}"); |
| 140 | + } |
| 141 | + } |
| 142 | + } |
| 143 | + private void btnFontDialog_Click(object sender, EventArgs e) |
| 144 | + { |
| 145 | + using (FontDialog fd = new FontDialog()) |
| 146 | + { |
| 147 | + fd.ShowColor = true; |
| 148 | + if (fd.ShowDialog() == DialogResult.OK) |
| 149 | + { |
| 150 | + this.lblFontDialogResult.Font = fd.Font; |
| 151 | + this.lblFontDialogResult.ForeColor = fd.Color; |
| 152 | + } |
| 153 | + } |
| 154 | + } |
| 155 | + private void btnColorDialog_Click(object sender, EventArgs e) |
| 156 | + { |
| 157 | + using (ColorDialog cd = new ColorDialog()) |
| 158 | + { |
| 159 | + if (cd.ShowDialog() == DialogResult.OK) |
| 160 | + { |
| 161 | + this.pnlColorDialogResult.BackColor = cd.Color; |
| 162 | + } |
| 163 | + } |
| 164 | + } |
| 165 | + private void trackBar1_Scroll(object sender, EventArgs e) { this.progressBar1.Value = this.trackBar1.Value; this.toolStripProgressBar1.Value = this.trackBar1.Value; } |
| 166 | + private void aboutToolStripMenuItem_Click(object sender, EventArgs e) { DarkMessageBox.Show(this, "All WinForms Controls Demo Application", "About"); } |
| 167 | + private void exitToolStripMenuItem_Click(object sender, EventArgs e) { Application.Exit(); } |
| 168 | + #endregion |
| 169 | + |
| 170 | + private void darkTabControl1_Load(object sender, EventArgs e) |
| 171 | + { |
| 172 | + |
| 173 | + } |
| 174 | + } |
| 175 | +} |
0 commit comments