I have created gui for windows form....!
one side i have groupbox with checkbox and two buttons ">>" and "<<" and on the other side i have one more groupbox.
I need to select one checkbox at a time if the user select more than one checkbox i need to raise error..
if the user selects checkbox and click on ">>" button i need to display number of messages in the other groupbox i.e in the "List of Selected Commands"...
and on the click of ">>" the selected list of message should be deleted from list.
I have included tab control in my gui on click of this tab i need to display some list of commands how can i do it...
can any one help me on this...
This is the code..
namespace Menu_Sample
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
groupBox1.Text = "MSC";
groupBox2.Text = "List Of Selected Commands";
checkBox1.Visible = false;
cb2.Visible = false;
cb3.Visible = false;
cb4.Visible = false;
label1.Visible = false;
label2.Visible = false;
label3.Visible = false;
label4.Visible = false;
}
private void submenu1ToolStripMenuItem_Click(object sender, EventArgs e)
{
groupBox1.Text = "ICP";
checkBox1.Visible = true;
cb2.Visible = true;
cb3.Visible = true;
cb4.Visible = true;
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
if (checkBox1.Checked == true)
{
label1.Visible = true;
label1.Text = "ibit";
groupBox2.Controls.Add(label1);
label2.Visible = true;
label2.Text = "Cbit";
groupBox2.Controls.Add(label2);
label3.Visible = true;
label3.Text = "Kbit";
groupBox2.Controls.Add(label3);
label4.Visible = true;
label4.Text = "ibit";
groupBox2.Controls.Add(label4);
}
if (cb2.Checked == true)
{
label1.Visible = true;
label1.Text = "ibit";
groupBox2.Controls.Add(label1);
label2.Visible = true;
label2.Text = "Cbit";
groupBox2.Controls.Add(label2);
label3.Visible = true;
label3.Text = "Kbit";
groupBox2.Controls.Add(label3);
label4.Visible = true;
label4.Text = "ibit";
groupBox2.Controls.Add(label4);
}
}
private void btn6_Click(object sender, EventArgs e)
{
if (label1.Enabled==true)
{
label1.Text = "";
}
}
private void btn5_Click(object sender, EventArgs e)
{
label1.Text = "";
label2.Text = "";
label3.Text = "";
label4.Text = "";
}
private void submenu2ToolStripMenuItem_Click(object sender, EventArgs e)
{
groupBox1.Text = "MCP";
}
private void mDPToolStripMenuItem_Click(object sender, EventArgs e)
{
groupBox1.Text = "MDP";
}
private void mRPPToolStripMenuItem_Click(object sender, EventArgs e)
{
groupBox1.Text = "MRPP";
}
}
}
I am giving you an idea, that how we can do that.
You have to create a group box click event and then use loop for the controls in that groupbox and if that control is checkbox and it is checked, then you just count that no-other checkbox should be checked.
I will be available with the code very shortly.
Related
I have three panels and three buttons. Upon clicking button1 I want to show Panel1 and hide Panel2 and Panel3.
The same process with the other buttons and panels. How can I do this?
I'm using a Window Forms application written in C#/.NET. This code is not working very well, because only two panels are showing.
private void frmMain_Load(object sender, EventArgs e)
{
pnlItems.Visible = true;
pnlCustomer.Visible = false;
pnlPOS.Visible = false;
}
private void btnItems_Click(object sender, EventArgs e)
{
pnlItems.Visible = true;
pnlCustomer.Visible = false;
pnlPOS.Visible = false;
}
private void btnCustomers_Click(object sender, EventArgs e)
{
pnlCustomer.Visible = true;
pnlItems.Visible = false;
pnlPOS.Visible = false;
}
private void btnPOS_Click(object sender, EventArgs e)
{
pnlPOS.Visible = true;
pnlCustomer.Visible = false;
pnlItems.Visible = false;
}
private void frmMain_Load(object sender, EventArgs e)
{
pnlItems.Visible = true;
pnlCustomer.Visible = false;
pnlPOS.Visible = false;
}
private void btnItems_Click(object sender, EventArgs e)
{
if(pnlItems.Visible != true)
{
pnlItems.Visible = true;
pnlCustomer.Visible = false;
pnlPOS.Visible = false;
}
}
private void btnCustomers_Click(object sender, EventArgs e)
{
if(pnlCustomer.Visible != true)
{
pnlCustomer.Visible = true;
pnlItems.Visible = false;
pnlPOS.Visible = false;
}
}
private void btnPOS_Click(object sender, EventArgs e)
{
if(pnlPOS.Visible != true)
{
pnlPOS.Visible = true;
pnlCustomer.Visible = false;
pnlItems.Visible = false;
}
}
Here I have updated the conditional statement for if your panel is not visible then act. I hope this will work.
In Windows form I have Button1, Button2 and Button3. These buttons represent a series of actions that should be carried out in a order from starting action to final action. So that normally I can handle this as follows.
Form1: Form
{
Form_Load(Object sender, event Args e)
{
Button1.Enabled = true;
Button2.Enabled = false;
Button3.Enabled = false;
}
Button1_click(Object sender, event Args e)
{
//Actions
Button2.Enabled = true;
Button1.Enabled = false;
}
Button2_click(Object sender, event Args e)
{
//Actions
Button3.Enabled = true;
Button2.Enabled = false;
}
Button3_click(Object sender, e)
{
//Actions
Button3.Enabled = false;
Button1.Enabled = true;
}
}
In several places I'm doing it in this way. Is this the standard way?
EDIT:
And also in a simple situation like you should have clicked button1 before clicking button2, the above approach is acceptable?
To expand on what Bjarke said, I'm providing a code example.
Form1: Form
{
List<Button> listButtons = new List<Button>();
public void EnableButton(Button btnToEnable)
{
foreach(Button btn in listButtons)
{
//check button name.
//if it is the button to enable, enable it, if not then disable it
btn.Enabled = btn.Name == btnToEnable.Name;
}
}
Form_Load(Object sender, event Args e)
{
listButtons.Add(Button1);
listButtons.Add(Button2);
listButtons.Add(Button3);
EnableButton(Button1);
//Button1.Enabled = true;
//Button2.Enabled = false;
//Button3.Enabled = false;
}
Button1_click(Object sender, event Args e)
{
EnableButton(Button2);
//Actions
//Button2.Enabled = true;
//Button1.Enabled = false;
}
Button2_click(Object sender, event Args e)
{
EnableButton(Button3);
//Actions
//Button3.Enabled = true;
//Button2.Enabled = false;
}
Button3_click(Object sender, e)
{
EnableButton(Button1);
//Actions
//Button3.Enabled = false;
//Button1.Enabled = true;
}
}
I have a couple of text boxes that i have initially hidden and what I want to do is as the users type I would like the next text box along with the label that goes with it to appear to notify of the next question.
At the same time if they change their mind and delete their response to the first question the next text box and label will disappear once the text has been deleted.
Here is my current code:
private void CreditScoreBox_KeyPress(object sender, KeyPressEventArgs e)
{
if (char.IsControl(e.KeyChar) || char.IsDigit(e.KeyChar))
e.Handled = false;
else
e.Handled = true;
if(CreditScoreBox.Text == "")
{
MakeBox.Visible = false;
MakeLabel.Visible = false;
ModelBox.Visible = false;
ModelLabel.Visible = false;
CreditLevelLabel.Visible = false;
}
else
{
MakeBox.Visible = true;
MakeBox.Enabled = true;
MakeLabel.Visible = true;
CreditLevelLabel.Visible = true;
}
I have tried using the TextChanged event with the same result.
I created a Form, with 2 textbox and 1 label. If text exist in textbox1 then label1 and textbox2 become available:
private void textBox1_TextChanged(object sender, EventArgs e)
{
if (textBox1.Text == "")
{
textBox2.Enabled = false;
textBox2.Visible = false;
label1.Visible = false;
}
else
{
textBox2.Enabled = true;
textBox2.Visible = true;
label1.Visible = true;
}
}
I have got problem with check-box to enable corresponding control next to it. My Requirement is at the page load we want to disable the all textboxes and dropdownlists by using checkbox
if the check-box is checked the control next to that check-box will be enabled for that i have done like this....
at page load
i have written like this
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
ChckOrdType.Checked = false;
ChkPlntPric.Checked = false;
ChkExcluBro.Checked = false;
......
.....
}
and then in checkbox check changed event i have written like this
protected void ChckOrdType_CheckChanged(object sender, EventArgs e)
{
if (ChckOrdType.Checked)
ddlOrdType.Enabled = true;
else
ddlOrdType.Enabled = false;
}
protected void chkPlntPric_CheckChanged(object sender, EventArgs e)
{
if (ChkPlntPric.Checked)
ddlPlntPric.Enabled = true;
else
ddlPlntPric.Enabled = false;
}
protected void chkExcluBro_CheckChanged(object sender, EventArgs e)
{
if (ChkExcluBro.Checked)
ddlExcluBroker.Enabled = true;
else
ddlExcluBroker.Enabled = false;
}
but results is like this ...
I am getting checkbox not checked and control next to it is enabled...But this not what i want
My results is if the check-box is not checked the control next to it is disabled
would any one pls help on this....
Thanks In advance......
This is because you have just wrote ONLY to uncheck the checkboxes in the pageload and not to disable the controls behind the checkbox; If thats needed, then your snippet in the pageload should be:
if (!Page.IsPostBack)
{
ChckOrdType.Checked = false;
ChkPlntPric.Checked = false;
ChkExcluBro.Checked = false;
......
.....
ddlOrdType.Enabled = false;
ddlPlntPric.Enabled = false;
ddlExcluBroker.Enabled = false;
.........
}
or
if (!Page.IsPostBack)
{
ChckOrdType.Checked = false;
ChkPlntPric.Checked = false;
ChkExcluBro.Checked = false;
......
.....
ChckOrdType_CheckChanged(sender,e);
chkPlntPric_CheckChanged(sender,e);
chkExcluBro_CheckChanged(sender,e);
...
}
Disable text boxes in page load like below.
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
ChckOrdType.Checked = false;
ChkPlntPric.Checked = false;
ChkExcluBro.Checked = false;
DisableFirstTime();
......
.....
}
private void DisableFirstTime()
{
ddlOrdType.Enabled = false;
ddlPlntPric.Enabled = false;
ddlExcluBroker.Enabled = false;
}
The Default is No Checkbox
When I run the program and Click the Yes Checkbox the program overflowed
private void checkEdit1_Click(object sender, EventArgs e)
{
checkEdit2.Checked = false;
textEdit1.Enabled = true;
answered = true;
optional = textEdit1.Text;
if (!checkEdit1.Checked)
{
checkEdit1.Checked = true;
checkEdit2.Checked = false;
textEdit1.Enabled = true;
optional = textEdit1.Text;
}
}
private void checkEdit2_Click(object sender, EventArgs e)
{
checkEdit1.Checked = false;
textEdit1.Enabled = false;
answered = false;
if (!checkEdit2.Checked)
{
checkEdit2.Checked = true;
checkEdit1.Checked = false;
textEdit1.Enabled = false;
answered = false;
}
}
What you think is the error ?
Instead of the Click event you should use the CheckedChanged event in this way:
checkEdit1.CheckedChenged += new EventHandler(checkEdit1_CheckedChanged);
checkEdit2.CheckedChenged += new EventHandler(checkEdit2_CheckedChanged);
private void checkEdit1_CheckedChanged(object sender, EventArgs e)
{
if(checkEdit1.Checked == checkEdit2.Checked)
checkEdit2.Checked = !checkEdit.Checked;
}
private void checkEdit2_CheckedChanged(object sender, EventArgs e)
{
if(checkEdit1.Checked == checkEdit2.Checked)
checkEdit2.Checked = !checkEdit.Checked;
}
But the best way in this case is to use a group of radio buttons.
Assuming that those methods are wired up to checkEdit1 and checkEdit2 I would advise that you don't make a change to checkEdit1 in checkEdit1_Click as it has already changed - only modify the state of the alternate.
However, when you modify the state of the other, unless you're careful, you're going to get called back. Eventually the computer gives up -- the overflow!
As mentioned in a comment by #Cyborgx37, radio buttons are the better UX choice here!
A possible solution, bind a single method to the OnClick to BOTH checkboxes:
private bool internallyUpdating = false;
private void CheckboxClick(object sender, EventArgs e)
{
if ( !internallyUpdating )
{
// Prevent subsequent changes
internallyUpdating = true;
// Exchange 'checked' state
if ( sender == checkEdit1 )
{
checkEdit2.Checked = !checkEdit2.Checked;
}
else // if (sender == checkEdit2)
{
checkEdit1.Checked = !checkEdit1.Checked;
}
// other logic here..
// restore 'on change' functionality.
internallyUpdating = false;
}