473,322 Members | 1,522 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,322 software developers and data experts.

Adding code to InitializeComponent in a UserControl

Hi,

I added some custom code to the InitalizeComponent function of a control
that I'm working on. Every once in a while, I've noticed that the code that
I added disappears. I finally tracked it down, and it seems that the code
disappears whenever I make a change to the UI of the control. For instance,
I just resized the control in the IDE, and my code disappeared.

Is this normal behavior? Is there a better place for this code? The code
that I inserted into InitializeComponent has to run before the OnSizeChanged
event runs.

Thanks
Nov 20 '05 #1
3 13552
Scott,
Did you read the comment just before the routine? :-)

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

Sometimes the designer will put your controls (variables) between the
comments & InitializeComponent.
Is this normal behavior? Yes, the routine belongs to the Designer, it will be replaced when you
modify the control in the designer. As the above comment states, do not
modify the InitializeComponent routine!
Is there a better place for this code? Yes, put your code in the constructor, after the call to
InitializeComponent, there is a comment indicating where.

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

' **** put your code here **** '

End Sub

Hope this helps
Jay
"Scott Kilbourn" <skilbourn@NO_SPAM_PLEASE.appliedsystems.com> wrote in
message news:e%****************@TK2MSFTNGP12.phx.gbl... Hi,

I added some custom code to the InitalizeComponent function of a control
that I'm working on. Every once in a while, I've noticed that the code that I added disappears. I finally tracked it down, and it seems that the code
disappears whenever I make a change to the UI of the control. For instance, I just resized the control in the IDE, and my code disappeared.

Is this normal behavior? Is there a better place for this code? The code
that I inserted into InitializeComponent has to run before the OnSizeChanged event runs.

Thanks

Nov 20 '05 #2
* "Scott Kilbourn" <skilbourn@NO_SPAM_PLEASE.appliedsystems.com> scripsit:
I added some custom code to the InitalizeComponent function of a control
that I'm working on. Every once in a while, I've noticed that the code that
I added disappears. I finally tracked it down, and it seems that the code
disappears whenever I make a change to the UI of the control. For instance,
I just resized the control in the IDE, and my code disappeared.

Is this normal behavior? Is there a better place for this code? The code
that I inserted into InitializeComponent has to run before the OnSizeChanged
event runs.


Did you realize the comments created by the designer automatically? Add
the code to the control's constructor (before the call to
'InitializeComponent').

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #3
Thanks for the responses. I guess I'm a bit overwhelmed by how different
this stuff is after so many years working with VB6. ;)

"Scott Kilbourn" <skilbourn@NO_SPAM_PLEASE.appliedsystems.com> wrote in
message news:e%****************@TK2MSFTNGP12.phx.gbl...
Hi,

I added some custom code to the InitalizeComponent function of a control
that I'm working on. Every once in a while, I've noticed that the code that I added disappears. I finally tracked it down, and it seems that the code
disappears whenever I make a change to the UI of the control. For instance, I just resized the control in the IDE, and my code disappeared.

Is this normal behavior? Is there a better place for this code? The code
that I inserted into InitializeComponent has to run before the OnSizeChanged event runs.

Thanks

Nov 20 '05 #4

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

Similar topics

0
by: Ryan Liu | last post by:
I think there are two way to define user control. For example, I want to define a ComoBox with contains only AM, PM items. a.. One way I define a class extends...
0
by: Colin | last post by:
Hi there, I really need your help on this. I'm trying to learn to using the VS.2003 to create a User Control. In my aspx code has no problem to use the property "grossWaye" that has "register" in...
0
by: Chris Millar | last post by:
I have a user control that i wish to extend to change the date when the user selects the numeric up down button. The code explains itself, hope someone can help. any ideas appreaciated.. ...
2
by: Tomek R. | last post by:
Hello ! I've got weird problem when adding new datagrid item. Here is the situation: my grid dgDeps is binded to DepartmentList arraylist, stored in Session between round-trips.. To add new...
1
by: sianan | last post by:
I tried to use the following example, to add a checkbox column to a DataGrid in an ASP.NET application: http://www.codeproject.com/aspnet/datagridcheckbox.asp For some reason, I simply CAN'T get...
1
by: elziko | last post by:
I have sucessfully created a control that inherits from a UserControl. Now I want to extend this by adding extra controls but if I try and drop a control onto the form then I just get the "No"...
1
by: npaulus | last post by:
Hi, I am trying to dynamically add user controls on to my web form but for some reason my form isnt displaying the user control. form1.cs: using System; using System.Drawing; using...
1
by: bonk | last post by:
I have a very simple UserControl (derived from System.Windows.Forms.UserControl) that contains several ListViews. The UserControl exposes a single public property: public...
1
by: Don | last post by:
I'm getting the following exception displayed in the task list at design time for my project: "Code generation for property 'Controls' failed. Error was: 'Object reference not set to an...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.