Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I made a textbox of name tbFirstNumber
When i enter any value in that textbox , i want that Value to dissapear
I am using C# window form application in visual studio 2008
private void tbFirstNumber_TextChanged(object sender, EventArgs e)
{
}
tbFirstNumber.Text = "";
Just set it to empty on text changed event.
If you want that user is not allowed to enter any text, you can make the textbox as read only.
Set the TextBox control's ReadOnly property to true.
tbFirstNumber.ReadOnly = true;
Another way would be to hook in to the KeyPress event.
private void tbFirstNumber_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
// Stop the character from being entered into the control
e.Handled = true;
}
private void tbFirstNumber_TextChanged(object sender, EventArgs e)
{
tbFirstNumber.Text = "";
}
Clear the value of the text box
this.tbFirstNumber.Text = ""
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Using a Windows Form I am trying to replicate the functionality of a "Tab Control" but instead of the panel selection being controlled by a tab selection it would be controlled by a list. Is there a built in way to produce this using neatly like the tab control or should I just check if a list value is equal to some value and if yes display panel else don't?
This is probably a dumb question so sorry for wasting anyone's time and thanks in advance!
Besides, you can also use tabpages in tabcontrol as "panel". Just hide the header via the code
private void Form1_Load(object sender, EventArgs e)
{
tabControl1.Appearance = TabAppearance.FlatButtons;
tabControl1.ItemSize = new Size(0, 1);
tabControl1.SizeMode = TabSizeMode.Fixed;
foreach (TabPage tab in tabControl1.TabPages)
{
tab.Text = "";
}
}
Then select the tabpage like,
private void listBox_SelectedIndexChanged(object sender, EventArgs e)
{
if(((ListBox)sender).SelectedItem.ToString() == "tabPage2")
{
tabControl1.SelectedTab = tabPage2;
}
//...
}
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 5 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
I'm totally new into forms and I have an problem.
I would like to choose one of items in comboBox then hit button and my action regarding to chosen item is performed.
I'm creating list with options, boolean to check if button was hit and integer index.
List<string> options = new List<string> {"Dodaj studenta", "WyĆwietl studenta", "Edytuj studenta" };
private bool button1WasClicked = false;
int index;
I'm trying to read index from comboBox:
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
index = comboBox1.SelectedIndex;
}
Setting handle to button to change the value of boolean to true when user hits button:
private void button1_Click(object sender, EventArgs e)
{
button1WasClicked = true;
}
And setting the comboBox:
private void comboBoxSetup()
{
this.comboBox1.DataSource = options;
this.comboBox1.DropDownStyle = ComboBoxStyle.DropDownList; //read only
if(index == 0 && button1WasClicked == true)
{
System.Windows.Forms.MessageBox.Show("My message here");
}
}
PS: In constructor I have comboBoxSetup(); :)
When I'm checking only index in condition - popup is visible. Thanks for any help in advance!
Thanks to #Plutonix the solution that worked:
Insted of calling comboBoxSetup() in constructor I moved whole code from this method to
button1_Click(object sender, EventArgs e)
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm confused as to how I can accomplish this. I want to press the buttons and then the bottom panels go to the top and then open, if that makes sense.
This is essentially what I have
http://i.imgur.com/BzAeugE.png
And I only have the basic code for button clicks
private void CP_OneFbutton_Click(object sender, EventArgs e)
{
}
Any ideas guys?
To do this you need to change Panel's Location property like this:
panel1.Location = new Point(X,Y);
If you don't know exact coordinates,then you can handle Form MouseMove event (temporarily)
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
label1.Text = e.X + "," + e.Y;
}
Move mouse to the location where you want to panel move and note coordinates, then handle button click event and change panel's location
private void CP_OneFbutton_Click(object sender, EventArgs e)
{
panel1.Location = new Point(X,Y); // type your X and Y coordinates here
panel1.Visible = true; // Display the panel
}
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm using c# 2008 and i want to know if its possible to create(or display) a new button in an if statement after something happened. eg. if a certain label displays text, then a button must be created. If anyone can help, it will greatly be appreciated.
This code show you how to create and display a new button when double click mouse on the form:
public partial class Form1 : Form
{
private Button button1 = null;
public Form1()
{
InitializeComponent();
}
private void Form1_MouseDoubleClick(object sender, MouseEventArgs e)
{
if (button1 == null)
{
button1 = new Button();
button1.Text = "New Button";
button1.Location = new System.Drawing.Point(10, 10);
button1.Size = new System.Drawing.Size(150, 30);
button1.Click += new System.EventHandler(button1_Click);
this.Controls.Add(button1);
}
}
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("Button clicked.");
}
}
Note: this.Controls.Add(button1); add the button1 to the Form1. You also using this Controls property of other control to add a control to another control.
See more details:
http://msdn.microsoft.com/en-us/library/vstudio/system.windows.forms.control.controls(v=vs.100).aspx
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am new to this website and fairly new to programming.
I am making a calculator in C# and I would like to know how I would make a number appear in a text box after the button for it is pressed.
Thanks!
You need to add code to the button event handler:
public void Button1_Click(Object sender, EventArgs e)
{
TextBox1.Text = "1";
}
Which would display the string "1" into the Textbox.
You could also have multiple textboxes on the webpage and use:
public void Button1_Click(Object sender, EventArgs e)
{
string input1 = txtInput.Text;
string input2 = txtInput2.Text;
int userInput;
int userInput2;
int result;
Int32.TryParse(input1, out userInput);
Int32.TryParse(input2, out userInput2);
result = userInput + userInput2;
txtAnswer.Text = "The answer is: " result.ToString();
}
I have included a TryParse example which demonstrates if the conversion from the strings to integer was successful.