CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2009
    Posts
    28

    ctype doesn't work properly

    hi all, i've got a problem here whereby my ctype doesn't work.

    firstly, to replicate my case briefly, i've created an extension of control class
    Code:
    <extension()> public function getheight(byref control as Control) as integer
    return control.height
    end function
    and i have this function that doesn't work
    Code:
    public sub dostuff(byref control as Control)
    dim father as object
    father = ctype(control.parent, Control)
    father.getheight 'compiler writes: Panel class doesn't support getheight, but I've already converted it to a Control with CType!
    end sub
    of course if i dim father as Control it works perfectly, but in my case father may be other objects as well that aren't controls so I had to dim father as a general object, is there a fix so i could properly convert father into a Control object?

  2. #2
    Join Date
    Oct 2009
    Posts
    28

    Re: ctype doesn't work properly

    ok let me rephrase my question. all i need is to be able to change the Panel type into a Control type, arg i cant seem to find a solution for this

    Code:
    dim test as CType(testpanel, Control))
    msgbox(typename(test)) ' i dun get it, how can typename of test give me Panel when i explicitly call it to be converted to a Control type?
    Last edited by pacerier; October 31st, 2009 at 03:10 PM. Reason: clarification

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured