Wrox Programmer Forums
|
BOOK: Visual Basic 2005 Programmer's Reference
This is the forum to discuss the Wrox book Visual Basic 2005 Programmer's Reference by Rod Stephens; ISBN: 9780764571985
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Visual Basic 2005 Programmer's Reference section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 30th, 2006, 07:31 AM
Authorized User
 
Join Date: Jan 2006
Posts: 43
Thanks: 1
Thanked 0 Times in 0 Posts
Default Error while Inherit

I want to create a usercontrol derived from Textbox
i follow the chapter 12 but
When i type

Inherits system.Windows.forms.textbox

the error comes

'AutoScaleDimensions'is not a member of 'WindowsControlLibrary1.abcd'.
'AutoScaleMode' is not a member of 'WindowsControlLibrary1.abcd'.

what can i do?

Thanks in advance

ackid32
 
Old May 30th, 2006, 08:17 AM
Rod Stephens's Avatar
Wrox Author
 
Join Date: Jan 2006
Posts: 647
Thanks: 2
Thanked 96 Times in 95 Posts
Default

A UserControl is intended to contain other controls not be derived from them. For example, you could put a TextBox inside the UserControl. Is that what you're trying to do? That should work.

If you want to derive a control from TextBox, build a class library, add a reference to Windows Forms, and then use an Inherits statement as in:

    Inherits System.Windows.Forms.TextBox

I don't know why you would get AutoScale errors unless perhaps you were trying to load code from a different vesion of Visual Basic. Microsoft changed some of the internals relatively late in the release process so perhaps you have older code?


Rod
RodStephens@vb-helper.com
Author of "Visual Basic 2005 Programmer's Reference"
http://www.vb-helper.com/vb_prog_ref.htm

Sign up for the free VB Helper Newsletters at http://www.vb-helper.com/newsletter.html
 
Old May 30th, 2006, 10:43 PM
Authorized User
 
Join Date: Jan 2006
Posts: 43
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Thanks for the reply, but im using vb 2005 professional edition.

I want to make my own Textbox with some extra properties So i put the textbox in usercontrol and add the properties. All the properties are worked well(without the normal textbox properties). I want to add those properties too (like selectionstart, text, slectionpos).
can you tell me a suggestion.

Thanks Rod
ackid32

 
Old May 31st, 2006, 07:25 AM
Rod Stephens's Avatar
Wrox Author
 
Join Date: Jan 2006
Posts: 647
Thanks: 2
Thanked 96 Times in 95 Posts
Default

This will still be easier if you derive a new control instead of making a UserControl. If you inherit from TextBox, then you only need to add and modify the things you want changed and you get all the normal TextBox behavior for free. With the UserControl, you need to implement everything that you want the new control to provide. For example:

Public Class MyTextBox
    Inherits System.Windows.Forms.TextBox

    Public Function DoubleLength() As Integer
        Return 2 * Text.Length
    End Function
End Class

Now the MyTextBox control can do everything a TextBox can plus it has the (admitedly simplistic) DoubleLength function.

But I still don't see where the AutoScale errors come from. Are you trying to implement those routines?

Rod


Rod
RodStephens@vb-helper.com
Author of "Visual Basic 2005 Programmer's Reference"
http://www.vb-helper.com/vb_prog_ref.htm

Sign up for the free VB Helper Newsletters at http://www.vb-helper.com/newsletter.html
 
Old June 1st, 2006, 03:41 AM
Authorized User
 
Join Date: Jan 2006
Posts: 43
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Thanks & can you guide me step by step for that.
ackid32

 
Old June 1st, 2006, 09:29 PM
Rod Stephens's Avatar
Wrox Author
 
Join Date: Jan 2006
Posts: 647
Thanks: 2
Thanked 96 Times in 95 Posts
Default

Create a new Windows Forms Controls Library project, delete the UserControl that it adds for you, add a new Class, and paste in the code above. Then add the properties that you want to add. Let me know what you're trying to do and I can probably make a better example.

To test it, use the file menu to add a new Windows Forms project to the solution. Then you can put instances of the control on that project's form and test it out.

Rod

Rod
RodStephens@vb-helper.com
Author of "Visual Basic 2005 Programmer's Reference"
http://www.vb-helper.com/vb_prog_ref.htm

