Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / September 2004

Tip: Looking for answers? Try searching our database.

Using a component to add a control to a form

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Christian Wikander - 16 Sep 2004 11:33 GMT
Hi!

I would like to use a component to add a control to a form. This will be
used to make a component that can enable/disable visual features on a form
without making every feature a toolbox item.

I can add and remove the control to the forms component container by using
the following code:

private bool m_bDisplayTextBox = false;
private TextBox tbTest = new TextBox();

[DefaultValue(false)]
public bool DisplayTextBox
{
  get { return(m_bDisplayTextBox); }
  set
  {
     if(value == true) this.Container.Add(tbTest);
     else this.Container.Remove(tbTest);

     m_bDisplayTextBox = value;
  }
}

This will make the TextBox visible in the dropdown list in the properties
browser, but it will not be visible on the form itself. I have pined this
down to the fact that there is no line containing
"this.Controls.Add(this.textBox1);" added to "Windows Form Designer generated
code" in the Form class.

How can I also get the "this.Controls.Add(this.textBox1);" added to the Form
class "Windows Form Designer generated code"?

BR
Christian Wikander
Joey Calisay - 16 Sep 2004 15:42 GMT
you should use a designer for your form, and there use the createcomponent
method

> Hi!
>
[quoted text clipped - 32 lines]
> BR
> Christian Wikander
Christian Wikander - 16 Sep 2004 19:17 GMT
Thanks for the quick response.

I don't quite understand. Maybe it's not possible, but I would like to add
the component to the form, and be setting some attributes of the component I
want to create one or more controls on the form. Can you give me another hint
in the right direction?

> you should use a designer for your form, and there use the createcomponent
> method
[quoted text clipped - 37 lines]
> > BR
> > Christian Wikander

Free Magazines

Get 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 ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.