 |
|
 |
Exactly what I needed, thanks!
There is one problem though, there is a problem if you want the GroupBox to start out collapsed. In this case the FullHeight property is undefined to solve this problem add;
protected override void OnSizeChanged(EventArgs e)
{
HandleResize();
}
modified yesterday.
|
|
|
|
 |
|
 |
Hi ! Very good control, simple and clean. Although, I noticed a bug when you put the CollapsibleGroupBox in AutoSize with
.AutoSizeMode=Windows.Forms.AutosizeMode.GrowAndShrink
In this case, when you collapse the GroupBox, the text and the "+/-" button totally disappears, but are still active (when you randomly click around the empty label and get the "+/-" button zone by chance, the groupbox does expand and the label and button are back).
After removing the AutoSizeMode, it works perfectly !
|
|
|
|
 |
|
 |
How come this thing still works when I comment out the event handling lines as show below ?? I'm new to .Net and a bit puzzled how event handling can function without a body for the CollapseBoxClickedEventHandler method...
Otherwise it works fine !! I'm using it in a C++ Visual 2008 project under Win7 (looks nice in classic and aero theme). I'm trying to port the control to C++ in order to link to it statically (instead of dragging around the C# dll) ... and yeah, I just discovered that you cannot compile native static libs from C#
Unnecessary (??) code commented out:
In event handling declaration:
/// <summary>Fired when the Collapse Toggle button is pressed</summary>
//public delegate void CollapseBoxClickedEventHandler(object sender);
//public event CollapseBoxClickedEventHandler CollapseBoxClickedEvent;
and later in the file:
void ToggleCollapsed()
{
IsCollapsed = !IsCollapsed;
//if (CollapseBoxClickedEvent != null)
// CollapseBoxClickedEvent(this);
}
PS: After placing a break point at CollapseBoxClickedEvent(this); I realized it never gets hit... looks like CollapseBoxClickedEvent is always null.
|
|
|
|
 |
|
 |
When calling IsCallapsed = true, in constructor <code> public TestHarness() { InitializeComponent(); this.collapsibleGroupBox4.IsCollapsed = true; } </code> the groupBox is hidden from the next first click (collapse/expand). Any help? obcstf
|
|
|
|
 |
|
 |
I see this has been discussed earlier. I like the control. Keep up the good work!! obcstf
|
|
|
|
 |
|
 |
I am trying to download the demo and source from the link at the top of the page but...
Does anyone have a valid link to these documents? Or where I can download them from?
Many thanks
Heavy givers are light complainers
|
|
|
|
 |
|
 |
Is there any way to to make the border of the GroupBox disappear or change the border color and inner border color to match the BackColor so it disappears? -- thanks B
|
|
|
|
 |
|
 |
I figured out my own question if someone wants the same effect here is the code...
This Hides the GroupBox Border through color (doesn't diasable it)
set SolidBrush to this.BackColor and use same Rectangle as Rectangle bounds
// Get windows to draw the GroupBox
Rectangle bounds = new Rectangle(ClientRectangle.X, ClientRectangle.Y + 14, ClientRectangle.Width, ClientRectangle.Height - 16);
GroupBoxRenderer.DrawGroupBox(g, bounds, GroupBoxState.Normal);
Pen pen = new Pen(BackColor);
g.FillRectangle(new SolidBrush(this.BackColor), g.FillRectangle(new SolidBrush(this.BackColor), bounds););
|
|
|
|
 |
|
 |
Replace this:
private Rectangle m_toggleRect = new Rectangle(8, 2, 11, 11);
with this:
private Rectangle m_toggleRect = new Rectangle(8, 1, 11, 11);
In DrawGroupBox(), replace this:
Rectangle bounds = new Rectangle(ClientRectangle.X, ClientRectangle.Y + 6, ClientRectangle.Width, ClientRectangle.Height - 6);
GroupBoxRenderer.DrawGroupBox(g, bounds, Enabled ? GroupBoxState.Normal : GroupBoxState.Disabled);
.
.
.
with this:
Rectangle bounds = new Rectangle(ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width, ClientRectangle.Height);
GroupBoxRenderer.DrawGroupBox(g, bounds, String.Format(" {0}", Text), this.Font, Enabled ? GroupBoxState.Normal : GroupBoxState.Disabled);
Remove everything else in DrawGroupBox().
The original code put too much space between the groupbox and the control above it and the font color should use the GroupBox font color. Also, using the GroupBoxRenderer.DrawGroupBox() to render the text eliminates the line behind the text effect.
|
|
|
|
 |
|
 |
very good. thank you. now the control is suitable for me.
|
|
|
|
 |
|
 |
Hi and thanks for sharing I learned a few things here.
I have merged your code with code from
GroupBox with an icon: the ImageGroupBox control[^]
To Produce the following result:
Collapsible GroupBox With Icon[^]
I hope that this is ok with you. I thought that since the License was COPL that the use would be acceptable. I have not taken any credit for any of the code and simply referred readers back to the two articles..
|
|
|
|
 |
|
 |
I really like the control, but I was wondering what license it has?
Thanks again!
|
|
|
|
 |
|
 |
There's a bug in Collapsible Groupbox.
After collapsing and uncollapsing, all controls inside groupbox have property Visible set to true (even if before the operation it was set to false).
|
|
|
|
 |
|
 |
To solve this problem, simply goto into IsCollapsed property and change:
public bool IsCollapsed
{
get { return m_collapsed; }
set
{
....
foreach (Control c in Controls)
c.Visible = !value;
Invalidate();
}
}
into:
public bool IsCollapsed
{
get { return m_collapsed; }
set
{
....
Invalidate(false);
}
}
Regards,
Andrea
|
|
|
|
 |
|
 |
The test program throws an exception if you run it with the "Windows Classic" theme on XP as follows:
System.InvalidOperationException: Visual Styles-related operation resulted in an error because no visual style is currently active.
Here is the code that is responsible. It doesn't check to see if a visual style is available before using a VisualStyleRenderer.
void DrawToggleButton(Graphics g)
{
VisualStyleRenderer glyphRender = null;
if (IsCollapsed)
glyphRender = new VisualStyleRenderer(VisualStyleElement.TreeView.Glyph.Closed);
else
glyphRender = new VisualStyleRenderer(VisualStyleElement.TreeView.Glyph.Opened);
glyphRender.DrawBackground(g, m_toggleRect);
}
Here is a fixed version of the function:
void DrawToggleButton(Graphics g)
{
if (Application.RenderWithVisualStyles)
{
VisualStyleRenderer glyphRender = null;
if (IsCollapsed)
glyphRender = new VisualStyleRenderer(VisualStyleElement.TreeView.Glyph.Closed);
else
glyphRender = new VisualStyleRenderer(VisualStyleElement.TreeView.Glyph.Opened);
glyphRender.DrawBackground(g, m_toggleRect);
}
else
{
if (IsCollapsed)
g.DrawImage(PlusImage, m_toggleRect);
else
g.DrawImage(MinusImage, m_toggleRect);
}
}
modified on Tuesday, June 10, 2008 11:54 AM
|
|
|
|
 |
|
 |
Nice control.
i added the following code, to have the parent controls resize on toggle.
HTH,
Sascha Kiefer
void ResizeParent()
{
int deltaHeight = this.FullHeight - m_collapsedHeight;
this.ResizeParent(this.Parent, !this.Collapsed, deltaHeight);
}
void ResizeParent(Control control, bool collapsed, int deltaHeight)
{
if (control != null)
{
this.ResizeParent(control.Parent, collapsed, deltaHeight);
foreach (Control c in control.Controls)
{
if ((c.Anchor & AnchorStyles.Bottom) != 0)
continue;
Point p = c.Location;
if (p.Y <= this.Location.Y)
continue;
if (collapsed)
p.Y -= deltaHeight;
else
p.Y += deltaHeight;
c.Location = p;
}
Size s = control.Size;
if (collapsed)
s.Height -= deltaHeight;
else
s.Height += deltaHeight;
control.Size = s;
}
}
</code>
void ToggleCollapsed()
{
<code>this.ResizeParent();</code>
this.Collapsed = !this.Collapsed;
if (this.CollapseBoxClickedEvent != null)
this.CollapseBoxClickedEvent(this);
}
|
|
|
|
 |
|
 |
I used your suggestion but have a few problems with it.
When it resizes it has a tendency to relocate components on the form to (-) values for the vertical positioning. One thing I noticed was when I had it in another groupbox - it resized the parent and the parents and changed positioning on the controls that made it unuseable.
It also has a tendency to displace some controls and place others over top of them. - If I have a GroupBox over a Tab Control say 500 pixels wide. I then place the Collapsible GroupBox to the right of the Groupbox (Even into another Collapsible Groupbox - nothing underneath. How can I keep the resize from happening when there is no need to resize parent - or the parents parent. I would rather not add a property to do this - if it could Automagically detect if it needed to resize the parent...
Any ideas ?
modified on Tuesday, June 10, 2008 3:43 PM
|
|
|
|
 |
|
 |
You need to comment ResizeParent() like this:
if (control != null)
{
//this.ResizeParent(control.Parent, collapsed, deltaHeight);
foreach (Control c in control.Controls)
{
if ((c.Anchor & AnchorStyles.Bottom) != 0)
continue;
Point p = c.Location;
|
|
|
|
 |
|
 |
Great article.
I noted that if you change the backgroud color of the form in your tests, the code to draw a line to cover the GroupBox border where the text will sit doesn't work (the line cover the text)
// Draw a line to cover the GroupBox border where the text will sit
g.DrawLine(SystemPens.Control, i_textPos, bounds.Y, i_endPos, bounds.Y);
I have only changed with
Pen pen = new Pen(BackColor);
// Draw a line to cover the GroupBox border where the text will sit
g.DrawLine(pen, i_textPos, bounds.Y, i_endPos, bounds.Y);
I think that's all...
Kind regards,
Marco
modified on Wednesday, July 30, 2008 3:20 PM
|
|
|
|
 |
|
 |
For me i could see the highlight line running through the background of the text so i changed the line to the following as a fix to paint over both the shadow and highlight of the boarder.
Brush lBrush = new SolidBrush( BackColor );
g.FillRectangle( lBrush, i_textPos, bounds.Y, i_endPos - i_textPos, 2 );
|
|
|
|
 |
|
 |
I fixed it this way
SystemPens.FromSystemColor(Parent.BackColor)
|
|
|
|
 |
|
 |
Hey, nice control.
I've got an improvement for it. By adding a class and some attributes, you can enable design-time collapsing of the group box by a mouse click on the box. It will save the size of the non-collapsed group box and all.
It will probably work only for VS 2005 .Net 2.0, haven't checked.
I can make a short article with the implemented details and post it on code project. Or, if you have the time, update the control with these improvements, if you think they actually improve it.
Quite simple. Add a reference to System.Design.dll in your project.
Then add the CollapsibleGroupBoxDesigner class:
Then, add the DesignerAttribute atttribute in front of the class itself. Also, you'll need to make the property toggleRect public.
That's probably all, if I'm not missing anything.
Now recompile the project, drop the collapsable group box control on a form in the designer, and click on the toggle box. It should toggle collapse and save it's original size in it's FullSize property.
Works for me quite nicely. Get back to me if you will update the control, please.
Good luck,
Dmitry Sadakov
|
|
|
|
 |
|
 |
I used this in the control - Nice - it lets me know what the thing will look like . I use it in conjunction with the resize parent from another poster.
I am not sure if his resize parent is an issue or if this one is the issue - as I get (-) values on the vertical positioning of some of my other components, during design time.
|
|
|
|
 |
|
 |
I have noticed something in Design time - my control changes namespaces , the system can not find it any more and requests I put Global.Indigo.CollapsibleGroupBox for the namespace - it then works until I click the designer to collapse the control, at that point it disappears.
Any hints, tips or ideas on how to fix this one ?
|
|
|
|
 |
|
 |
Anyone have an idea why localization (ie: use resource manager and reex files) changes the control to width of 503 in the Designer
|
|
|
|
 |