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

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.

Related

if statements in C# for a textbox to change back to normal when i press a button for the second time

This is the code that i used to change the text in the text box from "Livre" to "Ocupado"
What code should i use to change it from "Ocupado" to "Livre"
private void button1_Click(object sender, EventArgs e)
{
textBox1.Text="Ocupado";
}
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text == "Livre")
{
textBox1.Text = "Ocupado";
}
else
{
textBox1.Text = "Livre";
}
}
you can add a variable to your class
e.g.:
bool livre = true;
private void button1_Click(object sender, EventArgs e)
{
if (livre)
{
textBox1.Text="Ocupado";
}
else
{
textBox1.Text="Livre";
}
livre = !livre;
}

How to make a screen share application

I am trying to make a simple screen share application in C# and found this guide: https://www.c-sharpcorner.com/uploadfile/ulricht/how-to-create-a-simple-screen-sharing-application-in-C-Sharp/ and followed it but it doesn't work i tried it on the same computer and on two different PCs but nothing seems to work
//Host
public partial class ScreenShareHandler : Form
{
RDPSession x = new RDPSession();
public ScreenShareHandler()
{
InitializeComponent();
}
private void ScreenShareHandler_Load(object sender, EventArgs e)
{
}
private void Incoming(object Guest)
{
IRDPSRAPIAttendee MyGuest = (IRDPSRAPIAttendee)Guest;//???
MyGuest.ControlLevel = CTRL_LEVEL.CTRL_LEVEL_INTERACTIVE;
}
private void button1_Click(object sender, EventArgs e)
{
x.OnAttendeeConnected += Incoming;
x.Open();
}
private void button2_Click(object sender, EventArgs e)
{
IRDPSRAPIInvitation Invitation = x.Invitations.CreateInvitation("Trial", "MyGroup", "", 10);
textBox1.Text = Invitation.ConnectionString;
}
private void button3_Click(object sender, EventArgs e)
{
x.Close();
x = null;
}
}
//Client
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
string Invitation = textBox1.Text;// "";// Interaction.InputBox("Insert Invitation ConnectionString", "Attention");
axRDPViewer1.Connect(Invitation, "User1", "");
}
private void button2_Click(object sender, EventArgs e)
{
axRDPViewer1.Disconnect();
}
}
As written in my comments:
Have you hooked up the eventhandlers correctly? If you click on the button in the designer you can go to the Events Tab in the Property-window and check if the Click-event points to the right eventhandler. Another way to check if the correct handler is used is to put a breakpoint inside each handler. Then debug and check if you get into the right method when you click the button. If not you didn't hook up the Eventhandlers correctly.

Xamarin - Morse code app usuing the flaslight

I am trying to make a morse code for a college project, what I'm trying to do is use a 2 dimensional array to save the morse code people input to a text file and then be able to load it from the text file, my logic was to was that within the array was this array[morse name][morse input]. what I need to figure out first is how to send data from methods / buttons OBtn_Clicked , LBtn_Clicked, SBtn_Clicked and EndBtn_Clicked to NewMorseBtn_Clicked to add into the array which will then write it out to a text file I've created.
namespace FlashLightApp2018
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class MorsePage : ContentPage
{
//bool exitLoop = false;
public MorsePage()
{
InitializeComponent();
}
private async void NewMorseBtn_Clicked(object sender, EventArgs e)
{
bool isTextEmpty = String.IsNullOrEmpty(MorseName.Text);
if (isTextEmpty)
{
}
else
{
OBtn.IsEnabled = true;
LBtn.IsEnabled = true;
SBtn.IsEnabled = true;
EndBtn.IsEnabled = true;
// String morseName = MorseName.Text;
//String[,] morseSave = new String[100,100];
}
//File.WriteAllText(morseName, text);
//while (exitLoop != true)
//{
//}
}
private void LoadMorseBtn_Clicked(object sender, EventArgs e)
{
}
private void PlayMorseBtn_Clicked(object sender, EventArgs e)
{
}
private void OBtn_Clicked(object sender, EventArgs e)
{
}
private void LBtn_Clicked(object sender, EventArgs e)
{
}
private void SBtn_Clicked(object sender, EventArgs e)
{
}
private void EndBtn_Clicked(object sender, EventArgs e)
{
}
}
}
first, declare you data at the class level (outside of a single method) so that it is accessible from throughout your class
string morseData = string.Empty;
then have your different button methods update the data
private void OBtn_Clicked(object sender, EventArgs e)
{
morseData += ".";
}
private void LBtn_Clicked(object sender, EventArgs e)
{
moreseData += "-";
}

How to disable a combobox on clicking on another combox list data in C sharp?

I want to design a windows form using C sharp on Visual Studio 2013.
I go through the Source from here. but did not got it properly.
for that I have 3 combobox. I want to disable combobox2 when I click on combobox1 NSSCM element and enable when click on NSSFO element.
Below is my part of code snippet:
namespace NSE_First_Form
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
MaximizeBox = false;
MinimizeBox = false;
if (true)
{
comboBox1.Items.Add(Exchange.NSSCM.ToString());
comboBox1.Items.Add(Exchange.NSSFO.ToString());
comboBox1.Items.Add(Exchange.BSSCM.ToString());
}
}
private void button1_Click(object sender, EventArgs e)
{
string selectedItem = string.Empty;
ProcessValue(selectedItem);
}
public enum Exchange
{
NSSCM = 1,
NSSFO = 2,
BSSCM = 3
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
Try this:
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBox1.SelectedIndex == 0)
comboBox2.Enabled = false;
if (comboBox1.selectedIndex == 1)
comboBox2.Enabled = true;
}
Try this:
//This will disable combobox2 on the click of it
private void comboBox1_Click(object sender, EventArgs e)
{
comboBox2.Enabled = false;
}
//This will enable combobox2 on the click of it
private void comboBox1_Click(object sender, EventArgs e)
{
comboBox2.Enabled = true;
}
Because you want it on click, use the CLICK event, instead of SelectedIndexChange event.

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

Categories

Resources