I'm developing a winforms application (using .NET 3.5)
In a form I have a panel control ,and a datagridview control inside of it .
I want to have some control ( let's say for the simplicity - a label)
to appear in front of the datagridview , and I want this label to be transparent - which means : I want to see the data displayed in the gridview behind .
I just want to see the text that is in the label , but not the whole rectangle .. and behind that text - to see the data I have in the gridview.
The problem is the following : the parent control of the label is not the gridview
(since it's not a container control ) . The parent of the label , is the panel control .
So when I set the label to be transparent .. I actually get transparency to the panel , and not to the datagridview.
Check out this CodeProject article:
How to Use Transparent Images and Labels in Windows Forms
Also, you could always use GDI (System.Drawing) and just draw what you want directly onto a transparent panel?
Set the panel to also be transparent. It shouldn't cause any trouble with the panel, since you'll still have the form itself behind it.
There is one other issue to warn you about as well. Transparency in winforms controls is only simulated or faked, in that when you create the control it takes an image of the form behind the control and uses that for the background, rather than truly making it transparent. This can cause issues if that background changes or the controls moves around on the form.
Related
I just wondering about my windows Application. When i re-size windows form that time my Form controls should re-size. Can any body tell me how to do this in Vc++
Each one of your controls has an anchor property, set this property on each control to their relative position on the form then when you resize the form the controls will move and stay "Aligned"
i hope this is what you are referring to, and that this helps
I have wpf project which print label as per editor. Project has 17 different editors. This is small little drawing for my current application for current label editor.
It has several small controls like, Tool Box, Dimension Slider, Ruler, Canvas navigation bar, Label Definition bar etc... It has one more control called Label Editor, this control will vary as per different editors (17), other controls will stay as it is.
No I want to make some generic control which contains all controls except Label Editor, so each time when I create new editor I don't need to re-create all controls each time. I can use what I have for all 17.
What control should I take to do that, content control, control template, data template or user control for that. Here is small drawing what I have.
Pls share your suggestions.
Thanks
Dee
You could try loading the label editor through a Frame and create a page for each label editor.
Alternatively, you could create a custom control with a LabelEditor property that takes an object. This approach would be more difficult, though.
I'm about to lose my mind here.
Why won't the checkbox control blend with what's behind it?
The question applies to all WinForms controls, but I'm using this as an example.
A picture is worth a thousand words:
And a few more words:
What's behind the CheckBox are colored PictureBoxes and a Button.
The CheckBox's BackColor is set to Transparent. But somehow it decides that that means it should share the BackColor of the containing Form (is that its idea of the illusion of transparency?).
Is this not possible in WinForms? I could swear I did this before.
UPDATE:
I just tried this:
On that form, set the CheckBox's BackColor to Transparent, then change the BackColor of the containing Form to some other color, and the CheckBox will match that BackColor. What the.......?
This is a side effect of controls being Windows windows. A window is responsible for drawing itself, the OnPaintBackground and OnPaint methods take care of that.
This rendering model doesn't support transparency well. There is support for true transparency by using layered windows. That's implemented by the video adapter, Windows uses it hardware overlay feature. But that only works for toplevel windows, not child windows. Note the Form.Opacity and Form.TransparencyKey properties.
There's partial support for transparency through a trick. A control can fake it by asking the parent window to draw itself first inside the control window. That produces the background pixels, it can then draw on top of that. Setting the BackColor property to Color.Transparent enables this trick for controls that support this. All of the ButtonBase derived classes do. But not controls that are wrappers for native Windows controls.
"Asking the parent window" is where the flaw in this trick becomes visible in your screen shot. You are seeing the form pixels. Stacking effects don't work, it never considers any intermediary window in the Z-order, only the parent. This is fixable but very ugly, there's a KB article that show the code.
Also notable is that WPF doesn't have this restriction. Controls are not windows, they render by painting themselves on top of the parent. Layers of paint. Transparency is now trivial, just don't paint.
Bob Powell has written an excellent article about transparent controls. Check it out:
https://web.archive.org/web/20141227200000/http://bobpowell.net/transcontrols.aspx
Can you set the backcolor of the checkbox manually to the color you want? (The value in the picturebox behind it)
'Transparent' may mean something different from what you want to MS.
Also, try changing the zorder of the pictureboxes (bring to front) and see if that changes the checkbox's underlying color.
I have a Windows Forms form in C#.
It is just like a regular Windows GUI application. However I am facing problems making the different components on the form resize themselves according to the window size. I mean I do not exactly know which property of the component is to be changed.
I have a tabPage in the form. The tabPage contains a splitcontainer which has 2 panels in it.
The left panel contains a treeView and the right panel has components like radio buttons, textboxes, comboBox and buttons,etc
When I run my application and resize the window (either by dragging a corner of the window or by hitting the maximize button on top right corner) the Windows Forms form and the tabPage expand but the split container doesn't. It stays where it was. Also I want to anchor the split container so that if I shrink my window, the split cointainer still remain on top left. I am sorry I cannot put screenshots here.
Just set the Anchor property of the SplitContainer to Top, Left, Right, Bottom. Or experiment setting the Dock property to Fill.
Have you tried using a TableLayoutPanel? Windows Forms doesn't have great layout support (compared with, say, Java and WPF) but TLP works reasonably well - until you find a situation where it doesn't do what you want, and then it's a pain :)
I have an imagebrush of a soccer field as the page background and I want to be able create a line up by dragging players off the bench and positioning them on the field accordingly. I don't know what control to use for the background that allows the PlayerCard control to reside where it is dragged. Any help as to how to begin would be appreciated.
You can get the idea here.
What control to use?
I believe you want the Canvas container control. It lets you arbitrarily place child controls with a Left and Top attached property, similar to the way Windows Forms does it.