amigo
amigo

Reputation: 155

Set groupbox invisible or make a shadow over it c#

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?

Upvotes: 0

Views: 1372

Answers (2)

Alex Filipovici
Alex Filipovici

Reputation: 32571

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;
    }
}

Upvotes: 1

Blorgbeard
Blorgbeard

Reputation: 103525

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;

Upvotes: 2

Related Questions