Content format groupBox'u ExportOptions GroupBox'un altına getir, onların altına da ok…
- User
Content format groupBox'u ExportOptions GroupBox'un altına getir, onların altına da ok ve cancel buttonunu yerleştir, checkboxlist'in yüksekliğini biraz daha artır, pencereyi modern ve şık hale getir. -> public class ExportSettingsForm : Form { private CheckedListBox clbFields; private CheckedListBox clbCategories; private CheckBox chkSelectAllFields; private CheckBox chkSelectAllCategories; private Button btnOK, btnCancel; private RadioButton rdbExportAll, rdbExportByCategory; private RadioButton rdbKeepHtml, rdbConvertToText; // Yeni RadioButton'lar private GroupBox grpExportOptions; private GroupBox grpContentFormat; // Yeni GroupBox
private List<string> availableCategories; public bool ExportAll { get; private set; } = true; public bool ExportByCategory => !ExportAll; public List<string> SelectedCategories { get; private set; } = new List<string>(); public bool KeepContentAsHtml { get; private set; } = false; // Yeni özellik public ExportSettingsForm(List<string> categories) { availableCategories = categories; InitializeComponent(); } private void InitializeComponent() { this.Text = "Export Options"; this.Size = new Size(400, 700); this.FormBorderStyle = FormBorderStyle.FixedDialog; this.StartPosition = FormStartPosition.CenterParent; this.MaximizeBox = false; this.MinimizeBox = false; Label lblSelectFields = new Label { Text = "Select fields to export:", Left = 10, Top = 20, Width = 360 }; this.Controls.Add(lblSelectFields); clbFields = new CheckedListBox { Left = 10, Top = lblSelectFields.Bottom + 10, Width = 360, Height = 100 }; clbFields.Items.AddRange(new object[] { "id", "category", "title", "content", "favorite", "pinned", "backgroundColor", "timestamp", "updatedAt", "hashtags" }); this.Controls.Add(clbFields); chkSelectAllFields = new CheckBox { Text = "Select All Fields", Left = 10, Top = clbFields.Bottom + 10, Width = 150 }; chkSelectAllFields.CheckedChanged += ChkSelectAllFields_CheckedChanged; this.Controls.Add(chkSelectAllFields); // Export Options GroupBox grpExportOptions = new GroupBox { Text = "Export Options", Left = 10, Top = chkSelectAllFields.Bottom + 10, Width = 360, Height = 100 }; this.Controls.Add(grpExportOptions); rdbExportAll = new RadioButton { Text = "All Flashcards", Left = 10, Top = 20, Checked = true }; rdbExportAll.CheckedChanged += RdbExportOptions_CheckedChanged; grpExportOptions.Controls.Add(rdbExportAll); rdbExportByCategory = new RadioButton { Text = "Export by Category", Left = 10, Top = 50, Checked = false }; rdbExportByCategory.CheckedChanged += RdbExportOptions_CheckedChanged; grpExportOptions.Controls.Add(rdbExportByCategory); // Categories Selection Label lblSelectCategories = new Label { Text = "Select categories to export:", Left = 10, Top = grpExportOptions.Bottom + 10, Width = 360, Visible = false }; this.Controls.Add(lblSelectCategories); clbCategories = new CheckedListBox { Left = 10, Top = lblSelectCategories.Bottom + 10, Width = 360, Height = 100, Visible = false }; clbCategories.Items.AddRange(availableCategories.ToArray()); this.Controls.Add(clbCategories); chkSelectAllCategories = new CheckBox { Text = "Select All Categories", Left = 10, Top = clbCategories.Bottom + 10, Width = 150, Visible = false }; chkSelectAllCategories.CheckedChanged += ChkSelectAllCategories_CheckedChanged; this.Controls.Add(chkSelectAllCategories); // Content Format GroupBox grpContentFormat = new GroupBox { Text = "Content Format", Left = 10, Top = chkSelectAllCategories.Visible ? chkSelectAllCategories.Bottom + 10 : clbCategories.Bottom + 20, Width = 360, Height = 80 }; this.Controls.Add(grpContentFormat); rdbConvertToText = new RadioButton { Text = "Plain Text (Default)", Left = 10, Top = 20, Checked = true }; grpContentFormat.Controls.Add(rdbConvertToText); rdbKeepHtml = new RadioButton { Text = "Keep as HTML", Left = 10, Top = 45, Checked = false }; grpContentFormat.Controls.Add(rdbKeepHtml); // OK and Cancel Buttons btnOK = new Button { Text = "OK", Width = 80, Top = grpContentFormat.Bottom + 10, Left = 100, DialogResult = DialogResult.OK }; btnOK.Click += BtnOK_Click; this.Controls.Add(btnOK); btnCancel = new Button { Text = "Cancel", Width = 80, Top = grpContentFormat.Bottom + 10, Left = 200, DialogResult = DialogResult.Cancel }; this.Controls.Add(btnCancel); this.AcceptButton = btnOK; this.CancelButton = btnCancel; } private void ChkSelectAllFields_CheckedChanged(object sender, EventArgs e) { for (int i = 0; i < clbFields.Items.Count; i++) { clbFields.SetItemChecked(i, chkSelectAllFields.Checked); } } private void ChkSelectAllCategories_CheckedChanged(object sender, EventArgs e) { for (int i = 0; i < clbCategories.Items.Count; i++) { clbCategories.SetItemChecked(i, chkSelectAllCategories.Checked); } } private void RdbExportOptions_CheckedChanged(object sender, EventArgs e) { if (rdbExportAll.Checked) { ExportAll = true; } else if (rdbExportByCategory.Checked) { ExportAll = false; } // Kategori seçimlerinin görünürlüğünü ayarla bool isByCategory = rdbExportByCategory.Checked; clbCategories.Visible = isByCategory; chkSelectAllCategories.Visible = isByCategory; foreach (Control ctrl in this.Controls) { if (ctrl is Label lbl && lbl.Text == "Select categories to export:") { lbl.Visible = isByCategory; break; } } // Eğer kategoriye göre export edilmiyorsa, tüm kategorileri işaretlemeyi kaldır if (!isByCategory) { for (int i = 0; i < clbCategories.Items.Count; i++) { clbCategories.SetItemChecked(i, false); } chkSelectAllCategories.Checked = false; } } private void BtnOK_Click(object sender, EventArgs e) { // Ensure at least one field is selected if (clbFields.CheckedItems.Count == 0) { MessageBox.Show("Please select at least one field to export.", "No Fields Selected", MessageBoxButtons.OK, MessageBoxIcon.Warning); this.DialogResult = DialogResult.None; // Prevent the dialog from closing return; } if (ExportByCategory) { // Ensure at least one category is selected if (clbCategories.CheckedItems.Count == 0) { MessageBox.Show("Please select at least one category to export.", "No Categories Selected", MessageBoxButtons.OK, MessageBoxIcon.Warning); this.DialogResult = DialogResult.None; // Prevent the dialog from closing return; } // Collect selected categories SelectedCategories = clbCategories.CheckedItems.Cast<string>().ToList(); } // Collect content format selection KeepContentAsHtml = rdbKeepHtml.Checked; this.DialogResult = DialogResult.OK; this.Close(); } /// <summary> /// Retrieves the list of selected fields. /// </summary> public List<string> GetSelectedFields() { return clbFields.CheckedItems.Cast<string>().ToList(); } /// <summary> /// Retrieves the list of selected categories. /// </summary> public List<string> GetSelectedCategories() { return SelectedCategories; } /// <summary> /// Selects all fields by checking all items. /// </summary> public void SelectAllFields() { chkSelectAllFields.Checked = true; } /// <summary> /// Selects all categories by checking all items. /// </summary> public void SelectAllCategories() { chkSelectAllCategories.Checked = true; } } } - Assistant