How do I draw a toolbar on the titlebar of a C# winforms window in windows vista? I have a window where it works, except when the window is unminimized/unmaximized it increases in size by about 16x32px. If possible, please provide code examples.
The only way to effectively do it is to handle the WM_NCPAINT message when you override the WndProc method for the Form.
Passing to the base implementation of WndProc will cause the windows frame to be painted, but at that point, you would be responsibile for painting your toolbar elements on the title bar.
You will also want to handle all the other WM_NC* messages as well, which will allow you to process button clicks and the like (which you will need to handle events for your painted controls).
I've been looking around for the same problem, because I wanted to code a ribbon bar with that big button in the upper left corner... The only good source I found was at CodeProject on this blog and this one and another one.
Related
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.
Notes:
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:
Windows form with a transparent background that cannot be clicked through
Make a form not focusable in C#
How do I create an "unfocusable" form in C#?
You can do this by sending click (mouse up & mouse down) messages to the window underneath the transparent window using WinAPI.
PostMessageA
You'll need to find the window underneath the point you require.
WindowFromPoint
You'll have to translate the position of the click events accordingly since messages are processed based on relative window position, not absolute screen position.
I actually did this quite successfully to automatically play a facebook game many years ago.
Check the RAD designer in Visual Studio.
Is the label docked to fill?
Where is the main form clickable?
The transparent color is click-though in the main parent, however, components will still retain clicks.
Hello,
Above is the program I am writing. On the right panel is basically two custom controls (the blue rectangle area) I created and just added them as controls to the background panel control when this winform program loads.
I used MS paint to draw out the pop up balloon that I want to see when my mouse enter this control's area. I want to do the following:
1. If mouse enter the control area, the yellow area balloon pop up and populate with the information of that specific control
2. If mouse move out of the control area, the pop up balloon disappear.
Can this be done with Winform application? I looked around and found out about Tooltip class but so far from researching I don't know if it does what I want to do.
I could be wrong but googling around gave me the impress that Tooltip offers very little in term of style. Ideally I want to make this pop up balloon into almost like a border-less pop up window where I can put image , font ect.....at will. Also Tooltip works if you hover over a button or specific field whereas I want the entire control area.
Can this be done? I appreciate if you can point me to any work around if there is one.
I wrote a comment, but I figure I'll expand it into a full answer. This is assuming you want a new control, which isn't a tooltip, for maximum customizability. I did something similar to this for work recently, to act as a non-modal info popup that disappears when clicked.
Creating a Custom Popup Form
What you want is essentially a floating popup that appears over your form, which means you'll want to define a new Form object, rather than a UserControl, as it won't actually be embedded within your other form.
Give it a multiline, non-editable textbox that you can fill with the information you want to populate, then simply call a new instance of the form on your Mouse_Enter event. Close it upon Mouse_Leave.
Adjusting The Style
You'll have to play with it a bit to get it to actually act like a popup and not just a window. I'd recommend setting it to a non-modal popup, and removing the border. You can write a function to automatically size it to its contents. I don't imagine you'll want the user manually resizing it.
Some other things to look into would be overriding the CreateParams property that comes with the basic Form object. You can force DropShadows and TopMost forms without making the form modal. Overriding ShowWithoutActivation to always return true will prevent the form from stealing focus when it pops up.
I'm not sure if you can pull off rounded edges like you have in your mockup. Perhaps you can pull it off with some wizardry in the OnPaint() function, but I couldn't tell you how to do it.
It might be a bit of a pain for fiddling around with, but you can get some good functionality and appearance out of it. If you think you can pull it off acceptably with the ToolTip class, go for it. It took me about a week to get my notifications where I wanted them (though I added several features that you probably don't need to worry about).
Examples
Some keywords to look up in related searches would be Toast Notification and Non-Modal Popup. This might be some use:
http://www.codeproject.com/Articles/442983/Android-Style-Toast-Notification-for-NET
Since you already have implemented custom user controls you might want to try it again. Make a control that is that style and color, changes it's size based on it's text. You can feed it information (such as the text to display) from your existing user control object. You can also have the mouse enter/leave code reside in your first user control.
If you're not sure how to make a rectangle with round corners you can either make it on the fly using a graphics object (which will turn into a bitmap on the screen) or make it how you want it to look in GIMP (or photoshop if you have it) then use that image as the background on your user control. Make the default background transparent (so your voids above the round corners are not grey). If you make a pre loaded image you'll need to be aware you will only be able to scale it equally in Y and X directions. unequal scaling will make it look distorted.
Can you use the Mouse_Enter event on the control?
I want to fade a WPF window in, but I can't do that unless the window is set to transparent and window style is set to none, and I don't want that. Instead I want to create the illusion that the window is fading in by putting on top of it whatever is under it and then gradually reduce the opacity so it is brought into view.
I know that in order to to this another window with transparency and no borders must be used as the object that holds the captured image and performs the fade.
So in theory I know what I want, but I have no idea of how to capture as an image whatever is under a WPF window. Of course, the interface that I want to reveal will be hidden until the capture is performed, so the window on top doesn't capture the actual interface, and I will show the GUI only after the image has been captured, so it can be revealed after the image starts losing opacity.
That was just an explanation for what I need this. The basic question is: how do I capture to an image whatever is under a window (even if it requires the window to be transparent)?
Found an article here describing a couple of ways to do what I need: http://www.codeproject.com/Articles/91487/Screen-Capture-in-WPF-WinForms-Application
I'm looking for a nice way to render overlays over a native Windows form not owned by myself preferably using a library available for .NET (WinForms, GTK#, ...). Precisely, I'd like to display a few labels or text boxes at a given location on the window.
Device Context & System.Drawing: What I'm currently doing is drawing directly onto the other windows' device context, which causes flickering, as parts of the other application are redrawn in unpredictable intervals. I therefore would have to catch its WM_PAINT event using hook magic, but that's actually not as far down as I'd like to go unless there's no simpler way.
Transparent window overlay with visible child labels: another technique I tried was creating a Windows.Forms.Form with the other windows' size, using TransparencyKey to make only the children visible. This seems pretty hard to get correct, as I don't want the window to be the upper-most one but only exactly one Z-level above the foreign window. The upside would be, that I could add more behaviour to it, as I could actually handle click events, etc.
How would you implement it / deal with the problems in the two techniques described above?
Definitely go with the transparent window approach as that should be simpler to implement. Creating a transparent form is very easy. You already know how to use the TransparenyKey to get the background to not drawn. Also remove the border from the window and remove the min/max/close buttons so you do not have any chrome showing.
Create your window as owned by the window of interest and it will always be on top of the target and act like a modeless dialog. I.e. it is visible only when the owning window is visible.
Thanks for your answer, but I'm still a little confused. How exactly would you set the owner of a window to anything not owned by your own application? I guess that's not even possible when the other application is unmanaged, is it?
Edit:
I now got a little step closer. The example code is in Boo.
[DllImport("user32.dll", SetLastError: true, CharSet: CharSet.Auto)]
public def SetParent(child as IntPtr, parent as IntPtr):
pass
def createAttachedForm(parentHandle as IntPtr):
f = Form()
f.Text = "My overlay"
f.Show()
SetParent(f.Handle, parentHandle)
Application.Run(f)
Now only the TransparencyKey thing doesn't seem to work. Instead the form is completely invisible when the value is set.
Setting the owner of a form can be done with
Form.Show(IWin32Window w)
where w exposes the Handle to the parent window.
I'm creating a plugin to a software that skins the form I created. However, the button are not skin based on them and a standard gray button is shown. Asking on the software forum pointed me that .NET forms control are owner-draw and therefor my button won't redraw with the correct style instead of creating a non ownerdraw button.
All controls in the system.windows.forms namespace seem to be ownerdraw.
So how can I create a standar C++ PUSHBUTTON in .NET?
Currently codding in C# if that helps.
Thx
The controls in Windows.Forms are not owner-drawn, but rather system-drawn. This is how Windows paints them by default, be it a Button, TextBox or what else. You can override the drawing either by specifying that the control should be owner-drawn (that is: you are responsible for drawing it) - some controls support that, a couple of them even with a finer granularity (see ListView), or you can override the painting completely in OnPaint event of any Control descendant.
Your question is rather confusing - as I understand the buttons you create in your plug-in are not skinned. Obviously what you need is to tell this skinning framework to paint these buttons. There probably is or should be some component that you drop onto the plug-in form or method you call that will inject the skinning painting routines into your plug-in.
It sounds like you want to set the FlatStyle property of your button to FlatStyle.System. Windows Forms buttons are indeed, by default, owner draw at the WinAPI level, and are drawn by the framework.
Have you tried setting the FlatStyle to another value, such as Flat or Popup, just to see if that stops it being skinned?
also setting Flaststyle = Standard (as opposed to system) might solve your problem
Standard was the default and therefor wasn't reskinned. When setted to flat, I get a background color and a foreground color, but lose the round corner end the hover effect suggesting that the control is not reskinned and just color style is applyed. Flat is the only version not grey, but I lose some of button feature (hover, round corner)