Keep Label on top of TabControl .NET - c#

I have a label that I need to stay on top of my TabControl as I switch from tab to tab. I have tried calling the Label's BrintToFront method in the SelectedIndexChanged Event of the Tab Control but this has no effect. I also simply tried right clicking my label in design view and selecting "Bring to Front" but again, this had no effect.
When I switch to my second tab it drops behind the TabControl however, when I go back to my first tab it is in front again.
I placed the label itself on the Form rather than on the TabControl.
I am working in C#. Any ideas would be greatly appreciated. Thanks.

You should make sure that your label is not located inside a specific tab. To verify this you need to look at the nesting inside the 'document outline' (ctl+alt+T)
If it is I recommend;
dragging it just outside the tab control (you can also use the document outline).
then 'bring it to the front'.
and then use the arrow keys, or location property, to move it back into position.

Related

Make a ToolStrip Button staying highlighted when clicked in C#

I have a simple ToolStrip with buttons in it which contain images and text. When I go over that button it changes appearance (same when it gets clicked). How can I customize this so that it stays highlighted when clicked? I have to do this over a tabControl so that it stays highlighted when the tab is entered and gets back to its normal appearance when leaving the tab. Which methods do I have to override?
Thank you!
just set ToolStripButton.CheckOnClick property to true from design time. So it will stay highlited when clicked.
About the other requirement set ToolStripButton.Checked to true on entring the tab control, and set it to false on leaving the tab control.
For entering and leaving you may use Control.Leave & Control.Enter events of tabpage/tabcontrol.
Let me know incase of any issues

Tab index with tabControl

I have a tabControl control with multiple tabs. For each tab, I am adding tab index arranging the controls from top to bottom.
However, when I click tab during the program the order that the program moves from control to control isn't the order I specified.
Does this have something to do with the tabControl?
I am using the "tabIndex" property for each control.
Edit: Sorry I didn't know about this function, here is what it shows:
http://s7.postimage.org/m9burkbx5/Tab_Order.jpg
The red arrow is the flow the tab makes.
With TabOrder tool active, first click on each container controls (eg. the groupboxes) then, if the controls order inside the groupboxes, is not correct, click on each control in the order you desire them.
You will see the number change accordingly to your clicks. Sometimes happens to click in the wrong order, in this case close the TabOrder tool and reopen to restart again.

DataGridView cannot be Focused, but one of them can

I've come across the strangest bug pertaining to DataGridViews in Windows Forms.
I have a TabControl, that is supposed to contain a docked DataGridView in each tab page. I thought it would be convenient that the grid is focused upon changing the tab page, so that the user could simply hover the mouse over the grid and start scrolling when he changes the page. So, I just put a grids[tabs.SelectedIndex].Focus() in the event handler for changing the tab page.
However, something really strange happened. In my test application, I have three tab pages. If I try scrolling the grid right after starting the application, it doesn't work; I have to click in the grid first. I was expecting this. However, if I change the tab page, I can't scroll in any of the other grids until I click, except for the first one!
So, if I switch pages to the second page, then back to the first, I can automatically scroll that grid without clicking, but if I then switch to the third, I have to click for the grid to focus.
I had a look at the CanFocus properties of the grids, and it seems that only the first grid has it set to True. They are all created programmatically, and all in the same way. I don't see why they would be different.
Any ideas?
Inactive tab pages have their Visible property set to false. The documentation for CanFocus says:
In order for a control to receive
input focus, the control must have a
handle assigned to it, and the Visible
and Enabled properties must both be
set to true for both the control and
all its parent controls
Well, I solved it. Stupid programming error on my part, I had grids[tabs.TabIndex].Focus() instead of grids[tabs.SelectedIndex].Focus().
Oh well.

How to Set Up Winform Textbox Field Focus so a User Can Go Through Them by Clicking Tab Button?

UI is created in VS 2008. I'm using C# .... I need to let the user move/focus between text fields from top to bottom by clicking tab button. How can i do it?
On the Layout toolbar (will normally show up if you're in Design View) click on the buttom on the most right (it's called tab order).
Now on every element on your designer will come up a little box with a number. Just click all your elements in the order you like and they will automatically be re-ordered.
If you like to do it manually, just take ho1 advice and change the property manually.
You just set up the TabIndex property properly, so that it's sequential from top to bottom. Then it'll work automatically and you won't need any code to move around the focus.
So in other words, set the top TextBox TabIndex to 1, the next one you set to 2 etc and then one at the bottom will have the highest number (of the textboxes, you probably want to have even higher indexes for any OK buttons and similar so that the user can jump to them after editing all the textboxes).
You can find more info about it here:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.tabindex.aspx

ContextMenuStrip Behavior Problem

I am adding a label to a form dynamically, then dynamically adding a ContextMenuStrip control. Whether I use the label.ContextMenuStrip property to connect them, or add the event handler to the label manually to have it respond to the right-click and show the context menu, I get odd behavior:
1) The menu does not appear next to the mouse pointer, it is offset down and to the right. It appears that it is related to the position of the label in it's parent control (a picture control), rather than the form.
2) The menu does not disappear when I click on something other than the menu.
Any ideas what I am missing here?
Thanks,
Andy
I worked it out. First off, I was adding the control to the label control collection, changing it to the the form collection corrected the positioning problem. I never did figure out why the menu would not close.
Ultimately I restructured things by adding a static instance of the menu to the form, then just connected the label.ContextMenuStrip property to that stastic instance. All is well with that approach.
I used the tag of the label control to identify it to the click event handler.

Categories

Resources