Black content pane instead of tiled background - codenameone

I have a form with a tiled background which works well in the Simulator.
However on device the background of the content pane is drawn black after an instant (IOS or Android).
Apparently the form appears first correctly drawn because the initial image of the app was created by the build process.
Any ideas why the pattern icon is not painted on the device?
The code looks like:
Image imageIcon = null;
try {
imageIcon = Image.createImage("/patternicot2.png");
} catch (IOException e) {
Log.p(e.toString());
}
Style style = form.getContentPane().getAllStyles();
style.setBgImage(imageIcon);
style.setBackgroundType(Style.BACKGROUND_IMAGE_TILE_BOTH);

I'm assuming that the image is translucent in which can you must set the bgTransparency of the content pane to 0 so the form background is painted. Also make sure you didn't define the Form itself to be transparent.

Related

Specifying animations and Toolbar items in the resource editor

I'm getting the hang of using themes to change my app's look and feel, but there are still a few mysteries. Right now, in the SocialBoo theme, the button to show the overflow menu is way too small, even though it's the right size in any other theme. Also, the overflow menu pops up with a nice animation on the other themes, but not in the SocialBoo theme. Can anyone tell me how to modify the theme to fix the size of the overflow button and specify an animation for the overflow menu?
SocialBoo is a pretty old demo that still uses the old GUI builder. We are slowly migrating away to the new GUI builder which was slated for the 3.4 release but is currently still considered beta status.
The new GUI builder standardizes on Toolbar which didn't exist when we developed the old GUI builder.
The icons for overflow/side menu can be customized via theme constants specifically sideMenuImage and menuImage.
I was able to partly fix this in code like this:
Hashtable<Object, Object> newThemeProps = new Hashtable<>();
// I need to start these with #, which tells the addThemeProps() method
// that these are theme constants, not theme properties.
// (The # character gets stripped out.)
newThemeProps.put("#menuTransitionIn", "bubble");
newThemeProps.put("#menuTransitionOut", "fade");
UIManager.getInstance().addThemeProps(newThemeProps);
This gave me the animations I wanted. I still don't know how to change this in the resource file.
As for the buttons, I fixed this in the Resource Editor by opening the TitleCommand style and setting the Background Image type to [empty] in the "..." button. This didn't improve the size of the button, but it removed the too-small button image, so it looks more professional. Here's what it looks like before the fix:
This is after the fix:
(Yeah, I added another item to the menu, too.)
It retrospect, I could probably have just checked the Derive button in the Background Image tab.
I also changed the TitleCommand foreground color to white (not shown), because the black buttons were practically invisible.
Finally, I changed the FontImage Icons to white with this piece of code:
/**
* The icon created by this method gets passed to the Command constructor.
*
* #param icon The FontImage constant for the desired icon
* #return The icon as an Image.
*/
#Nullable
public static Image createClearMaterialIcon(char icon) {
materialIconStyle = UIManager.getInstance().getComponentStyle("TitleCommand");
// materialIconStyle.setBgTransparency(0, true);
if (icon == 0) {
return null;
} else {
return FontImage.createMaterial(icon, materialIconStyle);
}
}
The transparency of the style needs to be set to zero (transparent). This can be done using the setBgTransparency() call in the line that's commented out, or it can be done by setting the TitleCommand resource's transparency to 0 in the Color tab.
Thank you, Shai, for pointing me in the right direction.

how to Paint non-client area in winForms transparent? .Net 4

im developing a custom form and i want that the non-client area be transparent. im handling the non client area painting via message number "0x85" and this is what i have tried so far:
Paint using the color "Color.Transparent" -> the non-client area was painted black. If I had used an image of red or black or green, it works perfectly, but transparent = black
Created a transparent image of the size of the form and used the method "myGraphics.DrawImage("img.png")". the background remained black. If I had used an image of red or black or green, it works perfectly also...
Not paint anything (hoping that i just would stay transparent)... not worked
Getting parts of a window transparent requires hardware support, a video adapter feature called layering. Use the form's TransparencyKey property. Set it to an unusual color, like Color.Fuchsia. And draw with that color to get the video adapter to omit the pixels.

Stop/Start button binding in WP7

