Tab Control tab will only use Wait Cursor - c#

So, I'm making a game in C#, and I've created a window to handle custom controls schemes.
On this page there is a tab Control, with three tabs: Scheme 1, Scheme 2, and Custom
Scheme 1 and 2 are perfectly fine, but on the Custom tab, whenever the mouse hovers over it, it displays the wait cursor. The controls inside the tab work perfectly fine and without lag, but it just always displays the waitcursor.
I can't change the cursor property in the Design window (it just goes back to waitCursor), and I've tried changing it in code, but it won't work.

Please check the following property in your tab control and each tab:
UseWaitCursor set to true
If UseWaitCursor = true for a parent control then it will propagate this property to all child controls. I think this is probably your issue. Please see the link below for an explanation of the property:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.usewaitcursor.aspx

Related

Pass clicks to parent views

I have a TextBlock on top of other views with low opacity, How ever this is eating the click events (as well as mouse hovering events) and does not let underneath views to recieve click events.
How do I avoid this in UWP with or without caliburn micro?
Similar problem but this is for winforms, Also I only want this effect for a single view not entire window.
I have tried PointerEntered, Tapped, Holding events to set their handled parameter to true or false but none of that worked.
I just had to set IsHitTestVisible to false :|

limiting tabbing to a custom in-window message box

I have made a custom MessageBox for my application and it launches as a UserControl. I have two buttons inside it and I would like to allow users to press Tab to switch between Buttons. However, since it's a UserControl overlaying the content, Pressing tab more than twice makes the focus go in the background on elements that aren't supposed to be tabbed at.
I can't figure out a good idea how to prevent this, I've thought of making a method that will select all elements and make their IsTabStop values to false and then restore them later, but I think that would be more of a problem then a solution.
Is there a way around this to limit tabbing only to the UserControl?
I would also appreciate advice on working with the message box.. the whole messagebox is an async function that has an infinitive loop until the answer is given. Is there another way to stop the application until one of the message box options was selected?
Crowcoder's reference has lead to correct MSDN page where I found my solution:
dialog = new UCMessageBox("Are you sure you want to exit the application?", MBType.YesNo);
AppMessageBox.Children.Add(dialog);
KeyboardNavigation.SetTabNavigation(dialog, KeyboardNavigationMode.Cycle);
The key was to call .SetTabNavigation function and direct it to my dialog (custom UserControl for the message box) and setting the KeyboardNavigationMode to Cycle.
After closing the UC rest of the application continued normally regarding navigation.

Hide Container but not Text Positioned Over It

I have a .NET 4.5 WinForm that checks for the existence of a certain file when the form loads. If the condition is met, I display the form in its entirety. If the file doesn't exist, I want to display a simple text message while hiding (setting the Visible property to false) all the other components on the form.
My issue is that the Label I want to display can only be positioned on top of a GroupBox. Well, not only but it is most aesthetically pleasing being in that location. If I set the visibility of the container to false then it hides the message as well.
Is there a way to "break out" the Label from the GroupBox?
Worst comes to worst, I will hide the indivial components within the GroupBox and live with the border that remains. I am just curious if there is a way to do this.
I found a solution using only the designer. ChrisF's answer got me thinking, and the correct method isn't to place the label behind the container, but rather to place the container on top of the label. This seems to be a quirk of the VS designer.
I created a new WinForm and added a label and a groupbox, without the two of them overlapping. Then:
Right-click the label and Send to Back, or alternatively right-click the container and Send to Front
Drag or resize the container to cover the label
And that's it... the label appears behind the container. I guess the designer correctly notes the z-index when both components have the same parent container, and placing the label on top of the groupbox changes its parent container.
To have the label on the form in the position you want, but outside the group box use the "send to back" option to push it behind the group box. It won't be visible at design time, but it will be in the right place.
Then if the file is not found you can make the group box invisible revealing the label behind.
Another alternative is to position the label outside the group box (off to the left or right and outside the form) and then move it into position at the same time as making it visible.
I know you want to benefit the capability of design support to position your label correctly right at design time, however doing so will set the groupbox as Parent of your label, you can't drag and drop that label on your form. So just try the following code to change the Parent from groupbox to the form at runtime and maintain the design location, that way changing your groupbox's visible won't affect the visible of your label:
public Form1(){
InitializeComponent();
Load += (s,e) => {
var loc = label1.PointToScreen(Point.Empty);
label1.Parent = this;
label1.Location = PointToClient(loc);
};
}

How to make Panel Visible in WinForms?

I have the following Code:
marathonPanel.Visible = false;
resultPanel.Visible = true;
but only the marathonPanel gets invisible and the resultPanel stays invisible.
When I check the value of resultPanel.Visible it is set to false.
I also tried
resultPanel.BringToFront();<br>
resultPanel.Visible = true;
Can anyone help me?
This happens when you design two overlapping panels in Visual Studio Form Designer. It is too easy to drag one panel inside the other and the dragged one becomes the child of the first.
I usually draw the panels in different locations. The first one in the expected place, the second one in a different place, then at Runtime move the second one on the same spot of the first one.
in Form_Load
resultPanel.Left = marathonPanel.Left;
resultPanel.Top = marathonPanel.Top;
This is a common designer accident, caused by Panel being a container control. Overlapping two panels is a problem. Your resultPanel will end up as a child of marathonPanel. So when you make marathonPanel invisible, the child will always be invisible as well.
Use View + (Other Windows) + Document Outline to fix the problem. Drag resultPanel and drop it on the form. Edit the Location property by hand, don't move the control with the mouse or the panel will suck it right back in.
Another way to do it is to intentionally mis-place it so it won't be sucked-up and fix the Location property in the form constructor. A more friendly hack that works better in the designer is to use a TabControl instead. Check the sample StackPanel in this answer.
There is another way to find out such issues .
if you look at *.resx file , it will tell which control is taking place as parent and which is child
Also you can view this thing in Document outline which is available in Visual Studio.

How to force a focus on a control in windows forms

I am trying to focus a "search" textbox control in my windows forms application. This textbox is inside a user control, which is inside a panel which is inside a windows form (if it is important).
I tried 3 methods which I could find:
// 1
this.ActiveControl = myTextBox;
// 2
myTextBox.Focus();
// 3
myTextBox.Select();
Neither of them seems to work. I mean for example when I try the first one, active control is really set to myTextBox, but when I try to write something on keyboard, textbox doesn't accept it and I have to first click inside the textbox to get focus. This is same with all of the methods.
Am I missing something?
Ok, finally found the answer:
As I said my textbox is inside user control which is inside panel which is inside a form.
When I need my user control I add it to panel. To get focus on my textbox I have to firstly focus my user control so something like this:
In my top Form:
panel.Controls.Add(myUserControl);
myUserControl.Focus();
and then in my user control:
myTextBox.Select();
Note that if I used: myTextBox.Focus() it wouldn't work (don't know why). Also if I used myUserControl.Select() instead of myUserControl.Focus() it wouldn't work either.
This seems to be the only combination which works.
You could do these logic steps to set your control to be the focus:
your_control.Select();
your_control.Focus();
Enjoy! :)

Categories

Resources