- Прозрачный цвет фона формы
- C# Windows Form Transparent Background Image
- 2 Answers 2
- Windows form with a transparent background that can be clicked through
- INTRODUCTION
- PROBLEM
- RESEARCH
- Form. Transparency Key Свойство
- Определение
- Значение свойства
- Примеры
- Комментарии
- Transparent images with C# WinForms
- 6 Answers 6
Прозрачный цвет фона формы
Доброго времени суток.
Столкнулся с проблемой, не могу установить прозрачный цвет фона для основного окна программы.
Прозрачный фон формы при pictureBox(png картинка без фона)
Доброе. Я делаю прогу для лабы и она состоит из 2-х форм: сплэшскрина и рабочая форма. Как.
Прозрачный цвет для формы и PictureBox
вот на днях делал игру, и всплыл такой вот вопрос: установить прозрачный цвет для формы и picture.
Как сделать цвет фона формы изменяющимся?
Как сделать цвет фона формы изменяющимся? или это невозможно?
Цвет фона формы в зависимости от положения курсора
Есть форма, допустим 300х300. Когда курсор на координатах 0 0 — форма белая. Когда на 300х300 (или.
Нет, к сожалению мне это не подходит.
Вот есть статья: http://msdn.microsoft.com/ru-ru/library/wk5b13s4
Только не могу разобрать, как это использовать?
Вложения
WpfApplication3.zip (144.4 Кб, 212 просмотров) |
Заказываю контрольные, курсовые, дипломные и любые другие студенческие работы здесь или здесь.
Сохранение настроек программы (цвет фона формы, в частности)
Создана форма. На ней одна кнопка. Она описана ниже. ColorDialog diag=new ColorDialog(); .
Как изменить цвет фона для родительской формы в Visual C#
Делал по инструкции http://support.microsoft.com/kb/319465/ru, но выдает исключение, что .
Если введенная дата–выходной, изменить цвет фона формы
В текстовом поле вводится дата. Если введённая дата–выходной (суббота, воскресенье) , то форма.
Цвет фона текстбокса
Пытаюсь изменить цвет фона TextBox пишет Элемент управления не поддерживает прозрачные цвета фона.
C# Windows Form Transparent Background Image
When I tried from with transparent background, it’s not completely transparent. I tried two code blocks for this issue. First i tried like this code:
it look like this picture;
Then i found some different codes and tried ike this;
And this looks like this picture;
You can see logo with a white border. I want to show only .png Logo completely transparent. What should i do? How can do this?
Here is my Logo image as .png;
2 Answers 2
Using a layered window can significantly improve performance and visual effects for a window that has a complex shape, animates its shape, or wishes to use alpha blending effects. The system automatically composes and repaints layered windows and the windows of underlying applications. As a result, layered windows are rendered smoothly, without the flickering typical of complex window regions. In addition, layered windows can be partially translucent, that is, alpha-blended.
Create layered window in Windows Forms
Here is some code from msdn code gallery which demonstrates creating Layered Windows in Windows Forms. It allows you to create a shaped splash screen and let you to move it by mouse.
Add PerPixelAlphaForm to the project and then it’s enough to inherit from this form and call its SelectBitmap and pass your png to the method to create a layered window.
PerPixelAlphaForm.cs
SplashScreen.cs
Note
The original answer was based on turning double buffer off and overriding OnPaintBackground and drawing the image without calling base method. The answer had a known issue; while the form was moveless it was working well but if form was moving or the window behind the form was changed the window was not updating. You can see previous code in revisions. The current edit which is completely based on an MSDN code doesn’t have any known issue.
Windows form with a transparent background that can be clicked through
INTRODUCTION
Using C# or VB.NET. I’m trying to make a form’s background transparent; this form will be overlaped to other window, it will be a top-most window, so the transparent form (and its controls) must have the ability that they must not receive focus and they must can be clicked trough, this means if for example I perform a left-click on the transparent background, then the window on background of that (in the Z-order window) is the window that must receive the click instead.
For avoiding the focus I’m overriding the CreateParams property as explained here.
For making my form transparent, I’m calling Win32 DwmExtendFrameIntoClientArea function and also using SharpDX library as explained here. But I think this really doesn’t matter with the question itself.
PROBLEM
I’ll show a demostration of what I mean using images. Here below is a image of a form (with no transparency, just to simplify understanding) overlapped to a window of a text editor program; note that my form doesn’t receive focus. Well, the problem is when I do click on the form’s background (or one of its controls) the window on background (the text editor window) still have focus but it can’t receive the click.
Here is the same image of above but with a transparent form:
RESEARCH
I’m not really sure about what to investigate, so I’m going blind trying to find something useful in a trial-and-error stage by overriding the Window procedure (WndProc) of the transparent form to test related windows messages, like WM_NCHITEST or WM_MOUSEACTIVATE message as said here:
Form. Transparency Key Свойство
Определение
Возвращает или задает цвет, представляющий прозрачные области формы. Gets or sets the color that will represent transparent areas of the form.
Значение свойства
Объект Color, представляющий цвет прозрачных областей на форме. A Color that represents the color to display transparently on the form.
Примеры
В следующем примере создается окно с прозрачной клиентской областью независимо от цвета фона формы. The following example creates a window that has a transparent client region regardless of background color of the form. В этом примере метод example определяется в классе Form. This example requires that the example method is defined within a form class.
Комментарии
Если TransparencyKey свойству присвоено значение Color , области формы, имеющие то же значение, BackColor будут отображаться прозрачно. When the TransparencyKey property is assigned a Color, the areas of the form that have the same BackColor will be displayed transparently. Любые действия мыши, например щелчок мыши, которые выполняются в прозрачных областях формы, переносятся в окна под прозрачной областью. Any mouse actions, such as the click of the mouse, that are performed on the transparent areas of the form will be transferred to the windows below the transparent area. Например, если клиентская область формы становится прозрачной, щелчок мыши в этой области отправит уведомление о событии щелчка в любое окно, расположенное под ним. For example, if the client region of a form is made transparent, clicking the mouse on that area would send the event notification of the click to any window that is below it. Если цвет, назначенный свойству, совпадает с TransparencyKey любыми элементами управления в форме, они также будут отображаться прозрачно. If the color assigned to the TransparencyKey property is the same as any controls on the form, they also will be displayed transparently. Например, если в Button форме имеется элемент управления, свойство которого имеет TransparencyKey значение SystemColors.Control , то элемент управления будет отображаться прозрачно, если только BackColor свойство Button элемента управления не будет изменено на другой цвет. For example, if you have a Button control on a form that has its TransparencyKey property set to SystemColors.Control , the control will be displayed transparently unless the BackColor property of the Button control is changed to a different color.
Это свойство не поддерживается, если RightToLeftLayout имеет значение true . This property is not supported when RightToLeftLayout is true .
Transparent images with C# WinForms
I am working on a Windows Forms application in VS 2008, and I want to display one image over the top of another, with the top image being a gif or something with transparent parts.
Basically I have a big image and I want to put a little image on top if it, so that they kinda appear as one image to the user.
I’ve been trying to use a picturebox, but this doesn’t seem to have worked, any suggestions?
6 Answers 6
I was in a similar situation a couple of days ago. You can create a transparent control to host your image.
PictureBox has 2 layers of images: BackgroundImage and Image, that you can use independently of each other including drawing and clearing.
Put the big/bottom image on a PictureBox , then add a handler to the OnPaint event and use one of the e.Graphics.DrawImage() overloads. You can load the image using Image.FromFile() .
The small/top image will have to have an alpha channel and be transparent in the background for the overlay to work. You should be able to ensure this pretty easily in Photoshop or something similar. Make sure you save in a format that supports the alpha channel, such as PNG.
The vb.net code (All credits to Leon Tayson):
A list of similar posts is referenced at the bottom of this reply.
This reply addresses pictureBoxes and Winforms (in the other posts below, several reiterate that WPF solves this well already)
- Create Winform
- Create x2 pictureBoxes
- foreground_pictureBox // picture box ‘in front’ of ‘background’
- background_pictureBox // picture box ‘behind’ the ‘foreground’
- Add the ‘paint’ event for each pictureBox
- select object in the ‘designer’
- choose the ‘properties’ tab (or right-click and choose from popup menu)
- select the events button (small lightning bolt)
- double-click in the empty field to the right of the ‘paint’ event
- Add the following code to the main form’s ‘load’ function (if not already added, use the approach in step 3 and select ‘on load’ rather than ‘paint’)
5 . In the ‘paint’ call for the ‘background_pictureBox’:
6 . Within the ‘foreground_pictureBox_Paint’ call, add in whatever graphics calls you want to be displayed in the foreground.
This topic repeats itself in several posts it seems: