I am currently working with a Windows Form project and I am trying to make a TextBox allow input from another TextBox. I have the following code below and am stuck trying to get this to function correctly.
namespace Arlistia3._0
{
public partial class ArlistiaInterface : Form
{
public static string userInput;
public ArlistiaInterface()
{
InitializeComponent();
IntroScene();
}
private void IntroScene()
{
gameText.Text = "Welcome, what is your name?";
}
private void button1_Click(object sender, EventArgs e)
{
}
private void playerTextInput_TextChanged(object sender, EventArgs e)
{
userInput = gameText.Text;
}
}
}
I think this is what you want. It's similar to Lei Yang's:
private void playerTextInput_TextChanged(object sender, EventArgs e)
{
gameText.Text = "Welcome, " + playerTextInput.Text;
}
Hope it helps!
I think this is what you want. You may need to set the Multiline property of your gameText TextBox to true, I'm not sure.
private void playerTextInput_TextChanged(object sender, EventArgs e)
{
gameText.Text += "You: " + playerTextInput.Text + Environment.Newline;
}
I think this is what you want.
string Welcom="Welcome, what is your name?";
private void playerTextInput_TextChanged(object sender, EventArgs e)
{
gameText.Text = Welcom + playerTextInput.Text;
}
Related
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;
}
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.
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 += "-";
}
Need help in making a simple calculator. i can't put more than one number in my calculator's textbox. Everytime i put a second number it replaces the first one need help!
I can't exceed more than one input number in my Calculator's Textbox instead it replaces the first number with a second number input
namespace Calculator_Project
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void InputOutputArea_TextChanged(object sender, EventArgs e)
{
}
private void One_Click(object sender, EventArgs e)
{
int Input = 1;
InputOutputArea.Text = Input.ToString();
}
private void Two_Click(object sender, EventArgs e)
{
int Input = 2;
InputOutputArea.Text = Input.ToString();
}
private void Three_Click(object sender, EventArgs e)
{
}
private void Four_Click(object sender, EventArgs e)
{
}
private void Five_Click(object sender, EventArgs e)
{
}
private void Six_Click(object sender, EventArgs e)
{
}
private void Seven_Click(object sender, EventArgs e)
{
}
private void Eight_Click(object sender, EventArgs e)
{
}
private void Nine_Click(object sender, EventArgs e)
{
}
private void Eql_Click(object sender, EventArgs e)
{
}
private void AddB_Click(object sender, EventArgs e)
{
}
private void Minus_Click(object sender, EventArgs e)
{
}
private void MultiplyB_Click(object sender, EventArgs e)
{
}
private void DivideB_Click(object sender, EventArgs e)
{
}
private void Zero_Click(object sender, EventArgs e)
{
}
private void ResetB_Click(object sender, EventArgs e)
{
InputOutputArea.Clear();
}
}
}
You should use
InputOutputArea.Text += Input.ToString();
(note the '+') in order to append to a text box.
private void Two_Click(object sender, EventArgs e)
{
int Input = 2;
InputOutputArea.Text += Input.ToString();
}
You must use += to add other text to next of first text
Here is your problem:
InputOutputArea.Text = Input.ToString();
This replaces the content of the textbox instead of adding to it.
InputOutputArea.Text += Input.ToString();
the above code should do as you ask.
Good to remember is that concatenating strings with + is rather inefficient, so don't do this in performance critical code unless absolutely necessary. In those cases a String-builder is almost always better.
Every answers talking about the Concatenation of the previous text with the current, But I would like to suggest something more than that;
You need not to create separate event handlers for all your buttons that are doing same tasks, Hope that the Text of each button will be the number that you need to display in the textBox(say btnOne will holds 1 and btnTwoholds 2 and so on). By make use of this Text we can reuse the handlers like the following, Let btnNumber_Click be the handler and which is defined like the following:
private void btnNumber_Click(object sender, EventArgs e)
{
Button currentButton = sender as Button;
InputOutputArea.Text += currentButton.Text;
}
I am new in to C# programming and I have come across small issues i just cant wrap my mind around. I am creating small application which is going to have 3 input boxes as on screenshot below. When user click on Source button it will have freedom to chose the source folder. Once he select OK the Text Box next to the folder will be populated with path.So i got that part working.
Now the problem is that i am running out of the talent to figure out why that path from the box is not passed to the string in the code. For example, if i type the location of the List and put in string Item_List the code works fine. If i would to do same for the strings Source and Destination the app works perfectly fine. But when I try to have user set those variables by simply selecting the path destination it doesnt work. So just need to see what am i missing. Why the value from the text box which is C:\Files is not being passed to string Source = #"" . I am assuming I am handling this on wrong way due to "\" or it might be something else. Any ideas?
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
string Source = #"";
string Destination = #"";
string Item_List = #"C:\Users\Slavoljub Petkovic\Desktop\List.txt";
public Form1()
{
InitializeComponent();
}
//------------Form1 Load()----------------------------
private void Form1_Load(object sender, EventArgs e)
{
Source = tbSource.Text;
Destination = Convert.ToString(tbDestination.Text);
}
//-----------Move Files In The List-------------------
private void MoveFileInList()
{
StreamReader sr;
string curFile;
string to_file, from_file;
sr = File.OpenText(Item_List);
curFile = sr.ReadLine();
while (curFile != null)
{
to_file = Destination + "/" + curFile;
from_file = Source + "/" + curFile;
File.Move(from_file, to_file);
curFile = sr.ReadLine();
}
sr.Close();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void label2_Click(object sender, EventArgs e)
{
}
private void label3_Click(object sender, EventArgs e)
{
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
MoveFileInList();
}
private void label5_Click(object sender, EventArgs e)
{
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
private void Box_Source_TextChanged(object sender, EventArgs e)
{
}
private void Box_List_TextChanged(object sender, EventArgs e)
{
}
private void button1_Click_1(object sender, EventArgs e)
{
}
private void folderBrowserDialog1_HelpRequest(object sender, EventArgs e)
{
}
private void DestinationPath_Click(object sender, EventArgs e)
{
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
this.tbDestination.Text = folderBrowserDialog1.SelectedPath;
}
}
private void SourcePath_Click(object sender, EventArgs e)
{
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
this.tbSource.Text = folderBrowserDialog1.SelectedPath;
}
}
private void ListPath_Click(object sender, EventArgs e)
{
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
this.tbList.Text = folderBrowserDialog1.SelectedPath;
}
}
private void Form1_Load_1(object sender, EventArgs e)
{
}
private void tbList_TextChanged(object sender, EventArgs e)
{
}
}
}
You are assigning the values of the Source and Destination textboxes to two variables in your form load event.
Source = tbSource.Text;
Destination = tbDestination.Text;
These variables than contain the text that is written in those textboxes at the moment the form loads and will not be updated when the text in the textboxes changes.
When you use those values in your MoveFileInList method, they will contain the values of the textboxes on load time and not the current value.
to_file = Destination + "/" + curFile;
from_file = Source + "/" + curFile;
What you want to do is read the current values of the textboxes.
to_file = Destination.Text + "/" + curFile;
from_file = Source.Text + "/" + curFile;