.NET Forum / Windows Forms / Design Time / July 2005
Container control in designtime
|
|
Thread rating:  |
Monarghel - 25 Jul 2005 20:36 GMT 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,
Monarghel
Tim Wilson - 25 Jul 2005 21:32 GMT 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.
 Signature Tim Wilson .Net Compact Framework MVP
> Hi there, > [quoted text clipped - 10 lines] > > Monarghel Monarghel - 26 Jul 2005 02:12 GMT 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.
> 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 [quoted text clipped - 11 lines] > Alternatively, you could derive your control from another control like the > Panel control. Tim Wilson - 26 Jul 2005 02:53 GMT 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).
 Signature Tim Wilson .Net Compact Framework MVP
> Tim, > [quoted text clipped - 27 lines] > > Alternatively, you could derive your control from another control like the > > Panel control. Monarghel - 26 Jul 2005 12:59 GMT 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.
> 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 [quoted text clipped - 33 lines] > the > > > Panel control. Tim Wilson - 26 Jul 2005 13:11 GMT 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?
 Signature Tim Wilson .Net Compact Framework MVP
> 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 [quoted text clipped - 41 lines] > > the > > > > Panel control. Monarghel - 26 Jul 2005 14:15 GMT 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.
> 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 [quoted text clipped - 55 lines] > > > the > > > > > Panel control. Tim Wilson - 26 Jul 2005 16:51 GMT 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.
 Signature Tim Wilson .Net Compact Framework MVP
> 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 [quoted text clipped - 61 lines] > > > > the > > > > > > Panel control. Monarghel - 26 Jul 2005 17:22 GMT 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.
> 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 [quoted text clipped - 3 lines] > 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 - 26 Jul 2005 19:13 GMT 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.
 Signature Tim Wilson .Net Compact Framework MVP
Monarghel - 26 Jul 2005 20:28 GMT I feel like being stupid, I can not reproduce yours steps. Could you send me your solution at ckamieniarz@hotmail.com?
Thanks
> 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 [quoted text clipped - 20 lines] > 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 - 26 Jul 2005 20:59 GMT Ok. I've sent the solution, zipped, to your hotmail account. Respond back to this newsgroup thread and let me know how it goes.
 Signature Tim Wilson .Net Compact Framework MVP
> I feel like being stupid, I can not reproduce yours steps. Could you send me > your solution at ckamieniarz@hotmail.com? [quoted text clipped - 25 lines] > > 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. Monarghel - 26 Jul 2005 21:19 GMT 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.
> Ok. I've sent the solution, zipped, to your hotmail account. Respond back to > this newsgroup thread and let me know how it goes. [quoted text clipped - 37 lines] > > > slightly outside the visible area as the added control should be > clipped. Tim Wilson - 26 Jul 2005 22:16 GMT 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.
 Signature Tim Wilson .Net Compact Framework MVP
> Tim, > [quoted text clipped - 50 lines] > > > > slightly outside the visible area as the added control should be > > clipped. Eugene - 27 Jul 2005 13:17 GMT 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.
> 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 [quoted text clipped - 68 lines] > > > > > slightly outside the visible area as the added control should be > > > clipped. Tim Wilson - 27 Jul 2005 16:07 GMT 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.
 Signature Tim Wilson .Net Compact Framework MVP
> Could you please e-mail that zip file to sgl@core.com? > [quoted text clipped - 77 lines] > > > > > > slightly outside the visible area as the added control should be > > > > clipped.
Free MagazinesGet these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...
|
|
|