c# create object for .show() and .hide() - c#

Is there a way to create a method that goes like this in C#:
public void showHide(string shOne, string shTwo, string shThree) {
button1.shOne();
button2.shTwo();
button3.shThree();
}
private void discountButton_Click(object sender, EventArgs e) {
showHide("Show", "Hide", "Hide")
// I was thinking that this should be the same as
// button1.Show();
// button2.Hide();
// button3.Hide();
}
Is this possible ? I'm designing a c# application for thesis and I need to show and hide buttons (lots of buttons and labels and stuff).
I'm using this code as of now but I keep getting error:
Panel' does not contain a definition for 'shOne'.

public void showHide(bool shOne, bool shTwo, bool shThree)
{
button1.Visible = shOne;
button2.Visible = shTwo;
button3.Visible = shThree;
}

You can do this by multiple ways here is my code
private void button1_Click(object sender, EventArgs e)
{
if (button2.Visible == false)
{
button2.Show();
}
else
{
button2.Hide();
}
}

Related

How to combine two buttons

There is button_play and button_pause. I want to combine them into one button. The first time the song is pressed, the song starts playing. The second press - pause. At the third press, the playback continues. I can not do it.
Please tell me, how I can combine them.
private void button_play_Click(object sender, EventArgs e)
{
if ((list_catalog.Items.Count != 0) && (list_catalog.SelectedIndex != -1))
{
string current = Vars.Files[list_catalog.SelectedIndex];
Vars.CurrentTrackNumber = list_catalog.SelectedIndex;
BassLike.Play(current, BassLike.Volume);
label_time1.Text = TimeSpan.FromSeconds(BassLike.GetPosOfStream(BassLike.Stream)).ToString();
label_time2.Text = TimeSpan.FromSeconds(BassLike.GetTimeOfStream(BassLike.Stream)).ToString();
xrewind.Maximum = BassLike.GetTimeOfStream(BassLike.Stream);
xrewind.Value = BassLike.GetPosOfStream(BassLike.Stream);
timer1.Enabled = true;
}
}
private void button_pause_Click(object sender, EventArgs e)
{
BassLike.Pause();
}
Something like:
private bool _isPlaying;
private void button_Click(object sender, EventArgs e)
{
if(!_isPlaying)
{
mediaThing.Play();
button1.Text = "Pause";
}
else
{
mediaThing.Pause();
button1.Text = "Play";
}
_isPlaying = !_isPlaying;
}
The easiest way is to create a new Button object, and add the proper method for displaying the correct image. Something like this:
public class ButtonStateHandler:MonoBehaviour {
public boolean isClicked;
public Button myBtn;
public Sprite Play;
public Sprite Pause;
public void Click(){
changeState();
}
private void changeState(){
isClicked = !isClicked;
if(isClicked) myBtn.image.sprite = Play;
else myBtn.image.sprite = Pause;
}
}
Hope this helps!

c# winforms button and richtextbox

I made ​​a winform with 1 richtextbox and two buttons,
and I hope that when I click on the yes button , it will show a method soal2 in richtextbox1 , and then when I click again it will show soal3 , how to do that?
this is my design
public void soal1()
{
richTextBox1.Text = "Hemofilia is xxxxx";
}
public void soal2()
{
richTextBox1.Text = "xxxxxxx";
}
public void soal3()
{
richTextBox1.Text = "yyyyyy";
}
private void Quiz1_Load(object sender, EventArgs e)
{
soal1();
}
private void button1_Click(object sender, EventArgs e)
{
}
/* ... */
bool alreadyShownSoal2 = false;
private void button1_Click(object sender, EventArgs e)
{
if(alreadyShownSoal2)
soal3();
else
soal2();
alreadyShownSoal2 = true;
}
or
/* ... */
bool alreadyShownSoal2 = false;
public void soal2()
{
if(alreadyShownSoal2)
soal3();
else
richTextBox1.Text = "xxxxxxx";
alreadyShownSoal2 = true;
}
/* ... */
private void button1_Click(object sender, EventArgs e)
{
soal2();
}
This is an absolutely terrible design, but unless you give more specifications... it'd definitely do what you are asking

How to go from one "private void" to other "private void"?