There's a button for playing music on the form and a media element. The button is used for play/stop the music.
Is it possible (and how) to draw an arrow or a square inside the button by clicking in XAML? It must depends on the state of the media element (if it's playing or not). If it's impossible how to do it in code behind?
P.S. In other words it the music is playing the button must displays a square, otherwise it's must be an arrow (like a triangle).
You can change the background image of the button through code.
if(mediaplays)
{
ImageSource img = new BitmapImage(new Uri("imageurl", UriKind.Relative));
ImageBrush imgb = new ImageBrush();
imgb.ImageSource = img;
btn.Background = imgb;//btn is the name of the button
}

How to make label transparent without any flickering at load time

I have a panel and on that I've a picturebox. There are around 20 labels that I've to show in the panel. I want the background of Label to be transparent ie the image in picturebox is shown and the label displays only the text.
Now since labels do not exhibit true transparency I made the labels child of picturebox
this.lbl1.Parent = pictureBox1;
This has solved my immediate problem but now when the form loads, all the labels take a while to become visible and do so one at a time. I'd appreciate if you guys can give some solution for this.
Thanks in advance
The standard cure for flicker is double-buffering. But that cannot solve this kind of flicker. It is a different kind, caused by having multiple windows overlapping each other. Each label is its own window. When the form needs to paint itself, it draws its background leaving holes for the child windows. Each child window then takes a turn drawing itself. And their child windows draw themselves next. Etcetera.
This becomes noticeable when one control takes a while to draw, no doubt your picture box. Especially when it displays a large image that needs to be resized. The holes for the child windows stay unpainted while the picture box draws. They have a white background, black when you use the form's TransparencyKey or Opacity property. This can contrast badly with the image in your picture box, that effect is perceived by the user as flicker.
One immediate cure is to not use controls so you don't pay for their window. A Label is very convenient but it is a massive waste of system resources to burn up a window just to display a string. You can simply implement the picture box' Paint event and draw the strings with TextRenderer.DrawText(). PictureBox has double-buffering turned on by default so the image as well as the text is drawn completely smoothly, no more flicker. The obvious disadvantage is that you lose the convenience of point-and-click, you have to write code.
There are other fixes possible. One of them is to prevent the picture box from leaving holes for the child windows. It will draw the entire image, the labels pop on top of them. That's still flicker but not nearly as noticeable. Add a new class to your project and paste this code:
using System;
using System.Windows.Forms;
internal class MyPictureBox : PictureBox {
protected override CreateParams CreateParams {
get {
var parms = base.CreateParams;
parms.Style &= ~0x02000000; // Turn off WS_CLIPCHILDREN
return parms;
}
}
}
Compile and drop the new picture box control from the top of the toolbox onto your form.
Yet another possible workaround is to make the form and all of its children double-buffered. This doesn't speed up the painting at all but all of the windows get rendered into a memory buffer, the result is blitted to the screen. You'll notice a delay but the window suddenly pops on the screen. This is called compositing. Winforms doesn't support this directly since it can have side-effects but it is easy to enable. Paste this code into your form class:
protected override CreateParams CreateParams {
get {
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x02000000; // Turn on WS_EX_COMPOSITED
return cp;
}
}
Supported by XP and later. Watch out for painting artifacts.
or you can ditch the labels and draw the text yourself:
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
TextRenderer.DrawText(e.Graphics, "Label1", SystemFonts.DefaultFont,
new Point(10, 10), Color.Black, Color.Empty);
}
The label does not support transparency, you must create your own unique custom control, you can see these code examples.
http://www.codeproject.com/KB/dotnet/transparent_controls_net.aspx http://www.codeproject.com/KB/vb/uLabelX.aspx
Bye

How to hide the border around child window

I have a child Window , and I am displaying it from the code behind as below:
ChildPhotoViewer PhotoViewer = new ChildPhotoViewer();
PhotoViewer.DataContext = selectedPhoto;
PhotoViewer.Title = selectedPhoto.strTitle.ToString();
PhotoViewer.Show();
But While Displaying the child window I am getting the Close Button and a Border thickness arround the Window.
I am able to hide the Close Button but is there a way to hide the thickness(Border) across the child window.
Edit:
![alt text][1]
In the Image , there is border arround image after Collpasing the Close button and making
PhotoViewer.Title = null;
PhotoViewer.HasCloseButton = false;
I want to get rid of that Rectangular Border.
Have you tried:-
PhotoViewer.BorderThickness = new Thickness(0);
Edit
Perhaps you are refering to the title block across the top of the window?
PhotoViewer.Title = null;
PhotoViewer.HasCloseButton = false;
Edit
Third attempt.
The template for ChildWindow place the content in border with a 7 pixel margin. This also has an outer border which has a White background. That is what you are seeing in the image. The only way to eliminate it is to copy the ChildWindow template and edit it.
Depends on what you mean by the Border.
If you have a look at the Documentation you can see there is a border (with a thickness of 1) around the edge of the entire window that can be altered like Anthony mentions.
However there is also the window Chrome which in the default template has a number of borders. To change the thickness of these borders you will need to create a style without the borders being present.

Resources