Converting GUI from C# to Java - c#

I'm trying to convert a form which I currently have in C# to Java, utilising layout managers. And it's turning out to be a nightmare.
I've tried setting the sizes of the components, however no difference is present. Also, I cannot get the labels and textboxes to move closer to each other.

For all of the buttons and text fields, just put then in a Panel that has nothing but that one item in it. That will prevent the button/textfield from filling the entire space in the layout.
Other than that the only thing it seems you need to do is put a bit of a margin around the whole thing so that your items aren't right up against the edges of the window.

Try GridBagLayout instead of GridLayout.
GridLayout forces all components to be the same size.
See also javax.swing.Box, to put the label - text field pairs in one pane.

Related

How i can to change the size of a form c# without losing the structure

I made a virtual keyboard in C# Visual Studio, but I have problems when I try to change the dimensions.
This is the virtual keyboard:
and this is when I try to change the dimensions:
I lose the buttons. I found a tutorial where he uses a rectangle.
In this photo is the "main" function, and after I called this function for every button from list (I make a list with all the buttons), I lose all the buttons. Only shift/caps remain because they are special characters.
Your best bet is to anchor the buttons and enable auto size then set the AutoSize mode to grow and shrink.
If all else fails, writing a function to change the font of each button to change down in size according to the size of the form is your only option.
What the problem most likely is is that the font sizes for the individual keys is too big and when you re-scale the keyboard the font doesn't change to compensate for the scaling down in buttons.
(EDIT)
Also, next time you make a post on these forums try to keep up with the formatting and try to use more accurate descriptions of the problem as well as the properties of the buttons because all of my possible solutions are just going off a whim based on prior experience. Thanks
(EDIT EDIT)
Ok I just saw the resizeControl method, I didnt see that before, however, my previous edit still applies. Properties for the buttons would be much appreciated to help answer your question. Also, try to edit the image to instead of being an image, just use the markup language like so:
//Like this
To make it easier for us to use and help debug, if you need to know how, just add 4 spaces before your code. Again, thanks

How to initially place WPF controls on dynamic fullscreen application

Alright, so I'm trying to figure out the best way to accomplish this for my rather unique case. I have a fullscreen WPF application where controls are added to a Grid dynamically and the user is given the option to freely move/resize them. The controls can be individually moved or resized anywhere on the parent Grid but I have prevented them from overlapping via their MouseMove events. They also cannot be moved outside of their container. Since the app will be running on machines with different monitor sizes, I need to take that into consideration when making the original layout. I have an initial layout that I would like to use, but it would seem that I'm out of options:
I first tried using rows and columns just to (initially) place the controls that are added. This method places them correctly but becomes a problem when I need to move or resize the elements because the control is already assigned to a particular row and column. I could try to use this method and then remove any rows/columns after placing the controls, but I don't think that would work well.
I've also considered a Viewbox, but that's not practical in my case for fairly obvious reasons (as it merely resizes the controls to fit the screen). I'd prefer not to use this because I would only need it to standardize my initial layout. That's it. I also don't want to mess up any text that will be displayed on the window.
So yeah, this is more of a "best practice" question because any solution I can think of would not look very professional or elegant. Feel free to ask any questions if you need clarification.
Edit: As an additional note, I'd prefer to stick with a Grid as opposed to a Canvas as my container.
Edit 2: Just to be clear, I would not need the specific (inital) layout after the first launch. When the program exits, the layout (Margins, Width & Heights, etc. for each element) is saved to a file to use for the next launch.
I've developed a number of kiosk/interactive applications using WPF. If you are trying to show the element transitions (while moving), then it might be best to use a parent Canvas and bind the Canvas.Left and Canvas.Top properties. You can mimic the grid alignment, using a Canvas, if you put in place mechanisms (e.g. Manipulation/Mouse events, converters) to make sure that the Canvas attached properties adjust to the row/column offsets.
It is not uncommon at all to use the Viewbox to mitigate display differences (and your use case is not "rather unique"). You set the Viewbox to a target resolution (e.g. 1920x1080) and allow the control to fill the available space. The other alternative would be to dynamically apply a content template based on the application window size/ratio.
After looking at multiple options, I've decided to just use a calculation to (sort of) simulate the behavior of rows/columns. Because my application is fullscreen, I can take my SystemParameters.PrimaryScreenWidth and SystemParameters.PrimaryScreenHeight to orient my layout. Using a combination of universal padding (static values) and ratio-based calculations (dynamic values), I can smoothly set my initial layout.
For instance, I'm dividing the width of my monitor by 6 (rounded up to avoid decimals) and using that (minus half the control's width) as the control's Margin.Left property, centering it on a 'column' of sorts.
Honestly, my initial layout is fairly simple right now, so we'll see if this will suffice going forward. Thanks to everyone who contributed to the question, and sorry if I was unclear on what I was asking.