how can i go from private void turnon to private void turnoff ? I want only know how to go from one void to other. I know i can just make from these two a one private void but i don't want it
private void turnon(object sender, EventArgs e)
{
button2.Visible = true
}
private void turnoff(object sender, EventArgs e)
{
button3.Visible = false
}
If you're wanting it to be visible in one event and visible in another, why not use one method like so:
private void SwitchState(object sender, EventArgs e)
{
button3.Visible = !button3.Visible;
}
On reading your comments I guess you want to add this line in at the end of your turnon event:
turnoff(sender, e);
Do you want a toggle? If so, you could use the following code.
private void toggle(object sender, EventArgs e)
{
button2.Visible = !button2.Visible;
}
Hi I want to make toggle button, So that it shows/hides the content by clicking that searchButton
Here is my code,
private boolean visible;
protected Button SearchButton;
private void Toggle(){
if(visible=false){
DishButton.setVisibility(View.INVISIBLE);
SpoonButton.setVisibility(View.INVISIBLE);
cupButton.setVisibility(View.INVISIBLE);
FridgeButton.setVisibility(View.INVISIBLE);
}
else {
DishButton.setVisibility(View.VISIBLE);
SpoonButton.setVisibility(View.VISIBLE);
cupButton.setVisibility(View.VISIBLE);
FridgeButton.setVisibility(View.VISIBLE);
visible=true;
}
}

How can I init items of a tab?

I have a form with 2 tabs on it. I can chose the tab viewed after initialization and I need some initial code every time after the tab2 is initialized:
public partial class SetupComponent : Form
{
public SetupComponent(bool tab2)
{
InitializeComponent();
if (tab2)
{
this.tabControl1.SelectedTab = tabPage2;
}
}
private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
{
textBox1.SelectionStart = textBox1.Text.Length;
textBox1.ScrollToCaret();
textBox2.SelectionStart = textBox2.Text.Length;
textBox2.Focus();
}
}
if I call this class with tab2=false and then click onto tab2, tabControl1_SelectedIndexChanged is called.
But if I select the tab2=true during SetupComponent, I find no possibility to do that code. All the TabControl1_Events I found are too early and I don`t find a matching TabPage2_Event.
How can I manage it?
I managed this problem using the Paint_Event:
bool activated = false;
private void tabPage2_Paint(object sender, PaintEventArgs e)
{
if (!activated)
{
tabControl1_SelectedIndexChanged(null, null);
activated = true;
}
}
I use the variable because the Paint_Event is called many times.

c# error cant understand what i should do to solve it

hi i have this code(and i get the ERROR that i must declare a body because it is not not marked abstract,extern or partial...by the way i couldnt get it to post it here but right over the public partial class Form1 : Form i also have written bool play1 = true;bool play2 = false; int x=1;int o=10; )when i click on it it goes up to that area that i marked with fat letters
could someone please show me what is wrong and how to solve it step by step
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
værdier();
int[] status = new int[9];
zeihne();
}
private string[] status;
private void value()
{
int[] status = new int[9];
zeihne();
}
private void zeihne()
{
button1.Text = status[0];
button2.Text = status[1];
button3.Text = status[2];
button4.Text = status[3];
button5.Text = status[4];
button6.Text = status[5];
button7.Text = status[6];
button8.Text = status[7];
button9.Text = status[8];
}
// private void label1_Click(object sender, EventArgs e)
{
}
**private void Form1_Load(object sender, EventArgs e);**
private void button1_Click(object sender, EventArgs e)
{
if (play1 == true)
{
play1 = true;
button1.Text = "X";
play1 = false;
}
else
{
play2 = true;
button1.Text = "O";
play2 = false;
play1 = true;
}
You haven't defined the method body for
private void Form1_Load(object sender, EventArgs e);
That's an abstract method and they are only allowed on abstract classes
Something like this would do the trick
private void Form1_Load(object sender, EventArgs e)
{
}
Or you can just get rid of the method if you don't plan to have any code on it.
EDIT
Something else that looks weird on your code is
// private void label1_Click(object sender, EventArgs e)
{
}
What are you trying to do? Two options:
// Option1: All the method commented
*/private void label1_Click(object sender, EventArgs e)
{
}*/
// Option2: Nothing commented
private void label1_Click(object sender, EventArgs e)
{
}
Hello Hwoarang H i tryed your code in my form and its working fine. You have to just follow step.
You have difine your method like this
private void Form1_Load(object sender, EventArgs e);
This is not right way to define method like this.You must declare like bellow
private void Form1_Load(object sender, EventArgs e)
{ }
Now remove your lable click event and brackets
// private void label1_Click(object sender, EventArgs e)
//{
//}
Now you got warning like x is issigned to but never used, o is assigned to but never used and status is assigned to but never used.No warry about that bcos you assign x and o as integer and used as string so this warning is come,i dont know whats your logic but if you want to remove this warning than use this int x,and o.Also play2 is never used so put condition like bellow
if (play1 == true)
{
btnSendNotification.Text = "x";
play1 = false;
}
else if(play2==true)
{
btnSendNotification.Text = "o";
play2 = false;
play1 = true;
}
Hope this is help you if not get solution than comment me.

Categories

Resources