473,396 Members | 2,017 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Codedom: Adding a Button (or any control for that matter) to a Win Form.

Hi All,

I'm looking for some simple examples of using the CodeDom. While the ones
that I have found have been very helpful, I can't seem to find the
following:

How to add a control to a form.
How to add an event handle to that control just was just added to the form.

If anyone has any examples that they could share, it would be much
appreciated.

Thanks in advance for your time,
Gary Stewart
Mar 30 '06 #1
2 1941
Adding a control to a form using System.CodeDom? I think you'll have to be
more specific about what you think you're trying to do.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Show me your certification without works,
and I'll show my certification
*by* my works.

"Microsoft Newsgroups" <GS******@Microendeavors.com> wrote in message
news:uv**************@TK2MSFTNGP09.phx.gbl...
Hi All,

I'm looking for some simple examples of using the CodeDom. While the ones
that I have found have been very helpful, I can't seem to find the
following:

How to add a control to a form.
How to add an event handle to that control just was just added to the
form.

If anyone has any examples that they could share, it would be much
appreciated.

Thanks in advance for your time,
Gary Stewart

Mar 30 '06 #2
Hi Kevin...

Using the CodeDom I create a NameSpace, a Form, a constructor for that Form
and the InitializeComponent method for that form.

Here's a snip of the code that does that:
_Form = new CodeTypeDeclaration(this._Name);

_Form.BaseTypes.Add("System.Windows.Forms.Form");

_NameSpace.Types.Add(_Form);

// Create a constructor for this form.

CodeConstructor oConstructor = new CodeConstructor();

oConstructor.Attributes = MemberAttributes.Public;

oConstructor.Statements.Add(new CodeMethodInvokeExpression(new
CodeThisReferenceExpression(), "InitializeComponent", new
CodeExpression()));
_Form.Members.Add(oConstructor);

CodeMemberMethod oInitControls = new CodeMemberMethod();

oInitControls.Name = "InitializeComponent";

oInitControls.Attributes = MemberAttributes.Private;

oInitControls.CustomAttributes.Add(new
CodeAttributeDeclaration("System.Diagnostics.Debug gerStepThrough"));

/////////////////////////// End Code

That gives me a nice blank Form with a constructor and InitializeComponent
method. How do I add a button to that Form using the CodeDom and its
associated namespaces?
Thanks,

Gary

"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:OZ**************@tk2msftngp13.phx.gbl...
Adding a control to a form using System.CodeDom? I think you'll have to be
more specific about what you think you're trying to do.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Show me your certification without works,
and I'll show my certification
*by* my works.

"Microsoft Newsgroups" <GS******@Microendeavors.com> wrote in message
news:uv**************@TK2MSFTNGP09.phx.gbl...
Hi All,

I'm looking for some simple examples of using the CodeDom. While the
ones that I have found have been very helpful, I can't seem to find the
following:

How to add a control to a form.
How to add an event handle to that control just was just added to the
form.

If anyone has any examples that they could share, it would be much
appreciated.

Thanks in advance for your time,
Gary Stewart


Mar 30 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Codemonkey | last post by:
Hi, When I first installed Visual Studio 2003, I noticed I was getting the follow error when showing a form: A first chance exception of type 'System.ArithmeticException' occurred in...
1
by: Tom Bean | last post by:
When a control is created during program execution, how can the control add itself to the form's control collection? I'd like to do this without the control or the form having to know specific...
2
by: Richard Muller | last post by:
Hi All, I'm running MSDE 2002, ver. 7.0.9466 with Net Framework 1.0, ver. 1.0.3705 over Win2000ProSP4. I created a new Visual C# project using the Windows Application template. I'm trying...
1
by: Dave | last post by:
Hi, I am using the following code to try to open a window in a target frame using a button control that is in the original frame. It does not work unless I click the button twice. If anyone...
0
by: lab3terch | last post by:
I have built an enhanced button control which I want to use to capture the number of times the button has been clicked. I have added the new control to a test program but cannot get it to work. The...
2
by: Marc | last post by:
Hi, I want to allow the user to rename a button control. When they click rename from the menu I want the button text to become editable on the actaul button...and then perhaps save the new text...
3
by: John | last post by:
Hello, Is there a way I can reference the button control that activated the mouseenter event? My buttons are created at runtime so i do not know any names. I was hoping to use...
1
by: sotirios | last post by:
I have insert the ActiveX Color Button Control in my form (for selecting and store the color in a field) and I cannot store the value. Usually when I use an ActiveX I use me!ActiveX.value to store...
0
by: Parimaladevi | last post by:
hi, i want to know how to add a eventhandler for a button control that is created dynamically inside Template Column of a Datagrid in Silverlight application. Click event is not fired and it...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.