all groups > dotnet windows forms designtime > july 2005 >
You're in the

dotnet windows forms designtime

group:

Container control in designtime


Container control in designtime Monarghel
7/25/2005 12:36:03 PM
dotnet windows forms designtime: Hi there,

I am stuck in that, so I need your help. I designed a user control, which is
mainly a GroupBox (GB). When I drag a control in the GB, the new control (NC)
seems to be behind the GB. When I move my GB, the NC appears until I stop
moving the GB. At runtime, the NC does not show up. What I wanted to do is a
usercontrol behaving like a normal group box, i.e. when I drop a control on
it, I want it to become a group box child. I can see in the generated source
something like GB.Controls.Add(NC), but I guess, this is not that easy. Any
suggestions?

Many thanks,

Re: Container control in designtime Tim Wilson
7/25/2005 4:32:43 PM
You could change the designer for your custom UserControl. First add a
reference to the System.Design.dll assembly and then set the designer as
shown below.

using System.ComponentModel;
using System.Windows.Forms.Design;

[Designer(typeof(ParentControlDesigner))]
public class MyUserControl : System.Windows.Forms.UserControl
{
...
}

Alternatively, you could derive your control from another control like the
Panel control.

--
Tim Wilson
..Net Compact Framework MVP

[quoted text, click to view]

Re: Container control in designtime Monarghel
7/25/2005 6:12:01 PM
Tim,

I followed your tips, but I still have the sames problems. To be more
accurate, my usercontrol inherits from an abstract class which is itself
derivated from usercontrol class. I added some properties to it, nothing much.

UserControl --> MpeParameter (the abstract one) --> MpeGroupBox. I applied
the new designer on MpeGroupBox, because several other classes will be
derived from MpeParameter .

I am using Visual Studio 2005 beta 2, could be a bug?

Thanks,

Monarghel.


[quoted text, click to view]
Re: Container control in designtime Tim Wilson
7/25/2005 9:53:57 PM
Have you rebuilt your custom UserControl to see if the changes are properly
reflected in any instances that may be on a form, in the designer, that you
may be using? Try a rebuild of the UserControl(s).

--
Tim Wilson
..Net Compact Framework MVP

[quoted text, click to view]

Re: Container control in designtime Monarghel
7/26/2005 4:59:04 AM
Well, my custom control was rebuilt, same problems. Do have I to override
some methods? I am sorry to bother you with that, but this is crucial for my
project.

Thanks,

Christophe.

[quoted text, click to view]
Re: Container control in designtime Monarghel
7/26/2005 6:15:07 AM
I am trying to reach you, but I do not have any valid email address, and I am
not able to attach any file using the web interface. Could you send me an
address at ckamieniarz@hotmail.com?

Thanks.

[quoted text, click to view]
Re: Container control in designtime Tim Wilson
7/26/2005 8:11:44 AM
It all seems to work fine for me, against the 1.1 and 2.0 (beta) framework.
Maybe there's something in your project or source that is causing this. Can
you post the complete source code for the MpeParameter and MpeGroupBox
classes?

--
Tim Wilson
..Net Compact Framework MVP

[quoted text, click to view]

Re: Container control in designtime Monarghel
7/26/2005 9:22:02 AM
Well, that is not that secret:

So, the MpeParameter Class:

using System;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

public delegate void MpeChangedEventHandler(object sender, EventArgs e);

namespace Speedware.MpeControls
{
public abstract class MpeParameter : UserControl
{
public MpeParameter()
{
this.mpeIsOptional = true;
this.mpeByValue = true;
this.mpeGenerate = true;
this.mpeInput = true;
this.mpeFieldName = "WS-";
this.mpeValue = 0;
this.mpeFieldType = MpeEnumFieldTypes.I16;
this.mpeClass = this.GetType().Name;
}

public enum MpeEnumFieldTypes
{
CA, I16, U16, U32
}

public enum MpeEnumBitsetTypes
{
MpeBitsetCheckBox, MpeBitsetUpDown, MpeBitsetComboBox
}

public event MpeChangedEventHandler MpeGenerateChanged;

protected virtual void OnMpeGenerateChanged(EventArgs e)
{
if (MpeGenerateChanged != null)
MpeGenerateChanged(this, e);
}

[Category("MPE")]
public bool MpeGenerate
{
get { return this.mpeGenerate; }
set {
this.mpeGenerate = value;
this.OnMpeGenerateChanged(EventArgs.Empty);
}
}

[Category("MPE")]
public virtual int MpeValue
{
get { return this.mpeValue; }
set { this.mpeValue = value; }
}

[Category("MPE")]
public bool MpeByValue
{
get { return this.mpeByValue; }
set { this.mpeByValue = value; }
}

[Category("MPE")]
public bool MpeIsOptional
{
get { return this.mpeIsOptional; }
set { this.mpeIsOptional = value; }
}

[Category("MPE")]
public string MpeFieldName
{
get { return this.mpeFieldName; }
set { this.mpeFieldName = value; }
}

[Category("MPE")]
public bool MpeInput
{
get { return this.mpeInput; }
set { this.mpeInput = value; }
}

[Category("MPE")]
public virtual MpeEnumFieldTypes MpeFieldType
{
get { return this.mpeFieldType; }
set { this.mpeFieldType = value; }
}

private bool mpeIsOptional;
private bool mpeByValue;
private bool mpeGenerate;
private bool mpeInput;
private string mpeFieldName;
private string mpeClass;
private int mpeValue;
protected MpeEnumFieldTypes mpeFieldType;

private void InitializeComponent()
{
this.SuspendLayout();
//
// MpeParameter
//
this.Name = "MpeParameter";
this.Size = new System.Drawing.Size(322, 258);
this.ResumeLayout(false);

}
}
}
--------------------------------------------
And the MpeGroupBox, which is a GroupBox + a CheckBox:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.Design;

