Moving panels on button press C# [closed] - c#

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
}

Related

Windows Form: Display unique panel based on list selection [closed]

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

How to have fixed HeaderColumn width in ListView? [closed]

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
I want know how to have fixed HeaderColumn width in ListView.
private void listView_ColumnWidthChanging(object sender, ColumnWidthChangingEventArgs e)
{
e.Cancel = true;
e.NewWidth = listView.Columns[e.ColumnIndex].Width;
}
But this method is not resolved.
Can anybody help me solve this problem?
Prevent visual change during mouse move on _ColumnWidthChanging event. And remember previous width of sized column, and that it was user sizing event (not the designed code).
And on _ColumnWidthChanged event check if user sizing event and reset the width of column.
bool ColumnWidthChanging = false;
int ColumnWidthChangingWidth = -1;
private void listView1_ColumnWidthChanging(object sender, ColumnWidthChangingEventArgs e)
{
ColumnWidthChangingWidth = listView1.Columns[e.ColumnIndex].Width;
ColumnWidthChanging = true;
e.Cancel = true;
}
private void listView1_ColumnWidthChanged(object sender, ColumnWidthChangedEventArgs e)
{
if (ColumnWidthChanging)
{
ColumnWidthChanging = false;
listView1.Columns[e.ColumnIndex].Width = ColumnWidthChangingWidth;
}
}

Dissapear text in textbox in c# [closed]

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 = ""

creating a new button or making it appear in an if statement in C# [closed]

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

How do i make a number appear in a text box after a button is pressed? [closed]

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.

Categories