0

I've made a little Towers of Hanoi game, but nothing what was set on my PC looks the same on a different computer, not even the fonts. Everything is so messed up, I couldn't do it better even if I wanted this to happen. To say it short the backgrounds used for controls and forms are out of place, the initial values used for size and position of both forms and controls are bloody changed, and my project just looks like a huge mess. It's true I've worked in absolute values, because usually a programming language respects the programmer's point of view, and doesn't scales and moves everything the way it wants. If I wanted my project to rescale according to screen resolution I would had used relative coordinates, and made all my forms and controls dimensions be a certain amount of the screen's width and height.

Is there a way to preserve the project just as it was initially designed, so it would look the same on any computer?

I'm using Visual Studio 2010, and Windows 7 as OS.

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
  • 2
    Whoever voted to close this as off topic because it's "not programming related" is clearly confused or didn't bother to read the question. There are a couple of reasons this question might be legitimately closed (e.g. "too broad" or "lacks sufficient information to diagnose the problem"), but definitely not the one you picked. – Cody Gray - on strike May 15 '14 at 11:10
  • if your computer or the other computer has highly customized settings like Font sizing etc that will happen. especially if they are different OS versions like W7 vs XP. it could also be partly the way you laid it out (use of anchors). – Ňɏssa Pøngjǣrdenlarp May 15 '14 at 13:29

2 Answers2

0

You don't tell us specifically which properties you've modified from the defaults, or show us a screenshot of the before and after views from which we might be able to infer which modifications you've made. But you did mention something about changing the font, so we'll go with that.

In fact, it does try to preserve your specified properties to the extent possible. But sometimes it is just not possible. For example, if you specify a font for your controls that isn't available on the other computer, then it has no choice but to fall back to a font that is available. If you have any experience with web page design, it is a very similar problem. You have to use a small subset of web-safe fonts to ensure that they will be available on all of your users' computers. That's also why web designers are so keen now on embedding fonts into pages.

Anyway, it goes without saying that if the font has to change, the layout is going to be messed up. Different fonts are different sizes, so different amounts of text are going to fit, causing some to get cut off. That is why, in general, you should avoid changing properties like Font. If you use the defaults, things are a lot more compatible. But neither web pages nor desktop applications are WYSIWYG. You need images or PDF files for that.

Then there are system settings like DPI that can really mess things up, too. Keeping the default font isn't going to help you there. You have to design your application in a smart way. You mention something about relative layouts—these are the ticket. Unfortunately, WinForms doesn't make it easy to do this. It all but forces you into specifying absolute sizes and positions based on the pixel grid, which is mostly a waste of time, as you've seen. I describe in detail how to accomplish this in WinForms in this answer. The AutoSize property will be very useful to you. Of course, you'll also need the dynamically-growing TableLayoutPanel and/or FlowLayoutPanel controls, otherwise you'll end up with automatically sized controls that overlap one another.

Pre-emptive snarky comment: you should totally drop WinForms and use WPF instead. It is new, and cool, and sexy, and all but forces you the other way into pixel-independent layouts. Of course, it also makes it really easy to create butt-ugly, downright unusable applications that look like some of the stuff Microsoft has been churning out over the past couple of years.

Community
  • 1
  • 1
Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
  • `Of course, it also makes it really easy to create butt-ugly, downright unusable applications` - such as [this one](http://www.istartedsomething.com/20091124/razorfone-conceptual-windows7-wpf-multi-touch-retail/), right? - sorry, your lack of appreciation for technology advancement and excessive appreciation for dinosaur technology deserves a downvote. BTW, vanilla WPF looks just like winforms, because it "imitates" the Windows theme, but unlike winforms, WPF actually has (any) features. – Federico Berasategui May 15 '14 at 12:06
  • @High I added that *especially* for you. I almost addressed it to you. Downvote all you want, the question was explicitly not about WPF. – Cody Gray - on strike May 15 '14 at 12:09
  • right, the question is about how to create a decent UI in .Net, which winforms is totally uncapable of ;) – Federico Berasategui May 15 '14 at 12:10
  • No, that's not right either. The question was about a specific problem the person is having with his WinForms application. And I don't know, linking me to something designed for a touch screen is not a good way to convince me that a technology is well-suited for a desktop app. To be fair, I don't like WinForms either. I use raw Win32. – Cody Gray - on strike May 15 '14 at 12:11
  • BTW, I told you this before, and you refuse to understand. WPF is about **DataBinding**, not fancy UI. It surely helps if people want to create fancy UIs, but it's main advantage over winforms is in the area of data-centric apps (such as business apps and the like). – Federico Berasategui May 15 '14 at 12:18
  • How am I having another WPF vs WinForms debate? I seriously don't have a dog in this fight. I don't use either one. I just answer WinForms questions because I know about the damn technology. – Cody Gray - on strike May 15 '14 at 12:22
  • I need to change the fonts as this little game has a story, and how the writing looks matters. Anyway maybe there's a way to generate the executable, with all its initial settings and needed resources so it would be fully independent. I don't have much experience with Visual Studio in general, and I can't say I really enjoy working with it, but this project was mandatory and I had to do it in Visual Basic, no other way around. –  May 15 '14 at 12:44
  • 1
    Off Topic: [Pretty good UI](http://dnrtv.com/player/player.aspx?ShowNum=0115) using WPF: – Chris Dunaway May 15 '14 at 14:13
  • @ChrisDunaway of course some people are convinced that they can do a UI like that in winforms, or as demonstrated in the above comments, using butterflies. I would really like to see what the finished products made by this kind of people look like. – Federico Berasategui May 15 '14 at 18:43
0

@Cody Gray thanks for your insights.

This is how the main menu looks. It's kinda self-explanatory how it should had looked, without the big white margins while the text should had been inside the labels backgrounds

Some in-game footage. And this is just one of the levels. It's so messed up I'm almost sorry I've lost a night doing some heavy work on the image editing side of the mattercom/qMBJS.png

I'm not at my own PC right now, so I've tried to rearrange all the stuff directly in Visual Studio's design window, to show how the level should had closely looked. Just imagine it without the white and black margins surrounding some controls.

The first image is how the main menu looks. It's kinda self-explanatory how it should had looked, without the big white margins while the text should had been inside the labels backgrounds

The second one is some in-game footage. And this is just one of the levels. It's so messed up I'm almost sorry I've lost a night doing some heavy work on the image editing side of the matter. I'm not at my own PC right now, so I've tried to rearrange all the stuff directly in Visual Studio's design window, to show how the level should had closely looked. Just imagine it without the white and black margins surrounding some controls.

Also I've tried to set the controls and forms parameters through code, when the form loads, trying to force it to look as it should but the result wasn't any better.

  • Do the vertical "trees" move? Why are they separate controls? Are the "cross bars" separate controls too? Why use controls for those items at all? Why not just paint the appropriate elements in the OnPaint override as necessary? Have you verified that the DPI settings and screen resolution is the same on both machines? Is this a full screen app? – Chris Dunaway May 15 '14 at 14:15
  • They are controls and they shouldn't move. I've made them controls because the game's mechanics involves a double click to select the "tree" from where a cross bar should be token (in this case the trunk goes blue in texture) and another click to select the trunk where the cross bar should go, just like in any Towers of Hanoi game. –  May 15 '14 at 14:39
  • An illegal move, will make the trunk go red in texture. Yeah the cross bars are also controls as they are the ones getting moved from one "tree" trunk to another, so I've needed something I could work with their position. Even if I switch to the same resolution it makes no difference, same story, but the screens differ in diagonal length. It's not a full screen app. –  May 15 '14 at 14:40