How to fix translated text over controls in Winforms?

I have got labels in my Windows Forms application which are placed next to controls.
When I change my language options to another language, the text needs more space now it covers my control.
Are there any ways to fix this problem?
No magic here I'm afraid. You have to try making your labels as (reasonably) wide as possible to accomodate each of your supported languages. Don't use AutoSize property here.
If labels appears on the left, have your text aligned to the right using the TextAlign property. This way they should always appear close to your control without ever overlapping them.
Also try to use containers to design your forms: TableLayoutPanel, FlowLayoutPanel. Controls that are placed in their cells, are autosized and wordwrapped correctly in most cases.

How Can I Intelligently Implement Auto-Resizing in a Visual C# Winforms App?

My application (which I am using Visual C# 2008 WinForms for) involves a lot of generated controls. Specifically: grids of buttons, arrays of labels, lists, headings, etc... all populated so that they fit their containers appreciably.
I want users to be able to resize the main form, which obviously would require me to either destroy my generated content, and remake it at the proper size OR I could index through every control, figure out what it is by name and type, and re-size each item individually. I would have to do this while/after the form resizes.
Are there any more intelligent ways of doing this? Dock and Anchor don't quite apply here because I am dealing with items that don't make up 100% of a dimension (for example, grids of buttons).
Hard do give a reasonnable answer without seing just how complex the layout in question is.
But in principle, you should use a layout container such as FlowLayoutPanel or TableLayoutPanel to do the job they were designed to do. If one does not do the job, just nest them.
Docking/anchoring is probably the answer here. You need to anchor your grid to top/bottom/left/right or dock it (same effect, but the grid will fill the parent control).
If this is done right your control(s) will re-size with the rest of the form just as if you created everything in the designer.
I believe something like this would work:
Control.Anchor = AnchorStyles.TopLeft | AnchorStyles.BottomRight;

Resolution for full screen WPF application

Following the guide here, I have created a full-screen WPF application. But I met a problem: the various size & resolution of screens. For example, I want to put several sprites on the screen as buttons; but they are located at different positions in each screen, and even different to what shown in the XAML designer.
I have searched all over without a clue got. How can I fix this problem? (to make the buttons appears the exact place (in the center), and better, help the xaml designer reflect exactly what will happens when the program is running). Any help will be appreciated.
UPDATE: I'm defining my page as a Canvas inside the Window element. Actually I like Canvas more, cause I can easily put my sprites anywhere, not like a grid.
In general, you should not use pixel values in WPF.
Instead, you should layout your content in <Grid>s with rows and columns, and it will automatically expand to fill the screen (based on the alignments and row / column definitions).
Avoid using the canvas. Also, do not rely too much on the designer to build your layout. Using Grids, Stackpanels and/or Dockpanels will give much better results (and scale when resizing your window). For example, if you use only the designer and drag-and-dropp all your elements, the designer often puts huge margins a bit randomly and this will not always scale properly if you resize your window.

Categories