As the picture has been attached below,I have 2 panel from splitcontainercontrol .Panel 1 contains 1 button and panel 2.
I want to ask everybody how to write code for this button(panel1) to collapse panel 2 without changing properties and clicking on spliter when runs app .
You can simply collapse the panel with the following code :
private void button1_Click(object sender, EventArgs e)
{
splitContainer1.Panel2Collapsed = true;
}
If you do not want to change the propery of the panel, then you can hide the panel. Try this :
private void button1_Click(object sender, EventArgs e)
{
splitContainer1.Panel2.Hide();
}
And you can show the panel with this : splitContainer1.Panel2.Show();
Related
I insert tab-control in my windows application.It has 4 tab-pages.I wanted to show only relevant tab-page when I click the relevant button..my code as follows
private void Form1_Load(object sender, EventArgs e)
{
tabControl1.TabPages.Remove(tabPage1);
tabControl1.TabPages.Remove(tabPage2);
tabControl1.TabPages.Remove(tabPage3);
tabControl1.TabPages.Remove(tabPage4);
this.tabPage1.Hide();
this.tabPage2.Hide();
this.tabPage3.Hide();
this.tabPage4.Hide();
}
first every tab-page removed when form load
Here is the code for button click and I coded for 4 buttons...
private void button2_Click(object sender, EventArgs e){
tabControl1.TabPages.Insert(0, tabPage1);
this.tabPage1.Show();
tabControl1.TabPages.Remove(tabPage2);
tabControl1.TabPages.Remove(tabPage3);
tabControl1.TabPages.Remove(tabPage4);
this.tabPage2.Hide();
this.tabPage3.Hide();
this.tabPage4.Hide();
}
I again used ....
tabControl1.TabPages.Remove(tabPage2);
tabControl1.TabPages.Remove(tabPage3);
tabControl1.TabPages.Remove(tabPage4);
this.tabPage2.Hide();
this.tabPage3.Hide();
this.tabPage4.Hide();
these code. if another tabpage is opened when I click the button it should be remove and show relevant tabpage.Its working.
My problem is.. if I click the same button again and again same tabpages adding continuously
Can anyone give me a solution for it..
I founded a one way...In button click I modify like this.
private void button1_Click(object sender, EventArgs e)
{
tabControl1.TabPages.Remove(tabPage1);
if (tabControl1.TabPages.Count <= 1)
{
tabControl1.TabPages.Insert(0, tabPage1);
this.tabPage1.Show();
tabControl1.TabPages.Remove(tabPage2);
tabControl1.TabPages.Remove(tabPage3);
tabControl1.TabPages.Remove(tabPage4);
this.tabPage2.Hide();
this.tabPage3.Hide();
this.tabPage4.Hide();
}
}
first code is tabControl1.TabPages.Remove(tabPage1).Then if tab-page is open It removed.If statement responsible for when button click relevant tab page is opened.then always show only one tab-page for button click moment
I noticed that by programmatically selecting a Tab in the Tab control selects a control contained in the tab page selected.Is it possible to change this behaviour. I have a control in a tabpage that I do not want to be selected when the its tab page is selected from a button click. I have a simple form with a tab control and two tab pages. When button1 is clicked the tab page 2 is selected but so is the datagridview contained in that tab page.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
dataGridView1.GotFocus += DataGridView1_GotFocus;
}
private void DataGridView1_GotFocus(object sender, EventArgs e)
{
//this event is called from button1_click
}
private void button1_Click(object sender, EventArgs e)
{
tabControl1.SelectedTab = tabPage2;
}
}
By default when you select a tab (or even when you start a form) the control which is the first in your tab order is automatically focused. I am assuming this is what is happening here.
You can solve this by simply unfocusing the datagridView in question. There are multiple ways to do this. Firstly you can set focus to the control that you wish to be selected instead of the dataGridView. This can be done by:
myControl.Focus = True;
Or alternatively if you want non of the controls to be selected you can set the active control to Null:
ActiveControl = NULL;
Note: ActiveControl is a property which contains the current active control.
As to where this code should be placed. That is totally dependent upon you. You can do it as soon as you change the tab in the button click event. This is what I would prefer.
I am sure there are other kludges as well to acheive the same. Hope this helps.
Here is code to select tab
private void button1_Click(object sender, EventArgs e)
{
// we can select tab by tab name
tabControl1.SelectTab("tabPage2");
tabControl1.SelectedIndex = 1;
tabControl1.TabPages[0].Hide();
tabControl1.TabPages[1].Show();
}
I have made 2 user controls. First one contains a textbox and a button. In the second one there is a panel and a repeater control is used. Now when I am writing in the textbox 2nd control will open as a popup and and after focusing to textbox I am unable to write. I have searched a lot about this but nothing works.
CustomPopup customPopup;
Popup popup;
popup = new Popup(customPopup = new CustomPopup());
private void txtSearch_TextChanged(object sender, EventArgs e)
{
popup.Width = Width;
popup.Show(this);
popup.AutoClose = false;
}
In this way I am opening the popup from the textbox text changed event.
You can use this textbox event.
private void textBox1_Enter(object sender, EventArgs e)
{
}
this event call whenever textbox get focus
I want to create UI like this in Windows form application C#.
First my form should appear like this when the chechBox is not checked.
And if the checkBox checked my form changes to like this
How can I do this?
Change the height of the form dynamically on CheckedChanged event of check box. Don't forget to set anchor of below fields or set visible on expand and invisible on collapse.
EDIT: The most simple way to achieve the results is given below.
private readonly int _collapsedHeight;
public Form1()
{
//Set Anchor of Connect button to Right and Bottom and leave default for others
//Optionally you need to hide controls except Connect button on collapse and vice versa.
//Set Form Border Style to FixedSingle and MaximizeBox to false
InitializeComponent();
_collapsedHeight = Height;
}
private void chkAdvancedOption_CheckedChanged(object sender, EventArgs e)
{
//Set Y value to collapse eg. 140, adjust it as required...
Height = chkAdvancedOption.Checked ? _collapsedHeight + 140 : _collapsedHeight;
}
void Page_Load(Object sender, EventArgs e)
{
// Manually register the event-handling method for the
// CheckedChanged event of the CheckBox control.
checkbox1.CheckedChanged += new EventHandler(this.Check_Clicked);
}
void Check_Clicked(Object sender, EventArgs e)
{
**//This is only sample code**
// do your code
if (panel2.Visible)
{
panel2.Visible = false;
cmdAdvanced.Visible = true;
}
}
I am trying to place Usercontrols on a flowlayout panel that act as a listview in C# (windows forms) . How can I implement selecting items here ?
Click event is not working when the user clicks on the controls of Usercontrol..
Any ideas ?
private void flowLayoutPanel1_ControlAdded(object sender, ControlEventArgs e)
{
e.Control.Click += new EventHandler(Clicked);
}
private void Clicked(object sender, EventArgs e)
{
//click event code goes here
}