I'm very new to C# and I've run into a problem and haven't been able to solve it. I have a row of buttons that have .png images assigned to them. The images are in .png format to allow transparency, and smoothing the edges in GIMP leaves some semi-transparent pixels. I've set the Image List Toolbar (imglToolbar)'s properties to recognize "Transparent" as the designated color to show up as transparent. I'm working in Visual Studio 2005.
The strange thing is that everything looks great when I'm viewing the Visual C# form preview window. The icons look exactly as they should. However, once I actually build the project, the buttons treat every semi-transparent pixel near the edge of the image as if it's black. It seems like it can't handle one that's both transparent and has color.
Image of it via the Visual C# form editor:
alt text http://img5.imageshack.us/img5/2577/whatiwanted.jpg
Image of what it looks like when built:
alt text http://img690.imageshack.us/img690/7241/whatigot.jpg
Any ideas as to why this is happening?
I just found the answer, at least to my specific situation.
The form I'm dealing with is a top-level MDI container. For whatever reason, having the icons set to 32 bit color doesn't allow for these semi-transparent pixels to be properly interpreted. Setting it to 24-bit, on a whim, completely solved the problem. Not sure if this is some situation that has come up as a result of some unseen factor, but the color depth change fixed my problem.
Also for those who may come here with a similar problem, make sure the window isn't a child of an MDI container. While looking for information, I found MDI children don't support TransparencyKeys at all.
I ran into this problem as well; changing the form's IsMdiContainer property to false solved it.
Related
I have a problem with the opacity of some controls.
So I set the form opacity to 0.3, when the form is loaded, and the problem is that it makes the other controls as tranparent as the form. Here is the code.
private void Form1_Load(object sender, EventArgs e)
{
this.Opacity = 0.3;
}
By doing this, all my controls are as transparent as the form. Is there any way to have different opacity for the controls inside the form ? I don't want the other to be transparent at all.
My first recommandation would be to avoid that. Having a semi-transparent background with opaque controls will look somewhat weird. Instead, consider changing the opacity when the form is active say from 0.3 to 0.7 so that it is easier to read.
Also another problem if some controls are opaque and the background is almost transparent, then your UI might not work well on some background. For example, if the background is really dark, then dark text (control) will be hard to see. If the background is white, then white controls like edit box would be the same color as the background.
You can get a few idea from other people comments. Even though some comment are for WPF, you might be able to take some idea for WinForms. And if you don't get the expected result, you might also consider using WPF for that part of the UI.
Having said that, a possible workaround to get what you want is to create two top-level windows at the same position (and move/resize them as appropriate). That way, you can have one window with a transparency key and the desired background for opaque area that will be used to have opaque and semi-transparent area. The other window will use the opacity so that it would be semi-transparent. This is the window that will contain your UI controls (and the one that would be on the top).
I have used that technic in the past to have a semi-transparent client area with a fully opaque frame in one application where I want to be able to see through client area (adjustable opacity) so that I could "draw" in my window using the image in another application as a reference.
Another comment is that you might need actual control with windows handle and direct Win32 API access for some customization that are not available in WinForms and/or WPF. In my application, I was handling activation in a way that if I click on the bottom level windows, the top-level window still appears as the active one (caption bar color). If one has no standard caption bar (either the frame is custom or no frame at all), then you would not have that problem.
As suggested by some links in the comment section, it might also be possible to get what you want using a single top-level windows. I have not tried that. In fact, when I try the above solution, I think that my application was still supported on Windows XP and as such you are more limited in options and the behavior is somewhat different essentially because XP more or less write directly to screen while Vista and later use bitmaps (buffers) for each windows.
I have also used combined transparency key and opacity for splash screen (on a single window) and it works on most system but sometime I got black background instead of desired background on some system (probably some XP machine with specific configuration).
Background
I want to drag "icons" from the desktop on to my form, they will then be visualised on the form, not changing in appearance.
When i say "icon", i mean shortcuts, folders and application icons.
Example
Question
What is the best way of recreating the icons on the form. Is there a tried and tested way, or do you have to recreated them using picture
boxes and labels?
What I've Tried so Far?
Picture boxes
Forms
I've had limited success with both, with the latter being the best so far. However both have their limitations.
Notes.
I do not need help with other areas of my problem like, how to drag icons, extracting icons, etc. It's purely just recreating the icon visually i'm struggling with.
Use a ListView and set the view property to LargeIcon.
You can obtain the icons through: Icon.ExtractAssociatedIcon. However, you may need to manage the icons as two files with the same extension may have different icons.
If you only want the image, then you can grab just the icon portion of the control after it's painted.
I'm trying to make, essentially, a screen capture program, that captures the pixel values under the current window. (I'm working in C#, in Visual Studio 2015.) However, for various reasons, the window itself needs to be opaque (for filters and such). How can I best achieve this?
It is possible to find the window below yours and get a screenshot of it even if it is hidden with the method: PrintWindow (see PInvoke.net as well)
See Copying content from a hidden or clipped window in XP?
It is very simple to do in Winforms. Just set the form's Opacity value to 99%. Now Graphics.CopyFromScreen() will not see your window anymore.
Except when the window underneath yours is also a layered window, then it also won't be visible to CopyFromScreen() for the same reason. Then you have to set Opacity to 0, copy and set it back to 0.99. Very quick, probably good enough for what you want to do.
So I've been coding a program for a little over a month now, and I've encountered a problem that I have no idea how to tackle. For a while now, I've always been confused when I opened up my program on other computer, and my window size was different. I chalked it up to a different resolution, and figured the problem would be easy to solve later. Then I imported a custom font to my program, and was confused when I noticed the letters where not clear and where blurry. I figured that this was something caused by my specified font size that I was using, and left it as is. Today however, as I was doing some testing I was annoyed by the blurry text enough to go and search online for the problem and solution, only to find out my problem lay within my DPI settings (125% on the computer I had mostly programmed on.)
I have no idea what I can do about this. I started programming a little while ago, and it was hard enough figuring out how to get the custom text working, but I just have no idea where to take this.
I've been coding this program in Visual Studio C# 2010 since it's the only version I've got that won't expire, so I can't use anything that might be in the 2011 or 2012 version.
All I want is for objects to be on the same place on one computer as another with a different DPI. Is there a very simple step-by-step tutorial somewhere that I can read or watch to figure this out?
This code snipshet worked perfectly for me.
http://urenjoy.blogspot.it/2008/11/make-resolution-independent-windows-app.html
(Using Visual Studio Express 2013)
It is required that windows app should have same layout at different resolutions means there should be no effect on layout of app on changing resolution. Here are the steps to do this.
Use table layout panel
Drag control in cell of tablelayoutpanel and set anchor and dock property.
Set rowspan and colspan properties of dragged control to merge cells
Set margin and padding of dragged control with respect to cell.
drag all controls and follow same steps, complete design using tablelayoutpanel
Now set all columns and rows size of tablelayoutpanel = autosize (or in %)
Set tablelayoutpanel properties autosize = true,autosizemode = grow and shrink
Set Forms properties autosize = true,autosizemode = grow and shrink
Run windows app If your windows app opens in maximum state then set tablelayoutpanel dock property =fill.
Let me explain put it in just a few simplest lines.
I made a new C#/WPF application project in VS 2013 ultimate (x64).
On MainWindow I insert (for example) a button at bottom-right, actually anywhere..
See image below, but the position of the buttons at runtime does not match what it looks like when I am designing
As you can see from the marked up spots in the 2 images, the controls are mispositioned.
I tried to change some XAML attributes, setting min/max sizes, and so on and on. I am running a fresh-install Windows 7 Ultimate (x64) OS, with "Windows 7" aero theme.
I played around MainWindow/Grid properties (tried almost every one), also when I loaded up some custom theme (for example: Expression Dark) issue persists.
Don't get excited so much. Have some control on your temper.
It seems that you have not set the Right Margin of the button you have circled Red in the above image. Try to set the appropriate margins from the Property Window of the corresponding button and see what happens!