I have a TabbedView with multiple Panels
on each Panel I have a button for edit/save/cancel
i need to freeze all other Panels when I am editing one of them
I have an event on Edit Button and can read all Panels in TabbedView and make
dockPanel1.Enabled = false;
the problem is when they are on same panelContainer like in the image
i would like to freeze the other Tabs
with Enabled = false the Panel is disabled but the user can click on Tab, and I want to restrict him to view other panels
any suggestion is welcome
You would have to disable each control within each of the tab, this would probably be best handled on the click event of the tab.
Just spin through the tabView.controls object and set each control enabled or disabled based on whether you want them enabled or disabled.
Related
I have encountered a very odd issue with the code I am working on. I have a Table Layout Panel that contains two smaller table layout panels. One contains 6 radio buttons to handle SMEMA modes while another contains buttons to handle conveyor actions (load, rewind).
Nested within the click event handler for the conveyor buttons, I have a function that disables the buttons while motion is active (segment below). I have found that when the line calls to disable the rewind button, the CheckedChanged event for the radio buttons suddenly fires. NOTE: This is only when one of the 6 buttons are selected.
bool isIdle = state.IsIdle;
//process tab
_buttonStartupRoutine.Enabled = isIdle;
_ckbuttonPLCRun.Enabled = true;
_buttonCameraMode.Enabled = isIdle;
_checkBoxDryRun.Enabled = isIdle;
_updownJogScale.Enabled = isIdle;
_buttonConveyorLoad.Enabled = isIdle;
_buttonConveyorUnload.Enabled = isIdle;
_buttonConveyorRewind.Enabled = isIdle;
_updownConveyorWidth.Enabled = isIdle;
I have confirmed that this line is causing the CheckedChanged event to fire by moving it higher in the call stack so it is called immediately when the Rewind button is clicked. However, I can't find any link between the two besides sharing the same general table layout panel, despite being in two separate nested panels.
Has anyone ever experienced something like this?
EDIT: With more troubleshooting I have confirmed that something is trickling down into the radio buttons. I added a foreach statement above the line that says _buttonConveyorRewind.Enabled = isIdle; that disables each radio button in the table layout panel. This also re-enabled them because it comes back through the attached code once the movement of the conveyor is complete.
foreach (RadioButton button in tableLayoutPanel22.Controls)
{
button.Enabled = isIdle;
}
I also had to call the Focus event on the main panel to prevent the panel from jumping down below the panel of radio buttons. This seemed to prevent the radio buttons from changing and the SMEMA mode of the machine itself was remaining consistent as well. It would seem that a Focus event somewhere was trickling down and causing the radio buttons to change.
It turns out that an event was trickling down into either the panel or radio buttons. My solution was to disable each radio button using a foreach statement before disabling the conveyor buttons. This seemed to prevent the event from changing the buttons since they were disabled when it hit. I also had to manually call Focus() on the main panel to get the focus back up to the top of the scroll area. This would confirm that a focus event of some sort was causing the radio buttons to think they were changing. I have included the code change below.
foreach (RadioButton button in tableLayoutPanel22.Controls)
{
button.Enabled = isIdle;
}
_Panel_Main.Focus();
The title says it all: "How do I prevent TextBox or RichEditBox from losing focus after clicking on a disabled button?"
I tried setting AllowFocusOnInteraction to false, but that only works when the button is enabled. That property works well if, say, I have a button for setting text to bold or italic. The editor will not lose focus and everything works superb. But if I were to disable that button and then click on it, the editor loses focus. This causes several new issues for me. Would love some help with this. Thanks.
Also note that I have a UWP app. Not sure if it matters, though.
Okay, so I figured out the CORRECT way to fix the issue.
So the bold, italic, and underline format buttons are all within my custom toolbar. What I had to remember is that most xaml elements can be clicked on and therefore trigger a PointerPressed event so long as the element (a Grid element for example) has a background for the click to intercept. If the background is transparent the PointerPressed event will not fire.
Sooo, I made sure my toolbar had a solid background set and then I set a PointerPressed event on it. So whenever you click on the toolbar that event will fire and I simply set the e.Handled property to true;
So now because the button within the toolbar is disabled the pointer click will go to the next clickable element within the visual tree that is underneath the button that you clicked, which is my toolbar (which now has a background). When the toolbar is reached, the e.Handled event being set to true within the event handler will tell the system to do nothing further and so the RichEditBox retains its focus.
I know my writing here is very sloppy but I am sort of in a rush right now and so I will most likely come back and clean my answer up. Hope this helps someone.
wrap the disabled button in a Border or a Grid.
<Grid Tapped="DisabledButtonTapped">
<Button IsEnabled="false"/>
</Grid>
now with help of tapped method on this grid you can set focus back to your RichEditBox.
private void DisabledButtonTapped(object sender, object args)
{
MyRichEditBox.Focus(FocusState.Programmatic);.//use the x:Name of your richeditbox in place of "MyRichEditBox".
}
I need to have a toogle button in AppBar inside my WP7 app. But I see nothing except ApplicationBarIconButton.
Is it possible to have a toggle button in AppBar or make ApplicationBarIconButton to act as a toggle button?
no toggle button is not possible in the app bar. you can use application bar icon button and change the image depending upon user action
I have a Panel to play media. How can I determine if it was Right clicked? I want to bring up a ContextualMenu on the panel with (Pause, Play, Stop and Start Over)
just wire up your ContextMenu to the Panels ContextMenu property... another option is assign your handler to the MouseClick event of the Panel and check the event args for Button == MouseButtons.Right.
In visual studio on your form, add a contextmenustrip, and populate it with the values that you want. The panel has a property called contextmenustrip, all you need to do is set that to the one that you create and visual studio will do the rest for you.
I have a .NET 2.0 Windows Forms application. On this app there is a Form control with a Menu bar and a status bar. Also there's a ListView on this form.
If I add a context menu to this form, the context menu will open when the user right clicks any part of the form, including the menu bar and the status bar.
How can I prevent the context menu from opening when the click happened on the menu bar / status bar? I want it to open only when clicking the "gray area" of the form.
If the click happened above a control on this form (for example, on the ListView), how can I identify this? I'd like to know if the user right clicked above the gray area or above the ListView, so I can enable/disable some menu items based on this.
After you've placed your Statusbar at the bottom and MenuStrip at the top,
Set ContextMenuStrip on your form to None
Place a standard Panel in the middle (between MenuStrip and StatusStrip) with the Dock property set to Fill.
Set the ContextMenuStrip property on your Panel (instead of on the form).
And place the ListView and all other controls that should go into the form in the Panel
Eg
~~~~~~~~~~~~~
menustrip
~~~~~~~~~~~~~
Panel. Dock=Fill. ContextMenuStrip=yourContextMenu.
~~~~~~~~~~~~~
StatusStrip
~~~~~~~~~~~~~
I found the answer:
Point clientPos = this.PointToClient(Form.MousePosition);
Control control = this.GetChildAtPoint(clientPos);
This should give the underlying control that was clicked on the Form, or null if the click was on the gray area. So we just need to test for the type of the control on the Opening event of the context menu. If it's MenuStrip, ToolStrip or StatusStrip, do e.Cancel = true;.