Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
M

Member 2048894

@Member 2048894
About
Posts
3
Topics
1
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • How do I programatically select a Tab Page?
    M Member 2048894

    Name 2 buttons "btnPrev" and "btnNext". Name a tab control "tabControl1". Create "Click" event handlers for the two buttons and put the code in them like this:

    private void btnPrev_Click(object sender, EventArgs e)
    {
    if (tabControl1.SelectedIndex > 0)
    tabControl1.SelectedIndex--;
    }

    private void btnNext_Click(object sender, EventArgs e)
    {
    if (tabControl1.SelectedIndex < (tabControl1.TabCount - 1))
    tabControl1.SelectedIndex++;
    }

    C# question winforms help learning

  • which database is installed on every computer
    M Member 2048894

    Eslam is correct, but SQL Server has to be installed with the "default instance" to be able to do that. If someone installs it using a "named instance" and calls it something else, it won't work.

    C# database help question sql-server sysadmin

  • Funny Control Behavior [modified]
    M Member 2048894

    Create a C# Windows Application. Replace the non-designer class code in the Form with mine below. The code simply creates 10 Panels on the form, each with one button on it. I assign each button's parent panel to the button's "Tag" property. I assign one common click event handler to all the buttons. In the click event handler, I simply cast the button's "Tag" to a Panel, then do a Form.Controls.Remove() to remove the Panel from the Form's "Controls" collection. I also create a "debug" window so that I can see when the button click event handler fires. Run the application and start hitting the spacebar. Exactly as you would expect, as you "click" each button by hitting the spacebar, the respective panel is removed. But keep hitting the spacebar after no more panels are visible. The click event KEEPS ON FIRING. I can understand that the panel can still be alive (and not have been garbage collected) and still have the button in its' "Controls" collection. But how does the spacebar keypress get from the form (which is in focus and has Controls.Count = 0) to the panel (and on to the button) that is no longer in its "Controls" collection???

    public partial class Form1 : Form
    {
    	private Form debugForm;
    	private TextBox debugTextBox;
    
    	public Form1()
    	{
    		InitializeComponent();
    	}
    
    	void b\_Click(object sender, EventArgs e)
    	{
    		// Remove panel from form.controls with button on panel is clicked
    		Button b = (Button)sender;
    		Panel p = (Panel)(b.Tag);
    		this.Controls.Remove(p);
    		debugTextBox.Text += "Click event fired for " + b.Name + " : this.Controls.Count = " +
    			this.Controls.Count.ToString() + "\\r\\n";
    	}
    
    	private void Form1\_FormClosing(object sender, FormClosingEventArgs e)
    	{
    		try
    		{
    			debugForm.Close();
    		}
    		catch { }
    	}
    
    	private void Form1\_Load(object sender, EventArgs e)
    	{
    		for (int i = 0; i < 10; i++)
    		{
    			Panel p = new Panel();
    			p.Left = 0;
    			p.Top = i \* 35;
    			p.Width = 300;
    			p.Height = 30;
    			Button b = new Button();
    			b.Left = 0;
    			b.Top = 0;
    			b.Width = 300;
    			b.Height = 30;
    			b.Name = b.Text = "Button" + i.ToString();
    			b.Click += new EventHandler(b\_Click);
    			b.Tag = p;
    			p.Controls.Add(b);
    			this.Controls.Add(p);
    		}
    
    		Rectangle rScreen = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea;
    		this.Left = 0;
    		this.Width = rScreen.Width / 2;
    		this.Top = 0;
    		this.Height = rScreen.Height;
    
    		debugForm = new Form();
    		debugForm.StartPosition = FormStartPo
    
    C# csharp debugging question
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups