How write letters using the buttons in various textboxs? - c#

I have small app and I want write text in different textboxs using buttons.
This is my code , but click on button do not write text to text .
Please advise me.
What should I change?. In notepad it all works , but not in Textboxs.
enter image description here
public partial class Form1 : Form
{
protected override CreateParams CreateParams
{
get
{
CreateParams param = base.CreateParams;
param.ExStyle |= 0x08000000;
return param;
}
}
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
{
SendKeys.Send("A");
}
}
private void button3_Click(object sender, EventArgs e)
{
{
SendKeys.Send("B");
}
}
private void button2_Click(object sender, EventArgs e)
{
{
SendKeys.Send("C");
}
}
private void button4_Click(object sender, EventArgs e)
{
{
SendKeys.Send("D");
}
}
}
}

May be you should do something like this
private void button3_Click(object sender, EventArgs e)
{
//SendKeys.Send("B");
txtBox.Text += "B";
}
But because you don't know which text box to edit, you need to introduce variable
private TextBox _currTextBox;
// wire all text boxes to this "enter" event
private void txtBox_Enter(object sender, EventArgs e)
{
_currTextBox = (TextBox)sender;
}
// and accordingly
private void button3_Click(object sender, EventArgs e)
{
_currTextBox.Text += "B";
}

Related

How to store the values ​of the size of window, margin and textbox C# WF

It is necessary that after closing the program, it retains the size of the window, the values ​​of the CheckBox and what was entered in the TextBox.Can you write me a code?
namespace WindowsFormsApp8
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
}
private void checkBox2_CheckedChanged(object sender, EventArgs e)
{
}
}
}

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.

Button click events and restart problems

I have been able to get my exit button to work, but none of the others. I tried coding the other buttons the same way, but I get an error. The program also keeps restarting, even after I removed that code. Can someone tell me where I am going wrong on the other buttons and the restart problem?
namespace Module10Project
{
public partial class frmRadioStar : Form
{
public frmRadioStar()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
txtBx1.Text = "";
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
txtBx2.Text = "";
}
private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
listView1.Text = "";
}
private void btnExit_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void rdoAdd_CheckedChanged(object sender, EventArgs e)
{
}
private void btnCalc_Click(object sender, EventArgs e)
{
}
private void btnReset_Click(object sender, EventArgs e)
{
{
Application.Reset();
}
}
private void rdoSub_CheckedChanged(object sender, EventArgs e)
{
}
}
}

Can't put more than one number in the textbox. in my Simple Calculator program

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;
}

c# display the value to listview if 3 button is clicked

can someone help me on my problem I'm making an ordering system for our thesis and I don't know what to do next if 3 button is clicked
Things I want to happen:
user need to pick an item first then he/she will pick a quantity for the item(I have 10 buttons for quantity: 1,2,3,4,5,6,7,8,9,0)
so I add a button0 so the user need to pick item and then click button1 then button0 to have a quantity of 10 that will display in my listview
1-9 button is working now but my problem is what if the user wants the item for a quantity of 10 or more
so here I have my code for an item button1
private void button1_Click(object sender, EventArgs e)
{
ms = 1;
}
and the quantity button
private void button1_Click(object sender, EventArgs e)
{
if(ms == 1)
{
ListViewItem item = new ListViewItem(btnms1.Text);
item.SubItems.Add("1");
item.SubItems.Add("118");
listView1.Items.Add(item);
ms = 0;
}
}
private void button2_Click(object sender, EventArgs e)
{
//working
}
private void button3_Click(object sender, EventArgs e)
{
//working
}
private void button4_Click(object sender, EventArgs e)
{
//working
}
private void button5_Click(object sender, EventArgs e)
{
//working
}
private void button6_Click(object sender, EventArgs e)
{
//working
}
private void button7_Click(object sender, EventArgs e)
{
//working
}
private void button8_Click(object sender, EventArgs e)
{
//working
}
private void button9_Click(object sender, EventArgs e)
{
//working
}
here is the 0 button
private void button0_Click(object sender, EventArgs e)
{
// magic please
}
I'm not really sure what you want to achieve but it might be something like this.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
textBox1.Text += "1";
}
private void button2_Click(object sender, EventArgs e)
{
textBox1.Text += "2";
}
private void button3_Click(object sender, EventArgs e)
{
textBox1.Text += "3";
}
private void button4_Click(object sender, EventArgs e)
{
textBox1.Text += "4";
}
private void button5_Click(object sender, EventArgs e)
{
textBox1.Text += "5";
}
private void button6_Click(object sender, EventArgs e)
{
textBox1.Text += "6";
}
private void button7_Click(object sender, EventArgs e)
{
textBox1.Text += "7";
}
private void button8_Click(object sender, EventArgs e)
{
textBox1.Text += "8";
}
private void button9_Click(object sender, EventArgs e)
{
textBox1.Text += "9";
}
private void button10_Click(object sender, EventArgs e)
{
textBox1.Text += "0";
}
private void button11_Click(object sender, EventArgs e)
{
int quantity = 0;
bool quantityParse = int.TryParse(textBox1.Text, out quantity);
string productName = "Product Name"; // Sample Name
double productPrice = 300; // Sample Price
if (quantityParse)
{
ListViewItem lvi = new ListViewItem(productName); // Name
lvi.SubItems.Add(quantity.ToString()); // Quantity
lvi.SubItems.Add(productPrice.ToString()); // Price
lvi.SubItems.Add((productPrice * quantity).ToString()); // Subtotal
listView1.Items.Add(lvi);
}
}
}
Firstly, please start picking more meaningful names for variables as they help with code comprehension, especially when your code gets too complex for you or when you are sharing with others.
Secondly, how you're doing this at the moment is not the most intuitive way to go about things, always aim for the least amount of code as possible.
What I would be doing is calling the same event handler for each of the quantity buttons, but parsing the text in the buttons as a integer and adding that to a total string.
Ie:
private string QuantityText = string.Empty;
private void QtyButton_Click(object sender, EventArgs e)
{
if (sender is Button)
{
Button theButton = (Button)sender;
string qtyText = theButton.Content.ToString();
QuantityText += qtyText;
}
}
Then call something like this method when you want to process the quantity string:
Private Void ProcessQuantity()
{
int qtyAmount = -1;
int.TryParse(QuantityText, out qtyAmount)
if (qtyAmount > -1)
{
//Do Processing here
}
else
{
throw new InvalidArgumentException("Quantity is invalid");
}
}

Categories

Resources