static void FilterButtonCancel_OnClick(object sender, EventArgs e) { System.Windows.Forms.DataGridView grid = (System.Windows.Forms.DataGridView)telaFiltro.PainelFiltro.Parent; ((System.Windows.Forms.Control)telaFiltro.PainelFiltro.Controls["painelControle"]).Controls.Clear(); telaFiltro.PainelFiltro.Controls.Clear(); grid.Controls.Remove(telaFiltro.TituloFiltro); grid.Controls.Remove(telaFiltro.PainelFiltro); telaFiltro.PainelFiltro.Dispose(); telaFiltro = null; }
private static void DataGridView_OnColumnHeaderMouseClick(object sender, System.Windows.Forms.DataGridViewCellMouseEventArgs e) { System.Windows.Forms.DataGridView grid = (System.Windows.Forms.DataGridView)sender; if (e.Button == System.Windows.Forms.MouseButtons.Left) { if (grid.Columns[e.ColumnIndex].Tag != null && telaFiltro == null) { telaFiltro = new MontagemFiltro(); FilterSettings.Filtro filtro = (FilterSettings.Filtro)grid.Columns[e.ColumnIndex].Tag; telaFiltro.TituloFiltro = new System.Windows.Forms.Label(); telaFiltro.TituloFiltro.Location = new System.Drawing.Point(filtro.PosicaoCabecalhoGrid.X + 1, filtro.PosicaoCabecalhoGrid.Y + 1); telaFiltro.TituloFiltro.Size = new System.Drawing.Size(filtro.PosicaoCabecalhoGrid.Width - 3, filtro.PosicaoCabecalhoGrid.Height - 1); telaFiltro.TituloFiltro.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; telaFiltro.TituloFiltro.Font = StyleSettings.Fonte_Grid; telaFiltro.TituloFiltro.Text = filtro.Nome; telaFiltro.TituloFiltro.BackColor = System.Drawing.Color.FromArgb(120, 120, 120); telaFiltro.TituloFiltro.ForeColor = System.Drawing.Color.White; grid.Controls.Add(telaFiltro.TituloFiltro); telaFiltro.PainelFiltro = new System.Windows.Forms.Panel(); telaFiltro.PainelFiltro.Location = new System.Drawing.Point(filtro.PosicaoCabecalhoGrid.X, filtro.PosicaoCabecalhoGrid.Y + filtro.PosicaoCabecalhoGrid.Height); telaFiltro.PainelFiltro.Size = filtro.Tamanho; telaFiltro.PainelFiltro.BorderStyle = System.Windows.Forms.BorderStyle.None; telaFiltro.PainelFiltro.BackColor = System.Drawing.Color.FromArgb(120, 120, 120); grid.Controls.Add(telaFiltro.PainelFiltro); painelControle.Name = "painelControle"; painelControle.Location = new System.Drawing.Point(1, 1); painelControle.Size = new System.Drawing.Size(telaFiltro.PainelFiltro.Size.Width - 2, telaFiltro.PainelFiltro.Size.Height - 2); painelControle.BackColor = System.Drawing.Color.FromArgb(60, 60, 60); telaFiltro.PainelFiltro.Controls.Add(painelControle); System.Windows.Forms.RadioButton chkAscendente = new System.Windows.Forms.RadioButton(); chkAscendente.Text = "Ascendente"; chkAscendente.Font = new System.Drawing.Font("Calibri", 9f, System.Drawing.FontStyle.Bold); chkAscendente.Location = new System.Drawing.Point(10, 5); chkAscendente.BackColor = System.Drawing.Color.Transparent; chkAscendente.ForeColor = System.Drawing.Color.White; chkAscendente.Checked = filtro.Ascendente; painelControle.Controls.Add(chkAscendente); System.Windows.Forms.RadioButton chkDescendente = new System.Windows.Forms.RadioButton(); chkDescendente.Text = "Descendente"; chkDescendente.Font = new System.Drawing.Font("Calibri", 9f, System.Drawing.FontStyle.Bold); chkDescendente.Location = new System.Drawing.Point(10, 25); chkDescendente.BackColor = System.Drawing.Color.Transparent; chkDescendente.ForeColor = System.Drawing.Color.White; chkDescendente.Checked = !filtro.Ascendente; painelControle.Controls.Add(chkDescendente); System.Windows.Forms.GroupBox linha = new System.Windows.Forms.GroupBox(); linha.Location = new System.Drawing.Point(5, 50); linha.Size = new System.Drawing.Size(telaFiltro.PainelFiltro.Size.Width - 10, 1); linha.ForeColor = System.Drawing.Color.FromArgb(90, 90, 90); painelControle.Controls.Add(linha); int posY = 65; foreach (FilterSettings.CamposFiltro campo in filtro.CamposTextBox) { System.Windows.Forms.Label label = new System.Windows.Forms.Label(); label.Text = campo.Descricao; label.Location = new System.Drawing.Point(10, posY); label.TextAlign = System.Drawing.ContentAlignment.MiddleRight; label.Size = campo.DescricaoTamanho; label.ForeColor = System.Drawing.Color.White; painelControle.Controls.Add(label); System.Windows.Forms.TextBox textBox = new System.Windows.Forms.TextBox(); textBox.Text = (String)campo.Conteudo; textBox.Font = new System.Drawing.Font("Calibri", 11.25f, System.Drawing.FontStyle.Bold); textBox.Location = new System.Drawing.Point(20 + label.Size.Width, posY - 5); textBox.Size = campo.ConteudoTamanho; painelControle.Controls.Add(textBox); posY += 28; } foreach (FilterSettings.CamposFiltro campo in filtro.CamposBuscaTextBox) { System.Windows.Forms.Label label = new System.Windows.Forms.Label(); label.Text = campo.Descricao; label.Location = new System.Drawing.Point(10, posY); label.TextAlign = System.Drawing.ContentAlignment.MiddleRight; label.Size = campo.DescricaoTamanho; label.ForeColor = System.Drawing.Color.White; painelControle.Controls.Add(label); System.Windows.Forms.TextBox textBox = new System.Windows.Forms.TextBox(); textBox.Text = (String)campo.Conteudo; textBox.Font = new System.Drawing.Font("Calibri", 11.25f, System.Drawing.FontStyle.Bold); textBox.Location = new System.Drawing.Point(20 + label.Size.Width, posY - 5); textBox.Size = campo.ConteudoTamanho; //textBox.KeyPress += new KeyPressEventHandler(textBox_KeyPress); textBox.KeyDown += new System.Windows.Forms.KeyEventHandler(textBox_KeyDown); painelControle.Controls.Add(textBox); posY += 28; } foreach (FilterSettings.CamposFiltro campo in filtro.CamposComboBox) { System.Windows.Forms.Label label = new System.Windows.Forms.Label(); label.Text = campo.Descricao; label.Location = new System.Drawing.Point(10, posY); label.TextAlign = System.Drawing.ContentAlignment.MiddleRight; label.Size = campo.DescricaoTamanho; label.ForeColor = System.Drawing.Color.White; label.Font = new System.Drawing.Font("Calibri", 9.75f, System.Drawing.FontStyle.Bold); painelControle.Controls.Add(label); System.Windows.Forms.ComboBox comboBox = new System.Windows.Forms.ComboBox(); comboBox.Font = new System.Drawing.Font("Calibri", 9.75f, System.Drawing.FontStyle.Bold); foreach (String item in (List <String>)campo.Conteudo) { comboBox.Items.Add(item); } comboBox.SelectedIndex = 0; comboBox.Location = new System.Drawing.Point(15 + label.Size.Width, posY); comboBox.Size = campo.ConteudoTamanho; painelControle.Controls.Add(comboBox); posY += 28; } foreach (FilterSettings.CamposFiltro campo in filtro.CamposCheckBox) { System.Windows.Forms.Label label = new System.Windows.Forms.Label(); label.Text = campo.Descricao; label.Location = new System.Drawing.Point(10, posY); label.TextAlign = System.Drawing.ContentAlignment.MiddleRight; label.Size = campo.DescricaoTamanho; label.ForeColor = System.Drawing.Color.White; painelControle.Controls.Add(label); System.Windows.Forms.CheckedListBox checkedListBox = new System.Windows.Forms.CheckedListBox(); checkedListBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; checkedListBox.Font = new System.Drawing.Font("Calibri", 9.75f, System.Drawing.FontStyle.Bold); foreach (String item in (List <String>)campo.Conteudo) { if (!gListaClientes.Contains(item)) { gListaClientes.Add(item); } checkedListBox.Items.Add(item); } //checkedListBox.SelectedIndex = 0; checkedListBox.Location = new System.Drawing.Point(15 + label.Size.Width, posY); checkedListBox.Size = campo.ConteudoTamanho; checkedListBox.CheckOnClick = true; checkedListBox.Name = "checkedListBox"; checkedListBox.SelectedIndexChanged += new EventHandler(CheckedListBox_OnSelectedIndexChanged); painelControle.Controls.Add(checkedListBox); posY += 28; } if (filtro.BotaoOK != null) { System.Windows.Forms.Button botaoOk = new System.Windows.Forms.Button(); botaoOk.Text = "Filtrar"; botaoOk.Font = new System.Drawing.Font("Calibri", 9.75f, System.Drawing.FontStyle.Bold); botaoOk.Location = new System.Drawing.Point(painelControle.Size.Width - 160, painelControle.Size.Height - 35); botaoOk.Size = new System.Drawing.Size(70, 25); //botaoOk.Click += new EventHandler<FiltrarEventArgs>(filtro.BotaoOK.Handler); botaoOk.Click -= new EventHandler(FilterButton_OnClick); botaoOk.Click += new EventHandler(FilterButton_OnClick); //EventFiltrar += filtro.BotaoOK.Handler; //botaoOk.Click += new EventHandler(filtro.BotaoOK.Handler); painelControle.Controls.Add(botaoOk); } else { System.Windows.Forms.Button botaoOk = new System.Windows.Forms.Button(); botaoOk.Text = "Filtrar"; botaoOk.Font = new System.Drawing.Font("Calibri", 9.75f, System.Drawing.FontStyle.Bold); botaoOk.Location = new System.Drawing.Point(painelControle.Size.Width - 160, painelControle.Size.Height - 35); botaoOk.Size = new System.Drawing.Size(70, 25); botaoOk.Click += new EventHandler(FilterButtonOK_OnClick); painelControle.Controls.Add(botaoOk); } System.Windows.Forms.Button botaoCancel = new System.Windows.Forms.Button(); botaoCancel.Text = "Cancelar"; botaoCancel.Font = new System.Drawing.Font("Calibri", 9.75f, System.Drawing.FontStyle.Bold); botaoCancel.Location = new System.Drawing.Point(painelControle.Size.Width - 80, painelControle.Size.Height - 35); botaoCancel.Size = new System.Drawing.Size(70, 25); botaoCancel.Click += new EventHandler(FilterButtonCancel_OnClick); painelControle.Controls.Add(botaoCancel); painelControle.PreviewKeyDown += new System.Windows.Forms.PreviewKeyDownEventHandler(PanelControle_OnPreviewKeyDown); ConfigureControl(telaFiltro.PainelFiltro); telaFiltro.PainelFiltro.BringToFront(); } else { if (telaFiltro != null) { telaFiltro.PainelFiltro.BringToFront(); } } } }