TextBox shown in the wrong place after a scroll down - c#

i have a from c# and i want to show text Box after a click in a check box.
but when i scroll down, and check , the text Box is shown in the wrong place !!!
the text Boxes must be in the same level with check Boxes.
private void checkBox1_Checkedchanged(object sender, EventArgs e)
{
textBox1.Visible = true;
}
and changing the Location of the text Box don't give good results !
thanks for help.

You are running into an awkward quirk of the Panel control, it only scrolls controls that are visible. When you make it visible in your code, it will have the wrong Location property if you've used the scrollbar. You will need to make the correction yourself. Make it look like this:
private void checkBox1_Checkedchanged(object sender, EventArgs e)
{
if (!textBox1.Visible) {
textBox1.Location = new Point(textBox1.Left + panel1.AutoScrollPosition.X,
textBox1.Top + panel1.AutoScrollPosition.Y);
textBox1.Visible = true;
}
}
A better alternative is to use the Enabled property instead, also much less disorienting for the user. Set it to False in the designer and then:
private void checkBox1_Checkedchanged(object sender, EventArgs e)
{
textBox1.Enabled = true;
}

Related

Click Event not fired in User Control when multiple instances are created

I've a user control with 2 labels and two textboxes. When the label is clicked the textbox's visible prop is set to true. Here's the code I've used:
private void label_Heading_Click(object sender, EventArgs e)
{
label_Heading.Visible = false;
textBox_Heading.Text = label_Heading.Text;
textBox_Heading.Visible = true;
textBox_Heading.Focus();
}
After the textbox lose focus, it's visible prop is set to false and the label is updated with the text. Code:
private void textBox_Heading_Leave(object sender, EventArgs e)
{
textBox_Heading.Visible = false;
if(textBox_Heading.Text != "")
label_Heading.Text = textBox_Heading.Text;
label_Heading.Visible = true;
}
The code to create user controls on click:
private void label1_Click(object sender, EventArgs e)
{
TaskCard _taskCard = new TaskCard(++TOTAL_ITEM_COUNT, PanelName);
panel_DeletedItem.Controls.Add(_taskCard);
panel_DeletedItem.Refresh();
}
These code work fine when a single user control of this type is added to a panel. But if I add more than one, the code works only for the first user control, but it wont work for the new ones, although the event is fired for every user control. What am I missing here? Please suggest.
If I add a mbox to this code, the mbox is displayed for any control, but the rest of the code won't work, except for the first one.
private void label_Heading_Click(object sender, EventArgs e)
{
MessageBox.Show("Test"); // this will display, but the rest of the code is not executed or changes are not visible, i.e., the teboxes are not displayed even if I click the labels
label_Heading.Visible = false;
textBox_Heading.Text = label_Heading.Text;
textBox_Heading.Visible = true;
textBox_Heading.Focus();
}

C# TextChanged event doesn't happend right away

I'm building a WinFormApplication which allow the user to drag a document into a richTextBox which is loading the files content to the richTextBox. However the TextChange-event doesn't seem to happend emedietly after the text is changed, why could this be?
private void richTextBox_DragDrop(object sender, DragEventArgs e)
{
....
....
richTextBox.Text = content;
hasBeenEdited = false;
}
private void Form1_TextChanged(object sender, EventArgs e)
{
....
hasBeenEdited = true;
}
In the code above I have one DragDrop-event, the content of a file replaces the current richTextBox text. However the has been edited flag first get set to false, then true. I was hoping the flag would be set to true then false. How can I fix this?
Thanks!

C# richBox1 text disable

I have problem with richBox1 text disabling.
I've tryed richTextBox1.readonly = true; and richTextBox1.Enabled = false;
My code:
private void richTextBox1_TextChanged(object sender, EventArgs e)
{
richTextBox1.ReadOnly = !richTextBox1.ReadOnly;
}
Its disabling after one letter.
EDIT: And if disable I can still copy text but cant write there.
Honestly, disabling expected functionality is not something you should be doing. It is not good UI design.
The event TextChanged is fired every time the text changes (including writing or removing one letter). You can use Form's Load event (by double clicking the form on design time) :
private void Form1_Load(object sender, EventArgs e)
{
richTextBox1.ReadOnly = true;
richTextBox1.Enabled = false;
}

How can I manage overlapping DropDownBox drawers?

Most of my dropdown boxes use the SuggestAppend property, meaning when you start typing in the box, it will make a shortlist of the items that match your case. However, if I do this after opening the drawer, this happens:
I have tried using this method, but it closes both instead of just one:
private void cmbLoc_TextChanged(object sender, EventArgs e)
{
if (cmbLoc.Text != "")
{
cmbLoc.DroppedDown = false;
}
}
I am trying to have it so that when I type something into the text box, the original dropdown will disappear, and the SuggestAppend draw will appear. How can I manage this?
It worked if I used KeyDown. Try and tell if that helps
private void cmbLoc_KeyDown(object sender, KeyEventArgs e)
{
var comboBox = (ComboBox)sender;
comboBox.DroppedDown = false;
}

Change tooltip control

I have a series of textboxes with which I want to associate a tooltip with. This tooltip would appear when the user clicks on a black textbox, then disappear when they start typing or when they leave the textbox. The tooltip should be placed directly above the textbox, this is why I'm using the ToolTip.Show method instead of the ToolTip.SetTooltip method (it lets me control the placement).
So far, for each textbox I have 3 methods; Enter, Leave and TextChanged:
tt = new ToolTip();
String message = "some message"; //different for each textbox
private void textbox1_Enter(object sender, EventArgs e)
{
if (textbox1.Text == String.Empty)
{
tt.Show(message, textbox1, new Point(0, -2 * textbox1.Height));
}
}
private void textbox1_Leave(object sender, EventArgs e)
{
tt.Hide(textbox1);
}
private void textbox1_TextChanged(object sender, EventArgs e)
{
tt.Hide(textbox1);
}
Now consider two textboxes. Clicking on textbox1 triggers the tooltip as expected, in the expected location, then exiting textbox1 causes it to disappear. Trying the same thing on textbox2 also works. Now if I click on textbox1 again, the tooltip has the proper message, but the placement is in the same place as if I had clicked on textbox2. Not only that, but the shape of the tooltip is the same as for textbox2, meaning that my message gets truncated. (The message for textbox1 is longer than the one for textbox2). Does anyone know what might be causing this?
This only happens I think when the IsBalloon property is true. Unfortunately, known bug.
Try it like this:
private void textbox1_Enter(object sender, EventArgs e) {
if (textbox1.Text == String.Empty) {
tt.Show(string.Empty, textbox1, 0);
tt.Show(message, textbox1, new Point(0, -2 * textbox1.Height));
}
}

Categories