I have a forms app and when it starts up I would like it to give focus to a particular text box. While I was initially developing I just whacked all the controls straight on the form and the focus command worked fine.
The app is near ready and I put some splitcontainers on the form just to hold the controls in neatly defined areas using their Dock properties. Now a completely different read only control gets focus on startup and the app seems to ignore my command that the focus should go to this one textbox. Does any one know why this might be?
You can try this :
splitContainer1.Focus();
splitContainer1.ActiveControl = textBox1;
If it doesn't works please post your focus code here.
Sorry because i didn't write a comment but i don't have the privilege yet.
Related
I am developing an application in Windows Form C#, it begins with an explanatory window, language selection and a start button when the desired language is selected, I want that when I press the start button, all the elements disappear and begin the application process, I had thought of creating a new form, but this opens a new window and I don't want that, I want everything to happen on a window. Apart from making all the previous controls invisible, is there any way to achieve this? Or maybe a way to make all the controls invisible without going one by one?
You could put multiple controls in a panel for example and hide/show entire panel.
If you dont want to do that, you could always do it in a loop
for example:
foreach ( var control in this.Controls)
{
control.Visible=false;
}
Ofcourse you could also add controls dynamically, but that might be hard for a beginner.
You could also make use of MDI forms, but that might be also not worth it.
SOLVED
Solved using user controls, user controls allow me to design the application interface in the same way as a form and I can add and remove that control from the form as many times as I want, making it possible to display numerous interfaces in a single Windows Forms window.
This solution was suggested by Jeroen van Langen in the comments of my question and it was exactly what I was looking for.
I'm converting some VB6 forms to C# and have created an utility which generates C# designer files from the VB6 source files. It's going well, but I've ran into some trouble with ordering.
I have an option button and an updown beside each other and the right side of the option button is slightly overlapping the updown. I tried resizing the option button, but no usable size seems to leave the caption visible.
I've considered changing the option button to have a transparent background, but unfortunately the solution isn't viable for all of my forms.
However, what I think would definitely work is bringing the updown to the front or sending the option button to the back, but I can't figure out how to do this from within the designer code only.
How can I bring controls to the front or send them to the back from the designer code? If anyone has a different solution for having the caption visible I'm open for suggestions. It must be done from within the designer code only, as that is what my tool generates.
The order in which controls are added to their parent determines the initial Z-order. The control added first will be in front of controls added later:
this.Controls.Add(updownButton);
this.Controls.Add(optionButton);
This may sound a little odd, but I need in a unit test to give a specific control on a Windows Forms screen that isn't actually being displayed, the focus. This is because the form is being used as an 'engine' by programmatically clicking on buttons on it and reading the results from properties. That's the given, and my job is to test that when a button is 'clicked', after the button has completed its action the focus is returned to another control.
My problem is how to set the focus on a specific control, which doesn't seem to work (eg executing form.myControl.Select() or form.myControl.Focus() ). I'm told that this is because the form isn't currently being displayed, but that's only speculation.
Can anyone tell me how to do this in a unit test environment?
I am new to windows forms and localization.I have a windows form which is containing some radio buttons and checkboxes and some buttons. this from is impleneted as a child form inside a master form. the problems i am facing now is when i install the english build controls are appearing as they are positioned while desinging. But the problem is when i install the danish build for the same app the controls are not visible in the UI. but they are available somewhere on the Winform. the reason for making this statement is when the tab+ enter keys are pressed the browse dailog which is availble in the UI is opening but could not see it.
I tried the following ways.
set the Locked property of the controls to true.
set the autosize as true
anchor all the controls to left..
please let me know if anyone have any pointers on this ..
Thanks in advance..
I am not quite sure what type of localization you guys do, so I might be not 100% right here, but it seems that Danish resx file (something.da.resx) defines incorrect Location for the missing controls. Make sure that Location and Size values are correct.
If you are using some kind of tool to localize the contents, still Location of the controls is likely the cause, but I can't tell you why it happen (version incompatibility?).
I'd like to implement a feature in my application where show a dialog to the user, and the main form (similar to how jQuery looks). My only idea is to take a screenshot of the form, place it as the background of a panel (with opacity to my liking) then pushing the panel over everything on the form. I have to believe there is a better way of doing this, any suggestions?
The Opacity property is what you need to "dim" a form. You'll need to create an overlay, my code in this thread shows how to do this.
Be careful to not make it look like your program is displaying a UAC prompt. While perhaps appropriate in browsers, the user will never have any trouble recognizing that a window overlaid by a dialog is disabled. Controls paint themselves differently to make it clear.
Why not just set the opacity to something like 50% of the parent window just before launching the modal dialog and then back to 100% when the modal dialog is dismissed? This isn't exactly what you're asking for serves the same function for the end user.
If you do want to do something like your JQuery example you would indeed have to do the screen cap/augment/set as background idea that you described.
I know this is an old thread but if still interested you can take a look at this project.
Download Project