In Windows.Forms, I was not able to reproduce the exact same TextBox border as you see it in Vista / 7 Aero. All I get is a gray rectangle instead the slightly sunken gray / blue 3d border. I tried the following methods with no success:
VisualStyleRenderer class
TextBoxRenderer class
Control.DrawToBitmap()
P/Invoke with UxTheme and friends
Drawing RichTextBox elements instead of TextBox ones
This problem has already been discussed here but with no solution: http://social.msdn.microsoft.com/Forums/hu-HU/winforms/thread/46e66852-b52e-420d-8fe0-b717f86ecb18
It looks like there's no obvious solution for this problem.
Does anyone know how to draw the exact same border as in Aero?
It's probably not going to happen for you.
I think the VisualStyleRenderer, including the TextBoxRenderer, were more meant for the XP themes.
Even the Control.DrawToBitmap(...) function magically draws a different version from what is on the screen.
I don't have the canonical answer for this, but it's most likely a result of Microsoft moving on with WPF and leaving behind the WinForm controls with those visual themes half-baked.
The only answer to this question is to use WPF or use a 3rd party system like DevExpress (which support custom themes) if you need to "theme" all of your controls.
Related
How do you apply stroke (outline around text) to a TextBlock in XAML in a Windows 8 store app (not WPF)?
A very similar question was asked in 2008, but the suggested solution from Apply stroke to a textblock in WPF and the referenced https://msdn.microsoft.com/en-us/library/ms745816.aspx only work on Windows Presentation Foundation (WPF) applications. The effect I am looking for is the same.
Thanks for your help!
I have successfully done it with Win2D effect http://expediteapps.com/blog/textblock-with-win2d-effects/
The idea is to apply two effects that create the outline effect. You can experiment with different ways and find the best combination you need. To add Win2D you can get it by nuget and is really easy to use.
and you do not need to convert the font to any strange glyphs.
I've tried to find a way to change the layout of the background image on the ListView control.
I've searched around but haven't got any straight answer.
I can see that there is a ListView property BackgroundImageLayout which is supposed to do the job. But when i change it nothing really happens beside that the BackgroundImageLayoutChanged event is triggered.
How it is possible to change the BackgroundImageLayout on the ListView control? Is there any possible workaround to achive my goal?
PS.: I know about 3rd party controls that 'fix' this problem, but I'm looking for a solution that would do the task without any additional components.
ListView is a native Windows control. Yes, it does support a background image, the LVM_SETBKIMAGE message takes care of it. It however doesn't support the boilerplate Winforms BackgroundImage support, notable lacking is BackgroundImageLayout, the property that Winforms implements for the Control class and implements when the ControlStyles.UserPaint is turned on. It is not for native Windows controls, they paint themselves.
The guy that wrote the Winforms wrapper class for ListView did the next best thing, he added a new property to the ListView class called BackgroundImageTile. A layout option that the native Windows control does implement. Which leaves you with just the two layout options that the native control supports. Tile or don't tile.
That same guy did some pretty heroic things to make the Winforms wrapper class behave reasonably. The code is filled with hacks to work around the native control's quirks. Awesome work. His life would have been a lot easier if the Windows team guy would have the luxury to make the Winforms guy's life easier. But it doesn't work that way, ListView has been around a lot longer than Winforms. And wasn't designed that well from the getgo, Microsoft had pretty significant growing pains around that time.
Fast forward and change the rules so you don't depend on legacy code: WPF, Silverlight, WinRT.
According to the MSDN, 'ListView.BackgroundImageLayout Property':
"The API supports the .NET Framework infrastructure and is not
intended to be used directly from your code."
and
This property has no effect on the layout of the background image of the ListView control, therefore it is not shown in the designer or by IntelliSense.
Use the BackgroundImage property to set the background image. See msdn for more info:
That is unless you have something fancy you are trying to do with it?
EDIT: As per a previous thread HERE: the short answer is that you can't. =(
If you desparately want it, try creating a blank image that is the dimensions of your ListView. Add to this image YOUR image and add at it a position that is in the middle. There may be something similar in nature to this in under Bitmaps or Images.
I am using C# to make my desktop applications.
But I want to make more graphical applications that have full transparency backgrounds and different levels of transparency for picture box controls.
Basically, not cookie cutter opacity of removing a solid color.
How can I accomplish this with C#?
It is simple, just go ahead with WPF. This gived me a good start point.
This should help:
http://www.c-sharpcorner.com/UploadFile/scottlysle/XparentFormsCS10282007212944PM/XparentFormsCS.aspx
also
form2.Opacity = .x; where x is percentage of transparency
or
transparency can be directly edited in appearance property of form in case you are using VSTO
I need to write a complete diffrent looking textbox than the original winforms textbox. In fact I need a different background, how can I achieve this? I tried owner drawing with SetStyle(ControlStyles.UserPaint, true); but this caused a lot of flickers and the text was completly wrong drawn, wrong font, size etc.
Wrtiting a textbox from scratch would be overkill, I think.
This is not possible. The TextBox class is a wrapper around a native Windows control that has been around since Windows version 2. It had to run on some seriously sucky hardware, they had to break a few rules to make this work. One of which is that it draws parts of itself without using the standard Windows paint cycle. Invalidate() and OnPaint() in Winforms terms. Fixing this behavior wasn't possible due to app-compat problems. Way too much code out there that hacked the control in creative but unpredictable ways.
Accordingly, it isn't possible to intercept the drawing to prevent it from erasing parts of your background image. There is no workaround for this, creating your own is a lot of work. Consider WPF.
If you specifically need a different background on a text box, one work-around is offered here.
how to make somthing like this
Windows Forms Glass Effect, Make ImageBox transparent
I use VS 2010
If all you are looking for is the standard glass effect (which includes the blur), check out this article:
http://www.codeproject.com/KB/vista/AeroGlassForms.aspx
Basically, all you're doing is extending the window's frame (which already has the glass effect) into the client area. You have to call the DWM API that come with Windows Vista or later using a couple of P/invoke methods because this is not built into the .NET Framework.
EDIT: If you're looking for more control over the blur effect, you might look into more specifically the DwmEnableBlurBehindWindow function from the DWM API, although I have not used this myself.
Take a look at this:
http://msdn.microsoft.com/en-us/library/aa969512(VS.85).aspx
The MARGINS array is similar to margins on an HTML page. The first example on MSDN gives the margins for the glass effect 25 pixels in height on the bottom of the window.
This MS tutorial is fairly easy to understand and uses C#.