Size of Form - Windows Mobile Software Development

Hello,
i have an application, programmed in C#. I wanna that the size of the gui will automatically adapt to the size of the phone on which the application get used.
How can I do this?

In the Paint() event of the form examine its ClientSize property. This is the size of the client (White) area of the screen. It is itself a Size object with Height and Width integer properties, this.ClientSize.Width and this.ClientSize.Height
Use these values to position/resize your objects on the screen, by changing their Size and Location (Left and Top) properties, so that they fit in this area.
This event occurs before the Paint() event of the child objects, so they will be repositioned/resized before they themselves are drawn.
To be clever, reposition and resize screen objects, scaled to the screen size at run time, not values hardcoded at development time.
This technique can also detect a change of orientation, the values of Height and Width change over! If you want to be smart, handle this as well, and your app should be starting look pretty damned professional. A bit of work and it should look good on all screen sizes. Test them out against the SDK's emulator images for a range of device screen sizes.
The following code example positions the label in the correct place. Hey Diddle Diddle, slap bang in the middle!
Code:
private void Form1_Paint(object sender, PaintEventArgs e)
{
label1.Left = (this.ClientSize.Width - label1.Size.Width) / 2;
label1.Top = (this.ClientSize.Height - label1.Size.Height) / 2;
label1.Text = this.ClientSize.Width.ToString() + " x " + this.ClientSize.Height.ToString();
}

do you have to do this with every object you put on it? Seems like a lot of code. (also im doing this in VB so far..)

I'm afraid so. But it's worth the effort. Also it will run on all screen sizes, see image, and also the oddball ones they haven't thought of yet!
Change 'this.' to 'me.' and omit the C# end of line character ';' and it's now in VB.

Does your form property AutoScaleMode is set to AutoScaleMode.Dpi?
For controls set the anchor property (default is top|left) also to right (and/or bottom if needed). That will automatically 'stretch' the controls.
Advanced:
Now, if you really want to support different resolutions it will take much more work:
As already mentioned you have to rearrange the controls on orientation changes. Take a look at Developing Orientation and dpi Aware Applications for the .NET Compact Framework!
And finally you have to provide images in different resolutions.
Adapt to New Screen Orientations and Resolutions
Of course you have to decide if this is really needed for your app as this will take much more time.

Related

Registry entry for changing scroll bar size.

Can someone point me to the info regarding the registry entry for making the scroll bars thinner. I have looked every where and searched for scroll bars.. cant find it.
got it.
had to sneak over to the q forum.
here it is.
1. Making the scrollbars smaller (Vert. and Horz.)
This hack allows 4 icons on a row in the start menu instead of 3 and allows more to be viewed on the screen in IE:
• Go to: HKey_LOCAL_MACHINE\SYSTEM\GWE\
• Adjust the following values
cyHScr : Horizontal Scrollbars
Height in pixels (default is 6, set it to 3)
cxVScr : Vertical Scrollbars
Width in pixels (default is 6, set it to 3)
• Soft-reset
Its mostly nicer for web browsing.
also this asks for you to create them, they are allready created.
Bump for a good change that I felt was missing from the new roms. Thought others would appreciate it.

How to get smooth graphics (no jaggies)?

Hi
I built a simple clock app yesterday. It was surprisingly easy. One question I have though is how to make my images smooth (without jaggies). I drew my clock face and hands in photoshop. At first I did them at 300x300 pixels and the jaggies were so obnoxious I threw those images away. Then I did everything at 1000 x 1000 pixels and resized down to 300 when I was finished. This was much better, but still not as smooth as the clock in Jelly Bean. I notice that most of the graphics and fonts I see in Android are all very smooth. I've been testing the app on a Galaxy Nexus.
What is the secret to creating/displaying nice smooth images?
Thanks, Derek
vector graphic is the keyword with fix sized effects (photoshop, ie. inner shadow is always 1px, above 256px use 2px)... yeah, the simple bitmap resizing won't give pro result for you
Heh Yeah, I've had this problem and it was a ***** to solve. Mainly because the answer is distributed over a dozen different posts on half a dozen different forums.
Anyway, the answer depends mainly on if you're using imageviews/buttons or something or if you're drawing directly to a/your own canvas. But the way to solve it can be applied to both. It basically involves using BitmapFactory.Options and configuring it correctly:
Code:
private BitmapFactory.Options ops;
ops = new BitmapFactory.Options();
ops.inPurgeable = true; //means the system can recycle and reclaim the memory used by the bmp when the system has low memory
ops.inDensity = 0; //load the bitmap without scaling it to the screen density
ops.inDither = false; //don't dither (you only want dithering when you're working/converting between bitmaps/canvasses with different color depths (16bit to 8 bit etc)
ops.inScaled = false; //no scaling, related to some other settings in ops
ops.inPreferredConfig = Bitmap.Config.ARGB_8888; //load the bmp into a 32bit argb bitmap
ops.inJustDecodeBounds = false; //if true, you're just looking at the underlying bmp data, eg to see the height/width without loading the bmp into memory
//then load your bitmap like so:
Bitmap yourbitmap = BitmapFactory.decodeResource(getResources(), R.drawable.yourprettybmp, ops);
Now you can use the bitmap to draw onto all kinds of surfaces or load it into widgets.
Be warned, this is a non-mutable bitmap. If you want to change it's data (like you want to draw on it by making it the backing bmp of a canvas) you'll have to get a copy of the BMPFactory.decodeResouce bit by adding
Code:
.copy(Config.ARGB_8888, true);
to it.
For resizing the bmp, you can also do the following (which returns a mutable bmp, so you won't need the copy bit above):
Code:
yourresizedbmp = Bitmap.createScaledBitmap(yourbmp, width, height, true);
Of course, you can combine all this in one step (where "res" is a reference to getResources()):
Code:
yourresizedbmp = Bitmap.createScaledBitmap(BitmapFactory.decodeResource(res, bgIDInt, ops), width, height, true);
One more thing to ensure quick drawing, lower memory usage etc is to define the window type of your activity to match the colour depth of your bitmaps. You can do that by adding the following to the onCreate of your activity:
Code:
getWindow().setFormat(PixelFormat.RGBA_8888);
And if you're also drawing to a surface canvas in a thread, you also set that:
Code:
mSurfaceHolder.setFormat(PixelFormat.RGBA_8888);
Anyway, the most important thing is the "ops" section. Hope you get it sorted!
PS: clean, minimal graphics can often be more easily gotten by just drawing things yourself on a canvas (extend the View object and override it's onDraw()). Just use a correctly setup and antialiased Paint to draw circles, lines and text on it and use the result.
Bitmaps are not generally used for graphics. Try to use PNG images, Google does so too.
I might be wrong, but from the OP it seems like you're using the same image size for all resolutions, use the Android Dpi Calculator to easily get the right dimensions for each screen resolution (and put the resized images respectively in /res/drawable-xhdi, hdpi, mdpi, ldpi...)
If you didn't do so, then it's definitely the problem as mdpi is the default behaviour of /res/drawable, so it will be awfully resized on your xhdpi Galaxy Nexus.
dealy663 said:
Hi
I built a simple clock app yesterday. It was surprisingly easy. One question I have though is how to make my images smooth (without jaggies). I drew my clock face and hands in photoshop. At first I did them at 300x300 pixels and the jaggies were so obnoxious I threw those images away. Then I did everything at 1000 x 1000 pixels and resized down to 300 when I was finished. This was much better, but still not as smooth as the clock in Jelly Bean. I notice that most of the graphics and fonts I see in Android are all very smooth. I've been testing the app on a Galaxy Nexus.
What is the secret to creating/displaying nice smooth images?
Thanks, Derek
Click to expand...
Click to collapse
Not sure if you've fixed this already but it's really easy. No code is required to remove jaggies, regardless of resolution. Assuming you're using Photoshop, choose save for web and devices, then select PNG-24 (not jpg or PNG-8) with transparency enabled. Initial resolutions of 200x200, 300x300 etc. are all fine; there's no need to create it at 1000x1000 and scale down if you need something smaller. Your graphics will look great.
One more tip - clock widgets fill a certain number of "squares" on the home screen grid, so just make sure that you determine the right number of dp pixels to cover the size you want (e.g., 2x2 or 2x4, or 3x3) and then specify it in xml. See the Android site for widget sizing.

Hide input panels with setting configuration?

Is there a way to hide certain input panels on the window form using configuration or config file of some sort?
For example.... let's say in my database I have items with 12 possible fields in each (Name, LastName, Age, Occupation, Location.......etc).
But what is a user of application only wants to fill in 3 fields every single time (for example - LastName, Age, Location)? Leaving others in place when user doesn't needs them is an extra clutter. So how can I hide or disable those input panels based on user's preference on which fields he wants to use?
--
I think I found a way to hide items by setting Visible boolean.
Code:
this.txtName.Visible = false;
this.lblName.Visible = false;
this.txtOccupation.Visible = false;
this.lblOccupation.Visible = false;
However, how can I move up other fields between or below them? Currently hiding just creates empty spaces.
You can turn the textbox off completely by setting its enabled property to false.
You can then move other textboxes and labels over it by setting their Location.X and Location.Y properties.
You will have to keep track of where everything is on the screen, and what is enabled and what isn't.
stephj said:
You can turn the textbox off completely by setting its enabled property to false.
You can then move other textboxes and labels over it by setting their Location.X and Location.Y properties.
You will have to keep track of where everything is on the screen, and what is enabled and what isn't.
Click to expand...
Click to collapse
Thanks.
Do you know if there is an easy way to move everything up? (lets say I make first item invisible and want to move the 10 items below up) Or will I have to call everyone individually to move up?
Also.. Is there away how I can use TabIndex to call those forms?
There are others ways to accomplish what you are looking for, but no easy route to it.
They all end up as broad as long. You either spend time during the design stage, creating an array of possible tabbed forms to be used by the program later, or spend time designing the program to deal dynamically with the fields required. The latter of the two is harder to do, but it is far more elegant.
Sorry, but there is no silver bullet.

Adapt app to all screen size

Hi, I'm developing a material design calculator but I have a problem: How could I do to adapt buttons to alla screen size? For example on mi Xperia S buttons are too small! If you want screenshot or the xml code tell me it. I'm sorry for my bad english I'm only 14 XD
Hi,
You need to use the size in DP instead of PX and use max/min size attribute on your XML file
Start using dp (density independent pixels), they are designed to scale a graphic to "real-life size" for example 48dp is a little bigger than the size of our fingers and is the recommended size for buttons in order to be easily touchable.
If you need more info about density independent pixels read from Android Developer's page "Supporting Different Densities" (I'm new here and I can't post URLs, just google it).
At first you need to read "Support multiple screens" article on android developer website.
For my opinion the best way is to use wrap_content match_parent instead of pixels.
Hi,
Since you mentioned you're making a calculator app, while using "dp" for button dimensions, I also suggest you look into using "weights".
These can evenly space out your buttons in a layout.
To use weights in Android, your content must be wrapped in a LinearLayout.

Append variable width bitmaps dynamically so that resultant bitmap row is centered

I'm pretty sure what I'm trying to do is impossible with Zooper — I've experimented and searched massively — but maybe some wiz actually will know a workaround to what I'm trying to do:
I want to have a widget — which will place let's say two bitmaps side by side: they will be selected dynamically and their widths vary massively. I want the resultant “image”, consisting of the two images, centered: thus I can't put one left—aligned image next to one right—aligned, because the whole thing will not be centered.
I hoped the image field would let me specify two consecutive “” fields and I could nicely center this compound object — but it doesn't work, only displays the first image.
Is there a way to accomplish what I'm after, or is it truly impossible?
--
白い熊

Categories

Resources