Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Extend window control as custom control problem

Extend window control as custom control problem

Scheduled Pinned Locked Moved C#
helpquestioncsharptutorialannouncement
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    ting668
    wrote on last edited by
    #1

    Hi~ I have encountered a very difficult problem and worked for a long time but still can't solve it. Pls help it. The problem is : There are two cases. One is for .net full vesion, one is for .net compact framework. For the .net full version, "ListViewEx" is a class which extend listView. class ListViewEx : ListView { ListViewEx() { } protected override OnPaint(PaintEventArg e) { MessageBox.Show("ABC"); base.OnPaint(); } The problem is the overriding OnPaint not be executed if a instance of this class newly be created but the base class (I don't know the method (OnPaint()) of the class "Control" or class "ListView" will be called and draw the listview only without showing message box. However, the overriding OnPaint method seems works if the extended window control is not listview but button or panel. (Other control also not work). What is the problem? For the CF case, The case is that the if Class for example "ListViewEx2" extend the class ListView, the overriding Method OnPaint() still not work since the virtual void OnPaint method in the ListView Class is not supported. However, as the ListView extend Control, and the control also got the virtual method OnPaint(), that mean the ListViewEx2 also got the virtual OnPaint method and which can be overrided by ListViewEx2. Then why the overrided method in ListViewEx2 does not executed? Thanks }

    H 1 Reply Last reply
    0
    • T ting668

      Hi~ I have encountered a very difficult problem and worked for a long time but still can't solve it. Pls help it. The problem is : There are two cases. One is for .net full vesion, one is for .net compact framework. For the .net full version, "ListViewEx" is a class which extend listView. class ListViewEx : ListView { ListViewEx() { } protected override OnPaint(PaintEventArg e) { MessageBox.Show("ABC"); base.OnPaint(); } The problem is the overriding OnPaint not be executed if a instance of this class newly be created but the base class (I don't know the method (OnPaint()) of the class "Control" or class "ListView" will be called and draw the listview only without showing message box. However, the overriding OnPaint method seems works if the extended window control is not listview but button or panel. (Other control also not work). What is the problem? For the CF case, The case is that the if Class for example "ListViewEx2" extend the class ListView, the overriding Method OnPaint() still not work since the virtual void OnPaint method in the ListView Class is not supported. However, as the ListView extend Control, and the control also got the virtual method OnPaint(), that mean the ListViewEx2 also got the virtual OnPaint method and which can be overrided by ListViewEx2. Then why the overrided method in ListViewEx2 does not executed? Thanks }

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      OnPaint is not used by the ListView control, as you could see by disassembling or decompiling the System.Windows.Forms.dll assembly. Almost every control in Windows Forms simply encapsulates the Winodws Common Controls. In the case of some controls like ListView owner drawing the control simply by overriding OnPaint is not possible. To owner draw a List-View common control you need to override WndProc, define several custom drawing structures, and P/Invoke several native APIs. For more information about the native List-View common control that is encapsulated by the ListView managed control, see http://msdn.microsoft.com/library/en-us/shellcc/platform/commctls/listview/reflist.asp[^]. For examples on this site about owner-drawing a ListView control, see the search http://www.codeproject.com/info/search.asp?cats=3&cats=5&searchkw=ListView[^]. You could also try searching this forum for "ListView" by clicking "Search comments" directly above this message area. We've talked about custom drawing a ListView quite a bit, and I know that I personally have posted several snippets of code that show how to draw certain parts through the custom drawing routines that the native Common Controls use. This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Sustained Engineering Microsoft [My Articles] [My Blog]

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups