I have a TableLayoutPanel with a number of TextBoxes and GroupBoxes. I have set this TableLayoutPanel.Enabled = false.This Disables all the TextBoxes and Groupboxes and the Scrollbar. Is their anyway i can enable the scrollbar even if the TableLayouPanel.Enabled = false?
To achieve this automatically, you can subscribe to the EnabledChanged event of your TableLayoutPanel. You can subscribe to the event using the designer, or with the following line of code:
tableLayoutPanel.EnabledChanged += tableLayoutPanel_EnabledChanged;
Then, from the event handler, we can simply set the enabled property of the scroll bar to match the enabled property value of the TableLayoutPanel:
private void tableLayoutPanel_EnabledChanged(object sender, EventArgs e)
{
scrollbar.Enabled = tableLayoutPanel.Enabled;
}
Now, whenever the enabled state of the TableLayoutPanel changes, the scroll bar enabled state will be updated to match.
Related
I have setup a Panel that has a number of Buttons on it. These Buttons Visible Property is set to false. When I move the mouse over the Panel they became Visible and when I move the mouse out of the Panel they once again became invisible. This all works fine.
The code to do this is:
private void _Display_MouseEnter(object sender, EventArgs e)
{
foreach (Control C in _Display.Controls)
{
C.Visible = true;
}
}
private void _Display_MouseLeave(object sender, EventArgs e)
{
foreach (Control C in _Display.Controls)
{
C.Visible = false;
}
}
The problem is the Events I have set for the Buttons seem to get removed by doing this. If I don't change the Buttons visiblity the events fire as normal. I have set the events in the Designer.
Am I missing something or is this how its supposed to work and I have to resubscribe my events each time I change the Buttons visiblity?
Thanks
Danny
I did some research on that and apparently when the cursor enters one of the buttons the Panel's MouseEnter and MouseLeave events fire until the cursor leaves that button so what it does is not allowing your buttons to catch the Click event.
I think the best solution would be to get the cursor position and check if it is within your panel and then set your buttons visibility.
I use a textbox as an address bar for a WP browser application. I want to select all text when a user selects the textbox and also to modify the opacity.
I tried using GotFocus method to do that. I see that the whole text is selected for 1 second or so and then it is deselected. I also need to modify the opacity once the focus is on textbox and when the textbox loses focus. Using GotFocus method I can modify the opacity but when the focus is lost, when I set again the opacity percent nothing happens.
Can you give me a hint regarding the events that determine the text to be selected for a short period of time and for the opacity problem?
private void URLTextBox_GotFocus(object sender, RoutedEventArgs e)
{
URLTextBox.Opacity = 50;
URLTextbOX.SelectAll();
}
private void URLTextBox_LostFocus(object sender, RoutedEventArgs e)
{
URLTextBox.Opacity = 10;
}
You can try subscribing to one of the tunnelling events (PreviewGotKeyboardFocus and PreviewLostKeyboardFocus) instead of the GotFocus event.
TextBoxes and NumericUpDowns have the odd property of not allowing you to deselect them once they are selected. When my user selects a NumericUpDown and clicks else-where on the form, the NumericUpDown should be deselected.
Unfortunately, this is not the case. Currently I am just handling the MouseDown event of all other controls on the form (like the panels and actual form itself) and just calling the Focus method of a random label to remove the focus from the NumericUpDown. However, this cannot be applied to menu items or scrollbars.
There must be a better way to do this. The user may want to scroll the panel instead of the NumericUpDown and intuitively click the Panel and then use the scroll-wheel, but currently that would scroll the NumericUpDown instead, since it still has focus.
Thanks for reading.
Edit: Problem still unsolved.
Normally Panel Control is a Non-Focusable control. Therefore clicking on Panel will NOT remove focus from TextBox or NumericUpDown Countrol.
The workaround can be, place a button on panel and move it away from view for example setting its x = -100 and y = -100. Do NOT set visible = false.
Now whenever user clicks on Panel (Panel_Click event) set focus (Button.Focus()) to that button. In this way panel will be scrollable through scroll-wheel.
Enclose the numeric box within a panel of some sort and then do
panel1.MouseHover += new EventHandler(panel1_MouseHover);
private void panel1_MouseHover(object sender, EventArgs e)
{
if (numericUpDown1.Focused)
{
panel1.Focus();
}
}
I tested it and it works.!
I have a check box that is disabled that should be showing a tooltip when hovered over, but instead nothing happens. Once the checkbox is clicked on the tooltip shows momentarily then flashes on and off very fast. What could be causing this?
The tooltip should also be showing for every control involved, but shows for some and not others eventhough the tooltip is explicitly set for all controls. What could be causing this behavior?
Here is the event handler:
this.MouseHover += new EventHandler(OrderSummaryDetails_MouseHover);
void EventHandler_MouseHover(object sender, EventArgs e)
{
if (someCondition)
{
this.mFormTips.Show("Please open order form to manually modify this order", this);
}
}
I can't be positive, but if using WinForms, and you have your checkbox disabled (as in not enabled), then the checkbox will not receive events. This will cause tooltips not to show up properly.
I had the exact same problem before with a image button and what I ended up having to do was to create a gray scale of the image and swap it out when I wanted the button to be "disabled". I had to add the tooltip to the button and the image (two separate UI elements) and swap out the UI elements.
I added a MouseMove event and applied it to all the controls.
void OrderSummaryDetails_MouseMove(object sender, MouseEventArgs e)
{
Control control = GetChildAtPoint(e.Location);
if (control != null)
{
string toolTipString = mFormTips.GetToolTip(control);
this.mFormTips.ShowAlways = true;
// trigger the tooltip with no delay and some basic positioning just to give you an idea
mFormTips.Show(toolTipString, control, control.Width / 2, control.Height / 2);
}
}
I have a usercontrol that contains a FlowLayoutPanel (topdown flow) with a bunch of radiobuttons. The control exposes a CheckedChanged event that fires whenever one of the radiobuttons's check changed.
My form contains the usercontrol and a textbox. I subscribe the usercontrol's CheckedChanged event and depending on which radiobutton gets checked, I either disable the textbox or put a focus inside the textbox.
All this works fine with mouseclick when changing the radiobutton's check state. However, this will hang indefinitely when using the arrow keys. I don't understand why the difference.
The following are steps to reproduce the behavior I'm seeing:
Create a usercontrol and drop a FlowLayoutPanel control and set its FlowDirection = TopDown. Then add two radiobuttons to the FlowLayoutPanel.
Provide an event handler in the usercontrol
public event EventHandler CheckedChanged
{
add { radioButton2.CheckedChanged += value; }
remove { radioButton2.CheckedChanged -= value; }
}
Create a windows form and drop the above user control. Add a textbox and set Enabled to False. Subscribe to the usercontrol's CheckedChanged event as follows
private void userControl11_CheckedChanged(object sender, EventArgs e)
{
textBox1.Select();
}
Run. Notice that if you use the mouse to click between the radiobuttons, thing works fine; but it will crash if you use the up/down arrow keys.
public event EventHandler CheckedChanged
{
add {
radioButton2.CheckedChanged += value;
}
remove {
radioButton2.CheckedChanged -= value;
}
}
Hmm, value is uninitialized? Or am I missing something?