How to insert code into a form at design time? 
Author Message
 How to insert code into a form at design time?

Does anyone have a sample code (preferably in C#) as how to do the
following:

At design time I would like to be able to get the hold of the current
form (e.g. form1) that is under design and insert some code into it
(e.g. into form1.cs). I know I have to go through the _DTE object to get
the projectItem, but exatly how can this be done?! And once the current
projectItem (e.g. form1.cs) is obtained how to insert code into it?

Many thanks in advance beyond I can possibly express for any help with
this.

Regards,

*** Sent via Developersdex http://www.*-*-*.com/ ***
Don't just participate in USENET...get rewarded for it!



Sun, 22 May 2005 15:31:48 GMT  
 How to insert code into a form at design time?
There's a topic in the documents that gives some basic information on adding
text to a code file at design time.

The topic is:
Using a Macro to Add Text in a Visual Basic or Visual C# Code Editor
ms-help://MS.VSCC/MS.MSDNVS/vbcon/html/vbconusingmacroeditortoaddtexttovisua
lbasicnetcodewindow.htm

Here's the code snippet from that topic:

Public Sub AddSomeText()
   Dim doc As Document = ActiveDocument
   Dim textDoc As TextDocument = doc.Object("TextDocument")
   If doc.ProjectItem.ContainingProject.Kind = _
      VSLangProj.PrjKind.prjKindVBProject Then
      textDoc.StartPoint.CreateEditPoint()
      textDoc.Selection.Insert("x = 5")
   End If
End Sub

-Robin
VB Team

--
This posting is provided "AS IS" with no warranties, and confers no rights.

Quote:
> Does anyone have a sample code (preferably in C#) as how to do the
> following:

> At design time I would like to be able to get the hold of the current
> form (e.g. form1) that is under design and insert some code into it
> (e.g. into form1.cs). I know I have to go through the _DTE object to get
> the projectItem, but exatly how can this be done?! And once the current
> projectItem (e.g. form1.cs) is obtained how to insert code into it?

> Many thanks in advance beyond I can possibly express for any help with
> this.

> Regards,

> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!



Mon, 23 May 2005 05:35:13 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Design time form at runtime

2. Can not add a custom .NET control on the form in design-time

3. Form Collection in Design Time

4. Design time / run time

5. Simulate in runing time textbox in design time

6. Read/Write Properties During Design Time, but Read-Only During Run-Time

7. Design-time vs Run-time mode

8. Design Time/Run Time Licences for OCXs

9. Design time properties at run time...

10. Problem setting design-time properties on a form inheriting from another base form.

11. Windows Forms design and layout: Recommendations and hints required

12. Does VC.Net Support a Forms-Based GUI Design like VB and C#

 

 
Powered by phpBB® Forum Software