I am programming a mobile application. I need a UserControl (emulating the TabContol navigation - the customer wants the tabs at the top) with a transparent background. The control contains three buttons each with an OnClick handler.
In Googling, I've found a number of solutions for WinForms. But they seemed incompatible with Win Mobile. I used the Christian Helle blog for a transparent label used in the app, but cannot wrap my mind around modifying it for UserControls.
TIA, Gus
Yeah, it's a complex task - way more complex than it should be, but it is what it is. While I never actually finished Project Resistance, it does have code for transparent user controls
The resistor body itself is a UserControl, the background shows through the surrounding area and it even dynamically draws the color bands so that the resistor body shows through the band transparent areas.
Related
I need to rotate my custom control in Windows Form using C# without using third-party libraries.
Don't want to either rotate the text or image of control instead actually need to entirely rotate control.
From here:Is it possible to rotate a button control in WinForms?
5 up vote accepted
You can't rotate controls. That's simply not supported by the native API controls that WinForms uses.
And one might wonder why it even should be supported. What could you possibly be trying to do that you'd need to rotate a button control? It would be much easier to draw it in a different place with a different shape in the first place, rather than trying to rotate an existing control. (Do note that you can also resize and reposition a control at run-time, if that would fit your needs. Investigate the Size and Location properties.)
The only workaround is to draw the control's image to a bitmap, hide the control, and draw the bitmap onto the form in the location you want it to appear. Of course, that won't result in a control that the user can interact with. They won't be able to click an image of a button, because it's not a real button. If that's acceptable to you, you should probably be using an image in the first place, rather than a button.
It is possible if you can get control of the painting, but you have to do a lot of the work yourself. Basically it all occurs on painting. A good example demonstrating how to do it is the Dock Panel Suite for WinForms.
In the VS2005AutoHideStrip (found here), there is a GetTransformedRectangle method that uses a System.Drawing.Drawing2D.Matrix class to rotate a rectangle.
It also sets the Transform property on the Graphics class, which will apply transformations automatically when you ask for something to be painted.
I advise reviewing this code for examples, it does it to draw docked tab strips down the sides of the page as opposed to top / bottom.
Some controls like TextBox are funny in that they borrow heavily from low-level Win32 libraries in their painting / behaviour, I've no idea if it is possible to get enough control to rotate this.
It is not possible to rotate controls. This is not supported by WinForms' controls API.
As you are dealing with a custom control, try simply redrawing it to suit your purposes.
I am pretty sure you can not perform this in windows forms at least not easily. However you can perform this in WPF and then bring WPF to your windows Form if you are looking for cool designs or even special effects to your controls.
This is FAR more easily done in WPF. In Windows Form, it's a huage pain to pull off.
Hope this help
I've got a c#, .net 4, mdi Windows Forms application which configurates a product. The product is one of a kind, it always looks different but similar.
I would like to create a simple technical 2D drawing which is created and shown based on the user input. My idea is, that the user enters the product data in one mdi form and the drawing is shown in another mdi form. The drawing should be created in its own thread, so the user does not have to wait for it.
About the drawing:
It should contain lines and rectangles with different colors, filled and unfilled. Some lines/rectangles have text information next to it, f.e. to show the dimensions or a name.
I am not sure which way i should go to create the drawing. My first ideas were to use Microsoft Visio Drawing Control or just to draw on a Form. But i am not sure if thats really the way to go.
I am grateful for any suggestions. Are there any other good libraries for simple 2D technical drawings? Is Visio or Windows.Drawing the way to go? Any other ideas?
/edit: example drawing:
/edit2: it would be useful, to highlight shapes programmatically. Also useful would be a shape mouse over event.
I used WPF as suggested and host it in ElementHost. It works pretty good, polygons have mouseover events, so you can highlight/select them and show detailed information about a linked object.
There are lot of tutorials to get started with drawing polygons and stuff. A bit more tricky was to implement zoom and drag features. Therefore i found this example which i can highly recommend: WPF simple zoom and drag support in a ScrollViewer
I'm using the WindowsFormsHost to add a Windows Forms control in my WPF application, but I realise that WinForms controls cannot have transparent backgrounds without setting the style as in here How to: Give Your Control a Transparent Background. How would this be done in WPF?
BTW, I'm using C# and .net 4.0.
Thanks.
I don't think you can do this. The link you provided is really about being able to set the BackColor to Transparent. When that happens the WinForms control (in its paint background handling) gets the Parent Control and calls its PaintBackground and Paint methods. While your control will have a parent - the control that the WindowsFormsHost will create - that control will not and so there will be nothing to draw the background. In a Win32 world one might set the WS_EX_TRANSPARENT bit but that introduces all sorts of issues and I suspect it may not even work based on how WPF works. I would check out the MSDN topics (e.g. Technology Regions Overview and WindowsFormsHost interop) discussing the various air space issues with interop between WPF and other technologies.
suppose i have label and button on textbox and i want that if i resize my win form then my label and button size and position will change. i got the solution in wpf but i am working with win form apps. here i am giving the url from where you can see what kind of output i am looking form. the url is http://i.stack.imgur.com/QeoVK.png. please see the image and tell me how can i implement the same output in win form apps. please help me with code snippet in c#.thanks.
You should make yourself familiar with the Anchor and Dock properties of the controls. They are great tools for this kind of work.
Note though that they will alter the size of the controls only, they will not affect font size.
consider that window forms and WPF are very different, especially about the UI management and controls nesting / UI composition.
I have seen some articles describing what you are trying to do now in windows forms, long ego, it's something called control scaling if I recall well.
Use Anchor and Dock properties for simple stuff and SizeChanged event for more complicated stuff. UI positioning API is much more limited than WPF and you will probably have to do stuff like scaling manually.
May be i can get some negative points on this question but, really this question is boggling in my mind from last many days that what is the basic/raw code behind textbox(or other such controls).
i mean i understands that, we can inherit the textbox class and make our changes, we creates its object and use it.
but wants to know how that class creates a textbox(the design which allow us to enter text) (same query for other components), is it a code of 'C' language which are generating it using CG (computer graphics) programming or any other thing.
Experts please resolve my curiosity.
Thanks
Windows provides several basic API's for drawing on the screen. You can draw pixels, lines, boxes and more complex geometric shapes. There are also API's to draw text. Other API's allow you to react to user input, e.g. mouse movement and clicks and keyboard input.
From these basic API's you can create your own text box by drawing the exact pixels of how the text box should look and react to user input. However, Windows has a built-in concept of a text box. This text box has a standard look and feel and is also integrated with UI concepts like focus, tab order, the clipboard and the caret. But behind the scenes Windows is using the low level API functions to draw on the screen and react to user input.
When you create a TextBox in Windows Forms it actually creates and wraps a standard Windows Edit control. This control is drawn using GDI. However, other programming models like WPF may create TextBox controls that looks like a normal text box but uses a custom implementation supplied by WPF and is drawn using DirectX.
Use http://www.red-gate.com/products/reflector/ and see for yourself...
Here is what I think it is doing:
The Raw code behind TextBox or any other Control uses Windows API that is responsible for drawing these controls and provide Handles of these controls for later reference.
Windows has been using different methods to draw it's UI like GDI, GDI+ and sometimes DirectX. I may be wrong and there may be some other techs I forgot to mention.
These controls use each window's WinProc to receive Input Notification and other callbacks that notify these controls when clicked, typed or for example resized.