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 Controls / March 2006

Tip: Looking for answers? Try searching our database.

Change ToolBox Control Names in Code Behind when pulling them in?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jörgen Ahrens - 29 Mar 2006 16:45 GMT
Hi all

Is it possible to change the name in the code behind of a control pulled in
from a toolbox?

When i pull a Button control on my form the variable in the code behind is
named "button1". is it possible to set some propertie that it names the
variable "txb1" in the code behind?

thanks for your help
j.ahrens
"Jeffrey Tan[MSFT]" - 30 Mar 2006 03:34 GMT
Hi jahrens,

Thanks for your post!

Yes, we can rename the Control name(that is the reference name in code
file) in PropertyBrowser. We can modify the control name in "(Name)" in
PropertyBrowser. You may give this a try.

Hope this helps!

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Jörgen Ahrens - 30 Mar 2006 07:25 GMT
Hi Jeffrey I found it there. But is it possible so that by default my
Textbox is beeing named txb1 and not textBox1 ?
I need to stick to some codingrules and asked myself if i could implement
them somewhere so that visual studio could support me.

thanks
j.ahrens

> Hi jahrens,
>
[quoted text clipped - 15 lines]
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
"Jeffrey Tan[MSFT]" - 30 Mar 2006 09:36 GMT
Hi jahrens,

Thanks for your feedback.

Change control name can be done by VS.net automation. Please refer to the
sample provided by "Carlos J. Quintero [MVP]" in the link below:
http://groups.google.com/group/microsoft.public.vsnet.ide/browse_frm/thread/
1196b3070363ef6d/27cf1272bb1da25e?tvc=1&q=Designer-given+control+names+causi
ng+version+control+conflicts&hl=en#27cf1272bb1da25e

Hope this helps!

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Jörgen Ahrens - 30 Mar 2006 13:49 GMT
Thanks Jeffrey

works fine!

have a good time!

jahrens

namespace NamingConventionExtention

