Such as combobox text contain of 1, 2, 3 if choose 1 then open panel 1, if choose 2 open panel 2.
you can use if statement. Try to find out comboBox1_SelectedTextChanged event for more information.
Here pasted some of code for resolve your issue. Try it !
code-----------
if (comboBox1.SelectedText=="1")
{
panel1.Visible = true;
panel2.Visible = false;
panel3.Visible = false;
`enter code here`}
if (comboBox1.SelectedText=="2")
{
panel1.Visible = false;
panel2.Visible = true;
panel3.Visible = false;
}
if (comboBox1.SelectedText=="3")
{
panel1.Visible = false;
panel2.Visible = false;
panel3.Visible = true;
}
Related
I'm trying to create an Update button to let me insert data into a gridview and after creating the class, the button does nothing and I don't understand why that is the case.
private void Basic()
{
// no updates allowed
dataGridView1.AllowUserToAddRows = false;
dataGridView1.AllowUserToDeleteRows = false;
dataGridView1.ReadOnly = true;
//UpdateButton is available
UpdateButton.Enabled = true;
//Save and Cancel Unavailable
SaveButton.Visible = false;
CancelButton.Visible = false;
sTableAdapter.Fill(dataSet1.S);
}
This is the UpdateButton Event
private void UpdateButton_Click(Object sender, EventArgs e)
{
dataGridView1.AllowUserToAddRows = true;
dataGridView1.AllowUserToDeleteRows = true;
dataGridView1.ReadOnly = false;
UpdateButton.Enabled = false;
SaveButton.Visible = true;
CancelButton.Visible = true;
}
And this should be the update class:
this.UpdateButton.Location = new System.Drawing.Point(12, 63);
this.UpdateButton.Name = "UpdateButton";
this.UpdateButton.Size = new System.Drawing.Size(103, 23);
this.UpdateButton.TabIndex = 0;
this.UpdateButton.Text = "Update";
this.UpdateButton.UseVisualStyleBackColor = true;
The connection is made with a accdb.
The Update button isn't working on click, what did I do wrong?
I am trying to disable all buttons I am using after a time period of inactivity using the timer from toolbox. I can currently get it to work by just disabling the relevant buttons in
private void timer1_Tick(object sender, EventArgs e)
but this disables in ten seconds regardless of activity or inactivity.
Is it possible for the timer to work only after 10 seconds of no activity?
Here is the code I am using.
private void timer1_Tick(object sender, EventArgs e) {
button1.Enabled = false;
button2.Enabled = false;
button3.Enabled = false;
button4.Enabled = false;
button5.Enabled = false;
button6.Enabled = false;
button7.Enabled = false;
button8.Enabled = false;
button9.Enabled = false;
button10.Enabled = false;
button11.Enabled = false;
button12.Enabled = false;
button13.Enabled = true;
button14.Enabled = true;
button14.Visible = false;
button15.Enabled = true;
button15.Visible = false;
button17.Enabled = false;
button17.Visible = false;
button18.Visible = false;
button19.Visible = false;
button20.Enabled = false;
textBox1.Visible = false;
textBox2.Visible = false;
textBox3.Visible = false;
textBox4.Visible = false;
checkBox1.Visible = false;
checkBox2.Visible = false;
label15.Visible = false;
label16.Visible = false;
label21.Visible = false;
}
Any help would be greatly appreciated.
Just add the following event to each button that might be clicked and be counted as 'active':
public void ResetTimer(object sender, EventArgs e)
{
timer.Stop();
timer.Start();
}
...
button1.Click += ResetTimer;
The Timer in Winforms doesn't have a Reset method (nor does any of the other timer classes), so you'll have to stop it first and then start it again.
Solution 1:
Reset Time every time user click any button.
Solution 2: ( Not Recommended )
Have a global variable LastActiveTime, Every-time somebody clicks any
button :
LastActiveTime = DateTime.Now()
Parallel running Timer/Thread will check every second if inactive time is more than 10
second and will do accordingly.
i having a little advance with Command Button
lets say i having a form with
label1
label2
label3
And one command button of course
before click the command button
label1.Visible = true;
label2.Visible = false;
label3.Visible = false;
if i click the command button
label1.Visible = false;
label2.Visible = true;
label3.Visible = false;
and then i click again
label1.Visible = false;
label2.Visible = false;
label3.Visible = true;
and repeated again, then back to first before i click the command button
i didnt have any reference on this, so i just make a duplicated command button with same position in form, and i use the visible to get the another command button to be clicked
but it looks not cool,
is there any way better than i make?
you can make one button, and count the number of clicks the user has done, depending on the mod operation you can invoke any of the three method you provide, something like this:
int count = 1; //count clicks
private void ButtonClick(object sender, EventArgs e)
{
if(count%2 == 0)
{
label1.Visible = false;
label2.Visible = true;
label3.Visible = false;
}
else if(count%3 == 0){
label1.Visible = false;
label2.Visible = false;
label3.Visible = true;
}
else{
label1.Visible = true;
label2.Visible = false;
label3.Visible = false;
}
count++;
}
Something similar to this will allow you to only have one command button.
public int visibleLabel = 1;
private void commandButton_Click(object sender, EventArgs e)
{
this.visibleLabel += 1;
if (this.visibleLabel == 4) this.visibleLabel = 1
label1.visble = false;
label2.visble = false;
label3.visble = false;
switch (this.visibleLabel)
{
case 1:
label1.visble = true;
break;
case 2:
label2.visble = true;
break;
case 3:
label3.visble = true;
break;
}
}
Alternatively, you might want to consider having a single label and changing the text (assuming they are in the same locations as well)
Why dont you use a flag to track the current status of the command button? If I understand your question right you want a single command button that sets label2 to visible at first click and label3 visible at second click and label1 visible on third click. Do something like this in the command button click handler:
switch (status)
{
case 0:
{
label1.Visible = false;
label2.Visible = true;
label3.Visible = false;
status = 1;
break;
}
case 1:
{
label1.Visible = false;
label2.Visible = false;
label3.Visible = true;
status = 2;
break;
}
case 2:
{
label1.Visible = true;
label2.Visible = false;
label3.Visible = false;
status = 0;
break;
}
}
Some of the code is redundant, and of course you should have a integer variable called status somewhere in your class. Anyway, this should be fairly understandable and I hope it helps.
please i need a help i'm writing a code for hangman game and i want just to change the icon of the form , i try that using the icon property but it doesn't work any more ,please how i can do this ,and also i do the following project-->properties--->icon and manifest but also it doesn't work this is my code for the game it work perfectly :
private void button1_Click(object sender, EventArgs e)
{
stage_count++;//strat from stage 1
if (!int.TryParse(textBox1.Text.ToString(), out value))
return;//if user inter non_integer value do no thing and wait for new entry
if (key ==value )//directly if user guesses the key he/she wins the game
{
//view the seventh picture in hangman game
button1.Enabled = false;
textBox1.Text = "";
textBox1.Enabled = false;
pictureBox7.Visible = true;
pictureBox1.Visible = false;
pictureBox2.Visible = false;
pictureBox3.Visible = false;
pictureBox4.Visible = false;
pictureBox5.Visible = false;
pictureBox6.Visible = false;
groupBox1.Visible = true;
label1.Text = "Great... You Got It ^_^ ";
}
if (key > value)//guide the user to the correct answer
label1.Text = "Should Be Greater than" + value.ToString();
if (key < value)//guide the user to the correct answer
label1.Text = "Should Be Less than" + value.ToString();
if (key != value)
{
switch (stage_count)
{//this switch statement used to do some thing in each stage
case 1:
//view the first picture in hangman game
pictureBox1.Visible = true;
pictureBox2.Visible = false;
pictureBox3.Visible = false;
pictureBox4.Visible = false;
pictureBox5.Visible = false;
pictureBox6.Visible = false;
pictureBox7.Visible = false;
break;
case 2:
//view the second picture in hangman game
pictureBox1.Visible = false;
pictureBox2.Visible = true;
pictureBox3.Visible = false;
pictureBox4.Visible = false;
pictureBox5.Visible = false;
pictureBox6.Visible = false;
pictureBox7.Visible = false;
break;
case 3:
//view the third picture in hangman game
pictureBox1.Visible = false;
pictureBox2.Visible = false;
pictureBox3.Visible = true;
pictureBox4.Visible = false;
pictureBox5.Visible = false;
pictureBox6.Visible = false;
pictureBox7.Visible = false;
break;
case 4:
//view the fourth picture in hangman game
pictureBox1.Visible = false;
pictureBox2.Visible = false;
pictureBox3.Visible = false;
pictureBox4.Visible = true;
pictureBox5.Visible = false;
pictureBox6.Visible = false;
pictureBox7.Visible = false;
break;
case 5:
//view the fifth picture in hangman game
pictureBox1.Visible = false;
pictureBox2.Visible = false;
pictureBox3.Visible = false;
pictureBox4.Visible = false;
pictureBox5.Visible = true;
pictureBox6.Visible = false;
pictureBox7.Visible = false;
break;
default:
//view the sixth picture in hangman game
//it's the last try so diable the button and show the result
button1.Enabled = false;
textBox1.Text = "";
textBox1.Enabled = false;
groupBox1.Visible = true;
label1.Text = "YOU LOSE ,, IT WAS : " + key.ToString();
pictureBox1.Visible = false;
pictureBox2.Visible = false;
pictureBox3.Visible = false;
pictureBox4.Visible = false;
pictureBox5.Visible = false;
pictureBox6.Visible = true;
pictureBox7.Visible = false;
break;
}//end switch
//to make empty focused textbox
textBox1.Text = "";
textBox1.Focus();
}//end if
}
private void groupBox1_Enter(object sender, EventArgs e)
{
}
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{// if user want to playe new game the programm must enables the important controls and
//make the visible property equals to false for all the pictures boxes
if (radioButton1.Checked == true)
{
stage_count = 0;
key = (1 + obj.Next(99));
textBox1.Enabled = true;
textBox1.Text = "";
textBox1.Focus();
button1.Enabled = true;
label1.Text = "Guess a number btween 1-100";
pictureBox1.Visible = false;
pictureBox2.Visible = false;
pictureBox3.Visible = false;
pictureBox4.Visible = false;
pictureBox5.Visible = false;
pictureBox6.Visible = false;
pictureBox7.Visible = false;
groupBox1.Visible = false;
radioButton1.Checked = false;
}
}
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
// if user won't to play again just close it
if (radioButton2.Checked == true)
{
radioButton2.Checked = false;
this.Close();
}
}
}
}
GO Properties window and change "Icon" property with your own icon.
You need to perform following steps
Add you icon to resouce file of project
than Asssing the created resource to you icon property .
Icon = Resources.adobe_reader_icon;
You have to set it in the properties of your project.
If you start your application by pressing F5 in VisualStudio and the icon doesn't appear, take a look in the Debug-(Release) Directory. There should be the correct icon
The icon of a form is only displayed if:
- ControlBox is true
- FormBorderStyle is not None
- Text is not empty
If so, you should then be able to set it with this.Icon = ...
Also the icon should be available as project resource. For this, you can just edit the forms Icon property, and in the following dialog import the icon from a .ico file.
<pre>
application root directory
application resources directory **LIKE** ../../resources/dropbox.ico
this.Icon = new System.Drawing.Icon("../../dropbox.ico");
</pre>
First Solution then Properties of the project Add .ico file
Then open Form which you want icon
In Form property you can find Icon Field
There you can change Icon your windows form.
I have my code written like so:
private void radioSelectButton_Click(object sender, EventArgs e)
{
if (pteriRadio.Checked) // Selecting avatar to be displayed from here on out.
//This avatar will also be displayed on the game board.
{
pteriBox1.Visible = true;
xweetokBox1.Visible = false;
ixiBox1.Visible = false;
label1.Text = ("Pteri Inventory");
player1avatar = "pteri";
}
else if (xweetokRadio.Checked)
{
xweetokBox1.Visible = true;
pteriBox1.Visible = false;
ixiBox1.Visible = false;
label1.Text = ("Xweetok Inventory");
player1avatar = "xweetok";
}
else if (ixiRadio.Checked)
{
ixiBox1.Visible = true;
pteriBox1.Visible = false;
xweetokBox1.Visible = false;
label1.Text = ("Ixi Inventory");
player1avatar = "ixi";
}
characterSelectBox.Visible = false;
radioSelectButton.Visible = false;
characterSelectBox2.Visible = true;
radioSelectButton2.Visible = true;
}
It seems as though the visibility changes should display when I have it like this, with the changes within the button click but outside of the if statements (It doesn't matter what the user selects, once selected the option to select needs to disappear for that user.)Yet the visibility changes don't execute. What am I missing here?
If I nest the if-statements as suggested by a previous person, here's what I have:
private void radioSelectButton_Click(object sender, EventArgs e)
{
if (pteriRadio.Checked) // Selecting avatar to be displayed from here on out.
//This avatar will also be displayed on the game board.
{
pteriBox1.Visible = true;
xweetokBox1.Visible = false;
ixiBox1.Visible = false;
label1.Text = ("Pteri Inventory");
player1avatar = "pteri";
if (xweetokRadio.Checked)
{
xweetokBox1.Visible = true;
pteriBox1.Visible = false;
ixiBox1.Visible = false;
label1.Text = ("Xweetok Inventory");
player1avatar = "xweetok";
if (ixiRadio.Checked)
{
ixiBox1.Visible = true;
pteriBox1.Visible = false;
xweetokBox1.Visible = false;
label1.Text = ("Ixi Inventory");
player1avatar = "ixi";
}
characterSelectBox.Visible = false;
radioSelectButton.Visible = false;
characterSelectBox2.Visible = true;
radioSelectButton2.Visible = true;
}
}
}
Now, not only do the visible items not swap over, two of the character choices don't display.
It looks like the radio buttons here can be checked/unchecked together. I think you should use separate if statements for each condition instead of else if.
You need to Invalidate your form to make it redraw after you change the properties. Assuming the radioSelectButton_Click method is in the same form, calling this.Invalidate() at the end of the method should force the redraw.