Sign up for the free VB Helper Newsletters at http://www.vb-helper.com/newsletter.html
 
Old June 1st, 2006, 11:35 PM
Authorized User
 
Join Date: Jan 2006
Posts: 43
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Thanks Rod,
this is what i want. but i have one more problem

i want to check some values in the textbox's gotfocus event and even want to know the text1.text. but in my class there is no way for that. (In previous vb6 i just put a textbox in usercontrol and use that events and properties for local use). How can i implement that here.

thanks again
ackid32


 
Old June 1st, 2006, 11:57 PM
Authorized User
 
Join Date: Jan 2006
Posts: 43
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Rod, this the sample code i want to implement

Private Sub Txbx_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TXBX.GotFocus
     TXBX.BackColor = somecolor
     TXBX.ForeColor = somecolor
     TXBX.SelectionStart = 0
End Sub
txbx is non existent here so i couldn't get or set the
backcolor property as well as event "Handles TXBX.GotFocus"

hope you solve this one
thanks
ackid32

[u]</u>[u]</u>[u]</u>
 
Old June 2nd, 2006, 02:20 AM
Authorized User
 
Join Date: Jan 2006
Posts: 43
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Rod, i found it myself (i use me.) is it right?

one more question

i want to use the toolboxicon. i follow the book, but it is not working.

my code follows

<ToolboxBitmap(gettype(Tbox),"Textbox")>_

'here Tbox is my class
'Textbox is the name of the bitmat (I add Textbox.bmp into the resources)

but 'Identifier Expected error comes

pls guide me

thanks
ackid32




 
Old June 3rd, 2006, 09:40 AM
Rod Stephens's Avatar
Wrox Author
 
Join Date: Jan 2006
Posts: 647
Thanks: 2
Thanked 96 Times in 95 Posts
Default

> Rod, i found it myself (i use me.) is it right?
Exactly.

> <ToolboxBitmap(gettype(Tbox),"Textbox")>_
>
> 'here Tbox is my class
> 'Textbox is the name of the bitmat (I add
> Textbox.bmp into the resources)

This is something Microsoft seems to have really messed up. I have had terrible luck getting this to work.

There's a very informative article at:

    http://www.bobpowell.net/toolboxbitmap.htm

But I still have trouble if teh namespace has been changed.

I recommend one of two approaches.

1. Use the other version of the ToolboxBitmap attribute where you pass in the full path to the bitmap file as in:

    <ToolboxBitmap("C:\MyCotrols\Tbox\Textbox.bmp")> _

This seems heavy-handed because you'll need to change the code if you move the project but at least it's easy to understand.

2. Ensure that the project's root namespace matches the assembly's name. Double-click My Project, go to the Application tab, and make sure the Assembly Name and Root Namespace match. Then select the resource file in Project Explorer (Textbox.bmp in your case), go to the Properties window, and set Build Action to Embedded Resource. Finally, use a statement like this:

    <ToolboxBitmap(GetType(Tbox), "Textbox")> _

What a mess, huh? I haven't had a chance to try anything with the resfinder class suggested in that article.

If anyone has a better more consistent solution, please let me know!


Rod
RodStephens@vb-helper.com
Author of "Visual Basic 2005 Programmer's Reference"
http://www.vb-helper.com/vb_prog_ref.htm

Sign up for the free VB Helper Newsletters at http://www.vb-helper.com/newsletter.html





Similar Threads
Thread Thread Starter Forum Replies Last Post
about picturebox inherit youtubeline C# 3 December 12th, 2008 03:41 PM
Chapter 7, Inherit keyword not working VictorVictor BOOK: Beginning CSS: Cascading Style Sheets for Web Design ISBN: 978-0-7645-7642-3 2 April 12th, 2006 12:13 PM
Can we Inherit ADODB venki5star Visual Studio 2005 3 March 13th, 2006 10:50 AM
Inherit Exception or ApplicationException organicglenn BOOK: ASP.NET Website Programming Problem-Design-Solution 3 March 27th, 2004 10:42 PM
the inherit problem in java code. benni J2EE 6 November 13th, 2003 06:49 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.