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

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

Related

Calculate time difference with TextBox? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 days ago.
Improve this question
I got this time difference calculator and I don't like the DateTimePicker because when I have written the hour's it doesn't automatically jump over to minutes so I would like to change them to texbox, is that possible?
The problem Im having is that I cant use textBox.Value so what do I do?
private void button1_Click(object sender, EventArgs e)
{
TimeSpan result = this.dateTimePicker2.Value - this.dateTimePicker1.Value;
this.textBox1.Text = result.ToString();
string s = this.textBox1.Text;
string[] temparry = textBox1.Text.Split ('.');
textBox1.Text = temparry[0];
}
I would like it to be something more like this
private void button1_Click(object sender, EventArgs e)
{
TimeSpan result = this.texbox2.Value - this.texbox3.Value;
this.textBox1.Text = result.ToString();
string s = this.textBox1.Text;
string[] temparry = textBox1.Text.Split ('.');
textBox1.Text = temparry[0];
}
But it dosnt work

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

Action is not performed when clicking ComboBox and Button [closed]

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)

Moving panels on button press 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 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
}

Making text box visible/unvisible c# [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
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.
Closed 8 years ago.
Improve this question
I'm working on a windows form application and I have a button and a textbox in it.
When the button is pressed, it should make the textbox visible and hidden.
myTextbox.Visible = !myTextbox.Visible;
Did you try Google?
textBox1.Visible = false;
You can toggle the visibility by doing:
if(textBox1.Visible == true)
textBox1.Visible = false;
else
textBox1.Visible = true;
WinForm:
private void button1_Click(object sender, System.EventArgs e)
{
textBox.Visible = !textBox.Visible;
}
WPF:
private void button1_Click(object sender, RoutedEventArgs e)
{
if (textBox.Visibility != System.Windows.Visibility.Hidden)
textBox.Visibility = System.Windows.Visibility.Hidden;
else
textBox.Visibility = System.Windows.Visibility.Visible;
}
You can find an example here
private void button1_Click(object sender, System.EventArgs e)
{
/* If the CTRL key is pressed when the
* control is clicked, hide the control. */
if(Control.ModifierKeys == Keys.Control)
{
((Control)sender).Hide();
}
}
textbox.visible=true;
you should try this on buttonClick event

Categories