I'm writing an application in c# .NET 4.0. I've implemented TDI using TabControl and TabPages. On each TabPage there is a bunch of TextBoxes, ComboBoxes, Grids, Checkboxes etc. Each control has Validation and Validated event attached. Form, TabControl and each Tabpage have CausesValidation set to false. On each TabPage there are also some Panels, each has CausesValidation also set to false. Other controls (TextBoxes, CheckBoxes) have CausesValidation set to true. In this way, I'm able to switch between TabPages independently. However, when on one Tab, some control fails validation, controls on the rest of TabPages are prevent to receive focus. I've implemented onSelecting and onDeselecting events for each TabPage, so one way is to switch off CausesValidation on controls on TabPage, which is going to be hidden, and switch on CausesValidation on all controls on TabPage which is now in the front. Is there a better way to achieve this functionality?
Added:
I want validation to take place for each tab independently. Result of validation of one tab should not affect behaviour of other tabs. Changing AutoValidate property to EnableAllowFocusChange doesn't work - I still want to prevent changing focus if validation fails, but it should be limited only to this particular tab. If control is going to lost focus as a result of switching to the other tab, it should be allowed.
It is hard to provide source code, but here is a sample project that explains the problem.
http://www.speedyshare.com/T49DR/SampleProject.zip
Related
I have a windows forms application and added a menu to maneuver between few User Controls. I am using the events: Click, MouseEnter and MouseLeave.
In every event I am changing the BackgroudImage and what i want to achieve is that when the image did change after the click event, the image will stay. And I was thinking using the User Control properties to determine if he is Shown or not (as I am using the Show() and Hide() methods).
Tried using the Visible, Focused and Enabled properties but none of them changing after hiding or showing the User Control.
How can i determine if the User Control is shown or not?
The property IsHandleCreated gets true when the control is loaded. Try to use this property.
reference document :https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.control.ishandlecreated?view=netframework-4.7.2
Apparently when the form loaded, the default Visible property is set to True even though I really don’t see all of the User Controls (they are one on each other).
So I added a show and hide method in the form load event and the visible property works like a Charm.
Thank Franck
I'm using the 2013 Q3 Telerik Tab control in a C# WinForms project. If I test the .Visible property of a control placed on a Page in the Tab then it will always return false unless I Select the page. Is there another property besides .Visible that can be used to test the Visibility of a control on a Page without having to select it?
Here's my dilatation:
You should not change the native meaning of the control's properties. Period. I asked in a comment what were you trying to achieve, because I suspected that you're basing some UI logic on some control's visibility, which in my opinion isn't too good approach. The visibility should be bound to the background logic, not the oposite. You're hiding controls for some reason, because at some point something happened - so keep track of that "something" instead of inspecting its results. IMO the Visibility property should be set, but never checked.
Alternatively if it's not possible to change the concept for some reason, as a workaround I'd attach a handler to the VisibleChanged event and set Enabled property if the sender is not a tab control - then by checking against Enabled property you'd know whether the control is in use or not. I find it difficult to imagine a situation in which I'd need to check whether a control is visible.
I'm using tabControl with many tabs(>10), and each tab has UserContol. But tabs Initialize each control at starting my app. It's making my program too slow. I want to run my userControl only when I click on it. How can I do this?
You should improve your UserControls that they do not do the performance stuff until they get activated/visible. Give them a method Activate which the tabcontrol calls when the tabs becomes the selected tab.
Alternatively you could not add the UserControls to the TabPage content in the designer. Instead create your UserControl when the tab becomes active. But this will make them insivible in the Designer.
You could either have a marker such as IsLoaded and until a tab is selected, not load the controls. When the tab is then selected, if it hasn't already been loaded, you could load the controls and add them at runtime to the tabs Controls.
Or, you could have the controls added but not do anything with them until the tab is selected, and then each tab will do the calculations or whatever and update the correct controls.
It's all about your design.
Add a handler to your UserControl's Load event. Then kick off slow activity in the handler.
I create an user control that has some textbox and buttons.the problem is when I use tab to traverse in My form when my usercontrol get focus the focus go inside of user control and buttons insid if it would focus.How I can simply go to next control after my user control not inside it?
thanks
If the controls have Focusable CanHaveFocus TabStop sort of properties, set them to false.
Also set the TabIndex properties of those controls to 0. I'm sure that the controls will be ghosts in terms of getting tab focus.
Set TabStop property on your custom user control elements which you want to exclude (eg. your button) to false.
I have a windows application: a main form and several user controls on it.
Tab button doesn't work as I expected. I thought it goes through all user controls on form. But I was wrong. When user control received focus (using mouse click) it didn't want to go anyway using tab button. What thing can be wrong ? Did I miss something ?
I didn't override ProcessCmdKey and other key_down events. All user controls have TabStop property = true.
C#, .net 2.0, WinForms
you can use "Tab Order" tool in "Layout" toolbar to see the current TabIndex values. make sure TabIndex is correct (starts from 0) including tabIndex in the actual UserControl as well. quickly tried on mine and seems to work. Do u have any binding setup to these controls