namespace Speedware.MpeControls
{
[Designer(typeof(ParentControlDesigner))]
public partial class MpeGroupBox : MpeParameter
{
public MpeGroupBox()
{
InitializeComponent();
}

.......

}
}

I am new in this kind of tools and languages, I am coming from MPE + COBOL
environment, I guess my problem is trivial.

Thanks,

Christophe.

[quoted text, click to view]
Re: Container control in designtime Tim Wilson
7/26/2005 11:51:45 AM
The reason why I like keeping the discussion in the newsgroup is so that
anyone that is following this can continue to do so, and anyone in the
future that may "google" and get this thread can also have access to the
source. Is there a lot of content or is it private code? If there's not
thousands of lines of code then just cut and paste the source into the
message when you reply. But if you want to keep the source private then just
reply and let me know and we can take this offline.

--
Tim Wilson
..Net Compact Framework MVP

[quoted text, click to view]

Re: Container control in designtime Monarghel
7/26/2005 12:28:02 PM
I feel like being stupid, I can not reproduce yours steps. Could you send me
your solution at ckamieniarz@hotmail.com?

Thanks

[quoted text, click to view]
Re: Container control in designtime Monarghel
7/26/2005 1:19:13 PM
Tim,

The solution you sent me works as expected. So, it seems that the secret is
to build the control in a separate control library, the purpose being to get
rid of the <Control>.Designer.cs generated code.

Thank you for your patience and for sharing your knowledge with
lost-C#-beginner like me.

You made my day :-)

Christophe.


[quoted text, click to view]
Re: Container control in designtime Tim Wilson
7/26/2005 2:13:50 PM
I added the code for the UserControl to a new project that is contained
within the same solution as the windows forms application project that is to
consume it. The steps that I followed are below...

(1) Add a new "Windows Control Library" project to the solution that
contains the windows forms application.
(2) Cut and paste the "MpeParameter" code into the UserControl1.cs file,
then delete the associated UserControl1.Designer.cs file as it is not
necessary in this case.
(3) Add a new "User Control" to the "Windows Control Library" project that
was created earlier. Make the appropriate changes to the namespace and class
name in the UserControl2.Designer.cs file so that they line up with the
pasted code.
(4) Add a reference to the System.Design.dll to the "Windows Control
Library" project.
(5) Build the "Windows Control Library" project.
(6) Go to the windows forms applicaton project and display one of the forms
that requires the custom UserControl.
(7) In the ToolBox there should be a special section at the top that
contains the MpeGroupBox control. Drag and drop that control onto the form.

The control instance should be able to act as a parent to other controls.
You can easily tell this, in the designer, by adding a control and moving it
slightly outside the visible area as the added control should be clipped.

--
Tim Wilson
..Net Compact Framework MVP

Re: Container control in designtime Tim Wilson
7/26/2005 3:59:17 PM
Ok. I've sent the solution, zipped, to your hotmail account. Respond back to
this newsgroup thread and let me know how it goes.

--
Tim Wilson
..Net Compact Framework MVP

[quoted text, click to view]

Re: Container control in designtime Tim Wilson
7/26/2005 5:16:26 PM
You can probably keep the <Control>.Designer.cs file. The only reason that I
said to remove it is because you had all the appropriate information in the
class already. So, in relation to the abstract base class, there was no need
for the designer-code-behind file.

--
Tim Wilson
..Net Compact Framework MVP

[quoted text, click to view]

Re: Container control in designtime Eugene
7/27/2005 5:17:01 AM
Could you please e-mail that zip file to sgl@core.com?

I'm having the same problem :(

I do not think this is a secret in any way since the original author had
posted his code...

Thank you.

[quoted text, click to view]
Re: Container control in designtime Tim Wilson
7/27/2005 11:07:02 AM
Ok. I've sent an example to your email account. Basically I built the
example like this...
(1) Create a new "Windows Application" project (this should also create a
new solution).
(2) Add a new "Windows Control Library" project to the solution.
(3) Change properties, or add controls if necessary, for the new custom
UserControl using the designer and add any code necessary to the
"UserControl1.cs" file.
(4) Right-click on the "WindowsControlLibrary1" project in the solution
explorer and select "Build" on the context menu that appears.
(5) Open the form, in designer mode, that was created with the "Windows
Application" project.
(6) Got to the ToolBox, navigate to the top, and you should see a
"WindowsControlLibrary1 Components" section containing the custom
UserControl.
(7) Drag and drop the custom UserControl onto the form.

--
Tim Wilson
..Net Compact Framework MVP

[quoted text, click to view]

AddThis Social Bookmark Button