Sunday, July 6, 2008

How Much Does It Cost To Get Chest Waxed

Developer Creating a User Control with VB.NET 2005 Super Clásico Chihuahua 2008

Currently I am improving a desktop application I made for you chic material of Accounting I and II races Contaduaría and Administration. This application uses a window to create journal entries, creating and removing records, accounts and seats. In the end, with a single click scheme generated as an adult, trial balance, balance sheet and scratch daily and exported to Excel.

For during the upgrade I found nuevament
and with the difficulty of giving the user the ease of adding and removing records visually, because the first version was manually editing all sizes and locations of dozens of checks in her workspace. What I did in this second version was to design a custom control (User Control) called ControlAsiento.vb containing another User Control called ControlReg istro.vb, which provided me with life.

For this little tutorial we Consider Visual Studio 2005 I'm using VB.
What is a UserContr ol and use?
A User Control is not only a common class. Vb also provides references to work with the classes within the namespace System.Wi ndows.Forms to Unlike the Class Library, which is a good topic for another post. With User Control we can create more complex controls and advanced derivative of the controls and provides the IDE, as we shall see appropriate forward with an example.
Here I show you step by step how to create and use.

The following example will make a tiny part of I had to do to the application that was developed, that is to generate new run-time control instanacias of
we are to design and program .
How is it done? 1. After opening the IDE of Microsoft Visual Studio 2005 and using Visual Basic language, create a new Windows Application as commonly. I am and named "Example 1" to my project. 2. When creating our project presents a new form empty for com Enzar to work. Well, what s harem will add a User Control to our application. In the Solution Explorer (Solution Explorer) will deploy with a right click on the name of our application a popup window where



select the option Add> User Control

.
3. Note that when you open the window dialog is selected the User Control control. We will give a name to our new control, in our case will ControlRegistro.vb. This is the lowest level control, ie, the latter only contain predefined controls that Visual Studio.




4. We see a new canvas that contains no title bars or borders, which will begin to design our control.
5. For example only schedule a button on each User Control , although this will come after everything else designed.


6. Having temrinado with ControlRegistro design, create
then ControlAsiento, containing an undetermined amount of records. For this we proceed in the same way we ControlRegistro.

In the solution explorer (Solution Explorer) will deploy with a right click on the name

our application a window pop
where
select the option Add>

User Control

and we named ControlAsiento.vb, p

Proceed to make the interface design. For this interface need to add at least one
ControlRegistro control type we created, but we can not access this control
Box tools until we have rebuilt the application to changes in ControlRegistro take effect in the places which it is used. So far we have not used do and for this we also need to rebuild. Select from the main menu Build> Rebuild Example1
.





7. ControlAsiento have the following aspect. 8. When we design temrinar rebuild again implemented as already mentioned, then we can see our control in the tool box . 9. Finally we look like our main form Form1.





Well, we have designed our controls, just need to give life to this code fragment will ControlRegistro, ControlAsiento and Form1.
Form1
*** ***





Public Class Form1 Dim entry As ControlAsiento
crearAsiento Sub (ByVal asientoAnterior As ControlAsiento) 'calculate the position of the new entry from the front seat, the which made the call 'and added to form the new ControlAsiento
seat = New ControlAsiento
asiento.Location = New Point (asientoAnterior.Location.X, asientoAnterior.Height asientoAnterior.Location.X + + 5)
seat. Label1.Text
asientoAnterior.Label1.Text + 1 = With GroupBox1
. Size = New Size (. Width. AsientoAnterior.Height Height + + 5) . Controls.Add (seat)
End With End Sub End Class
*** ***

ControlAsiento

ControlAsiento

Public Class Private Sub Button1_Click (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

'We call the method crearAsiento () of the form contains this seat.

CType (Mark
FindForm , Form1). CrearAsiento (Me) End Sub
ControlAsiento_Load Private Sub (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'is just one example of how you can add an event handler to a control,
' as in micas have used a lot of these handlers when creating controls dynamically

'and have several ways to access the same event


AddHandler Button1.Click, AddressOf Button1_Click End Sub
crearRegistro Sub (ByVal sender As ControlRegistro) Dim reg As New
ControlRegistro
'The separation will add to the record position and other controls, and the amount you add to the size GroupBox1 of

sender.Height Dim y = + 3
reg.Location = New Point (sender.Location.X, sender.Location.Y + y)

'We got too multiline text box and buttons
ControlAsiento
redaccion.Location = New Point (redaccion.Location.X, redaccion.Location.Y + y)
Button1.Location = New Point (Button1.Location.X, Button1.Location.Y + y) = New
Button2.Location Point (Button2.Location.X, Button2.Location.Y + y) 'To get the formuylario Me.ParentForm containing this control and became the type Form1, which is the class that we
With CType (Me . ParentForm
, Form1). GroupBox1
. Size = New Size (. Width. Height + y)
End With 'add the new control to the appropriate container, in this case ControlAsiento that contains the button you've pressed
Me.Controls.Add (reg) End Sub End Class



*** *** ControlRegistro
ControlRegistro
Public Class Private Sub Button1_Click (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ' We get the ControlAsiento which contains this ControlRegistro
seat Dim As ControlAsiento = Me. Parent


'We call we did in the subroutine to generate new records ControlAsiento

asiento.crearRegistro (Me) End Sub End Class

I have highlighted in bold some functions that are useful to access controls that contain our
User Control



, so you can use these properties and methods.
What the above code will do is create a new entry under the seat containing the '+' button where you clicked. And generate a new record below the record that is the '+' button which was clicked.





As we have seen, we can use User Control


not only for those cases where we have to use a complex control in various parts of our application, but also in cases where it is necessary to dynamically create some complex controls without breaking both his head, as happened to me .

I hope you learn something this short tutorial.

0 comments:

Post a Comment