Click here to Skip to main content
15,918,808 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
Questionintercepting network traffic of a process Pin
prattel17-Oct-07 13:59
prattel17-Oct-07 13:59 
AnswerRe: intercepting network traffic of a process Pin
Dave Kreskowiak17-Oct-07 14:09
mveDave Kreskowiak17-Oct-07 14:09 
GeneralRe: intercepting network traffic of a process Pin
prattel17-Oct-07 14:21
prattel17-Oct-07 14:21 
QuestionComboBox issues Pin
tuga-x17-Oct-07 1:24
tuga-x17-Oct-07 1:24 
AnswerRe: ComboBox issues Pin
Luc Pattyn17-Oct-07 2:48
sitebuilderLuc Pattyn17-Oct-07 2:48 
GeneralRe: ComboBox issues Pin
tuga-x17-Oct-07 2:57
tuga-x17-Oct-07 2:57 
GeneralRe: ComboBox issues Pin
Luc Pattyn17-Oct-07 3:13
sitebuilderLuc Pattyn17-Oct-07 3:13 
GeneralRe: ComboBox issues Pin
tuga-x17-Oct-07 3:45
tuga-x17-Oct-07 3:45 
Here's the partial class code for a proof of concept:

public partial class Form1 : Form
{
    Panel panela = new Panel();
    ComboBox comboBox1 = new ComboBox();

    public Form1()
    {
        InitializeComponent();

        this.panela.Name = "panel";
        this.panela.Size = new Size((int)(this.ClientSize.Width * 0.765), (int)(this.ClientSize.Height * 0.75));
        this.panela.BackColor = Color.SteelBlue;
        this.panela.Hide();
        this.panela.Parent = this;

        this.comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;
        this.comboBox1.Items.AddRange(new string[] { "item1", "item2", "item3" });
        this.comboBox1.SelectedIndexChanged += new EventHandler(comboBox1_SelectedIndexChanged);
    }

    void button1_Click(object sender, EventArgs e)
    {
        this.panela.Location = new Point((this.ClientSize.Width / 2) - (this.panela.ClientSize.Width / 2), (this.ClientSize.Height / 2) - (this.panela.ClientSize.Height / 2));

        int width = (int)(this.panela.ClientSize.Width * 0.965);
        int height = (int)(this.panela.ClientSize.Height * 0.95);

        Panel panelb = new Panel();
        panelb.Size = new Size(width, height);
        panelb.Location = new Point((this.panela.ClientSize.Width / 2) - (width / 2), (this.panela.ClientSize.Height / 2) - (height / 2));
        panelb.BackColor = Color.White;

        Rectangle parentRect = panelb.ClientRectangle;
        int maxWidth = parentRect.Width - 4;

        this.comboBox1.Bounds = new Rectangle(parentRect.Left + 2, parentRect.Top + 2, maxWidth, this.comboBox1.Height);
        this.comboBox1.SelectedIndex = -1;
        this.comboBox1.Parent = panelb;

        Button ok = new Button();
        ok.Bounds = new Rectangle(parentRect.Width - ok.Width, parentRect.Bottom - ok.Height, 72, 23);
        ok.Text = "OK";
        ok.FlatStyle = FlatStyle.System;
        ok.Click += new EventHandler(ok_Click);
        ok.Parent = panelb;

        panelb.Parent = this.panela;

        this.panela.Show();
        this.panela.BringToFront();
    }

    void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
    {
        MessageBox.Show("index changed");
    }

    void ok_Click(object sender, EventArgs e)
    {
        this.comboBox1.SelectedIndex = -1;

        this.panela.Hide();
        this.comboBox1.Parent.Controls.Remove(this.comboBox1);

        int count = this.panela.Controls.Count;
        int i = 0;
        while (i < count)
        {
            this.panela.Controls[0].Dispose();
            i++;
        }
    }
}


If instead of disposing the objects I use "this.panela.Controls.Clear()" the events will fire without any problem.

So it has to do with the Dispose() of the parent panel
GeneralRe: ComboBox issues Pin
Luc Pattyn17-Oct-07 14:53
sitebuilderLuc Pattyn17-Oct-07 14:53 
GeneralRe: ComboBox issues Pin
tuga-x17-Oct-07 23:02
tuga-x17-Oct-07 23:02 
GeneralRe: ComboBox issues Pin
Luc Pattyn18-Oct-07 2:52
sitebuilderLuc Pattyn18-Oct-07 2:52 
GeneralRe: ComboBox issues Pin
tuga-x18-Oct-07 2:57
tuga-x18-Oct-07 2:57 
GeneralRe: ComboBox issues Pin
Patrick Etc.18-Oct-07 9:16
Patrick Etc.18-Oct-07 9:16 
GeneralRe: ComboBox issues Pin
Luc Pattyn18-Oct-07 9:42
sitebuilderLuc Pattyn18-Oct-07 9:42 
GeneralRe: ComboBox issues Pin
Patrick Etc.18-Oct-07 9:56
Patrick Etc.18-Oct-07 9:56 
GeneralRe: ComboBox issues Pin
Luc Pattyn18-Oct-07 10:41
sitebuilderLuc Pattyn18-Oct-07 10:41 
GeneralRe: ComboBox issues Pin
tuga-x18-Oct-07 22:19
tuga-x18-Oct-07 22:19 
QuestionValueType vs Reference Pin
rtalan17-Oct-07 0:16
rtalan17-Oct-07 0:16 
AnswerRe: ValueType vs Reference Pin
Robert Rohde17-Oct-07 0:27
Robert Rohde17-Oct-07 0:27 
GeneralRe: ValueType vs Reference Pin
rtalan17-Oct-07 0:48
rtalan17-Oct-07 0:48 
GeneralRe: ValueType vs Reference Pin
lmoelleb17-Oct-07 1:39
lmoelleb17-Oct-07 1:39 
GeneralRe: ValueType vs Reference Pin
rtalan17-Oct-07 1:53
rtalan17-Oct-07 1:53 
GeneralRe: ValueType vs Reference Pin
lmoelleb17-Oct-07 2:12
lmoelleb17-Oct-07 2:12 
GeneralRe: ValueType vs Reference Pin
rtalan17-Oct-07 2:42
rtalan17-Oct-07 2:42 
GeneralRe: ValueType vs Reference Pin
Luc Pattyn17-Oct-07 2:57
sitebuilderLuc Pattyn17-Oct-07 2:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.