0

I try to understand how work the groupboxes in windowsforms. My question now. I have 2 groupboxes with 2 radiobuttons each one. I want when for example the radiobutton 2 from groupbox1 is clicked the whole groupbox2 to be invisible or better to put something like a white shadow over it and not allow the user to use it. I read here but i did not find something http://msdn.microsoft.com/en-us/library/system.windows.forms.groupbox.aspx. I tried the property visible but make the whole window invisible. Here is my example code. Thanks in advance

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace groupbox
{
   public partial class Form1 : Form
  {
    public Form1()
    {
        InitializeComponent();
        radioButton1.Checked = true;
        radioButton3.Checked = true;
    }

    private void groupBox1_Enter(object sender, EventArgs e)
    {
        if (radioButton4.Checked == true) {
            this.Visible = false;
        }
    }

    private void groupBox2_Enter(object sender, EventArgs e)
    {
        if (radioButton2.Checked == true)
        {
            this.Visible = false;
        }
       }
  }
  } 

Also i read this Can you make a groupbox invisible but have it's contents visible? but is there anyway without panels?

Community
  • 1
  • 1
amigo
  • 155
  • 1
  • 10
  • `this` in your methods refers to your window ("form", in WinForms speak). That is why your whole window becomes invisible rather than just the group box. Have you tried something like `groupBox1.Visible = false;`? – O. R. Mapper Feb 08 '13 at 08:24
  • Thank you. I thought that this go to function. Thanks a lot! – amigo Feb 08 '13 at 08:30

2 Answers2

2

this refers to the class that the code is in - in this case, the form.

You should try groupBox1.Visible = false; or groupBox1.Enabled = false;

Blorgbeard
  • 101,031
  • 48
  • 228
  • 272
1

Try this:

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
        radioButton1.Checked = true;
        radioButton3.Checked = true;
        radioButton2.CheckedChanged += radioButton2_CheckedChanged;
    }

    void radioButton2_CheckedChanged(object sender, EventArgs e)
    {
        groupBox2.Enabled = !radioButton2.Checked;
    }
}
Alex Filipovici
  • 31,789
  • 6
  • 54
  • 78
  • Thanks a lot this gives exactly what i wanted. Not to be invisiable at totally but to have something like a shadow over it. – amigo Feb 08 '13 at 08:39