{

using System;

using System.Data;

using System.Windows.Forms;

using Microsoft.Office.Core;

using Extensibility;

using System.Runtime.InteropServices;

using EnvDTE;

using System.ComponentModel;

using System.ComponentModel.Design;

using System.Collections;

#region Read me for Add-in installation and setup information.

// When run, the Add-in wizard prepared the registry for the Add-in.

// At a later time, if the Add-in becomes unavailable for reasons such as:

// 1) You moved this project to a computer other than which is was
originally created on.

// 2) You chose 'Yes' when presented with a message asking if you wish to
remove the Add-in.

// 3) Registry corruption.

// you will need to re-register the Add-in by building the MyAddin21Setup
project

// by right clicking the project in the Solution Explorer, then choosing
install.

#endregion

/// <summary>

/// The object for implementing an Add-in.

/// </summary>

/// <seealso class='IDTExtensibility2' />

[GuidAttribute("62A2C7D0-DB40-495C-A5CC-CE9A5022A4C0"),
ProgId("NamingConventionExtention.Connect")]

public class Connect : Object, Extensibility.IDTExtensibility2

{

private _DTE applicationObject;

private AddIn addInInstance;

private EnvDTE.WindowEvents windowEvents;

private Window activeWindow;

private IDesignerHost designerHost;

private Hashtable componentChangeServices = new Hashtable();

private DataSet ds;

/// <summary>

/// Implements the constructor for the Add-in object.

/// Place your initialization code within this method.

/// </summary>

public Connect()

{

}

/// <summary>

/// Implements the OnConnection method of the IDTExtensibility2 interface.

/// Receives notification that the Add-in is being loaded.

/// </summary>

/// <param term='application'>

/// Root object of the host application.

/// </param>

/// <param term='connectMode'>

/// Describes how the Add-in is being loaded.

/// </param>

/// <param term='addInInst'>

/// Object representing this Add-in.

/// </param>

/// <seealso class='IDTExtensibility2' />

public void OnConnection(object application, Extensibility.ext_ConnectMode
connectMode, object addInInst, ref System.Array custom)

{

applicationObject = (_DTE)application;

addInInstance = (AddIn)addInInst;

try

{

windowEvents = applicationObject.Events.get_WindowEvents(null);

windowEvents.WindowActivated += new
_dispWindowEvents_WindowActivatedEventHandler(windowEvents_WindowActivated);

windowEvents.WindowClosing += new
_dispWindowEvents_WindowClosingEventHandler(windowEvents_WindowClosing);

windowEvents.WindowCreated +=new
_dispWindowEvents_WindowCreatedEventHandler(windowEvents_WindowCreated);

ds = new DataSet();

System.Xml.XmlDocument doc = new System.Xml.XmlDocument();

doc.Load(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase)
+ "\\NamingConventions.config");

ds.ReadXml(doc.SelectSingleNode("/configuration//appSettings//add[@key=\"NamingConventionsPath\"]//@value").Value);

ds.Tables["NamingConventions"].PrimaryKey = new
DataColumn[]{ds.Tables["NamingConventions"].Columns["Namespace"]};

}

catch(Exception e)

{

MessageBox.Show(e.ToString());

}

}

/// <summary>

/// Implements the OnDisconnection method of the IDTExtensibility2
interface.

/// Receives notification that the Add-in is being unloaded.

/// </summary>

/// <param term='disconnectMode'>

/// Describes how the Add-in is being unloaded.

/// </param>

/// <param term='custom'>

/// Array of parameters that are host application specific.

/// </param>

/// <seealso class='IDTExtensibility2' />

public void OnDisconnection(Extensibility.ext_DisconnectMode disconnectMode,
ref System.Array custom)

{

}

/// <summary>

/// Implements the OnAddInsUpdate method of the IDTExtensibility2 interface.

/// Receives notification that the collection of Add-ins has changed.

/// </summary>

/// <param term='custom'>

/// Array of parameters that are host application specific.

/// </param>

/// <seealso class='IDTExtensibility2' />

public void OnAddInsUpdate(ref System.Array custom)

{

}

/// <summary>

/// Implements the OnStartupComplete method of the IDTExtensibility2
interface.

/// Receives notification that the host application has completed loading.

/// </summary>

/// <param term='custom'>

/// Array of parameters that are host application specific.

/// </param>

/// <seealso class='IDTExtensibility2' />

public void OnStartupComplete(ref System.Array custom)

{

}

/// <summary>

/// Implements the OnBeginShutdown method of the IDTExtensibility2
interface.

/// Receives notification that the host application is being unloaded.

/// </summary>

/// <param term='custom'>

/// Array of parameters that are host application specific.

/// </param>

/// <seealso class='IDTExtensibility2' />

public void OnBeginShutdown(ref System.Array custom)

{

}

private void windowEvents_WindowActivated(Window GotFocus, Window LostFocus)

{

HandleActiveWindowChange(GotFocus);

}

private void windowEvents_WindowClosing(Window Window)

{

HandleActiveWindowChange(null);

}

private void windowEvents_WindowCreated(Window Window)

{

HandleActiveWindowChange(Window);

}

private void HandleActiveWindowChange(Window newActiveWindow)

{

activeWindow = newActiveWindow;

designerHost = null;

if(activeWindow != null &&
!componentChangeServices.ContainsKey(activeWindow))

{

designerHost = activeWindow.Object as IDesignerHost;

if(designerHost == null) return;

IComponentChangeService componentChangeService =
designerHost.GetService(typeof(IComponentChangeService)) as
IComponentChangeService;

if(componentChangeService == null) return;

componentChangeService.ComponentAdded += new
ComponentEventHandler(componentChangeService_ComponentAdded);

componentChangeServices.Add(activeWindow, null);

}

}

private void componentChangeService_ComponentAdded(object sender,
ComponentEventArgs e)

{

try

{

int i = 1;

string type = e.Component.GetType().ToString();

DataRow row = ds.Tables["NamingConventions"].Rows.Find(type);

if(row == null) return;

string prefix = row["Prefix"].ToString();

if(e.Component.Site.Container.Components[prefix] == null)

{

e.Component.Site.Name = prefix;

return;

}

string name = prefix + i;

while(e.Component.Site.Container.Components[name] != null)

{

i++;

name = prefix + i;

}

e.Component.Site.Name = name;

}

catch(Exception ex)

{

MessageBox.Show(ex.ToString());

}

}

}

}
"Jeffrey Tan[MSFT]" - 31 Mar 2006 02:46 GMT
You are welcome

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

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.